Skip to content

Commit 9d094eb

Browse files
Bring cron nightly rust updater for CI workflow.
1 parent 947ffc8 commit 9d094eb

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Update nightly Rust
2+
on:
3+
schedule:
4+
- cron: "29 17 1 * *" # At 17:29 on day-of-month 1.
5+
workflow_dispatch: # allows manual triggering
6+
env:
7+
CARGO_TERM_COLOR: always
8+
jobs:
9+
format:
10+
name: Update nightly Rustc
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
persist-credentials: false
16+
- uses: dtolnay/rust-toolchain@nightly
17+
- name: Update rust-toolchain.toml to use latest nightly
18+
run: |
19+
set -xe
20+
21+
# Get the latest nightly date.
22+
# If the latest nightly date is not the same as the current nightly date,
23+
# rustup will default to the latest nightly up to TODAY.
24+
#
25+
# Example: If the latest nightly is 2023-07-01, and the TODAY is 2023-07-02,
26+
# then rustup will default to nightly-2023-07-01.
27+
TODAY="$(date +%Y-%m-%d)"
28+
29+
# Update the nightly version in the rust-toolchain.toml file.
30+
echo "Updating rust-toolchain.toml to use nightly-$TODAY"
31+
sed -i "s/^channel = \"nightly-.*\"/channel = \"nightly-$TODAY\"/" rust-toolchain.toml
32+
33+
# Update the nightly date in the environment.
34+
echo "nightly_date=${TODAY}" >> "$GITHUB_ENV"
35+
36+
# Maybe there is no new nightly.
37+
# In this case don't make an empty PR.
38+
if ! git diff --exit-code > /dev/null; then
39+
echo "Updated nightly. Opening PR."
40+
echo "changes_made=true" >> "$GITHUB_ENV"
41+
else
42+
echo "Attempted to update nightly but the latest-nightly date did not change. Not opening any PR."
43+
echo "changes_made=false" >> "$GITHUB_ENV"
44+
fi
45+
- name: Create Pull Request
46+
if: env.changes_made == 'true'
47+
uses: peter-evans/create-pull-request@v7
48+
env:
49+
NIGHTLY_DATE: ${{ env.nightly_date }}
50+
with:
51+
author: Update Nightly Rustc Bot <no-reply@alpenlabs.io>
52+
committer: Update Nightly Rustc Bot <no-reply@alpenlabs.io>
53+
title: Automated update to rustc (to nightly-$NIGHTLY_DATE)
54+
body: |
55+
Automated update to Rust nightly by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action
56+
commit-message: Automated update to Rust nightly-$NIGHTLY_DATE
57+
branch: create-pull-request/automated-nightly-update

0 commit comments

Comments
 (0)