diff --git a/.github/workflows/cron-nightly-rust.yml b/.github/workflows/cron-nightly-rust.yml new file mode 100644 index 000000000..87cf49652 --- /dev/null +++ b/.github/workflows/cron-nightly-rust.yml @@ -0,0 +1,57 @@ +name: Update nightly Rust +on: + schedule: + - cron: "29 17 1 * *" # At 17:29 on day-of-month 1. + workflow_dispatch: # allows manual triggering +env: + CARGO_TERM_COLOR: always +jobs: + format: + name: Update nightly Rustc + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@nightly + - name: Update rust-toolchain.toml to use latest nightly + run: | + set -x + + # Get the latest nightly date. + # If the latest nightly date is not the same as the current nightly date, + # rustup will default to the latest nightly up to TODAY. + # + # Example: If the latest nightly is 2023-07-01, and the TODAY is 2023-07-02, + # then rustup will default to nightly-2023-07-01. + TODAY="$(date +%Y-%m-%d)" + + # Update the nightly version in the rust-toolchain.toml file. + echo "Updating rust-toolchain.toml to use nightly-$TODAY" + sed -i "s/^channel = \"nightly-.*\"/channel = \"nightly-$TODAY\"/" rust-toolchain.toml + + # Update the nightly date in the environment. + echo "nightly_date=${TODAY}" >> "$GITHUB_ENV" + + # Maybe there is no new nightly. + # In this case don't make an empty PR. + if ! git diff --exit-code > /dev/null; then + echo "Updated nightly. Opening PR." + echo "changes_made=true" >> "$GITHUB_ENV" + else + echo "Attempted to update nightly but the latest-nightly date did not change. Not opening any PR." + echo "changes_made=false" >> "$GITHUB_ENV" + fi + - name: Create Pull Request + if: env.changes_made == 'true' + uses: peter-evans/create-pull-request@v7 + env: + NIGHTLY_DATE: ${{ env.nightly_date }} + with: + author: Update Nightly Rustc Bot + committer: Update Nightly Rustc Bot + title: Automated update to rustc (to nightly-$NIGHTLY_DATE) + body: | + Automated update to Rust nightly by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action + commit-message: Automated update to Rust nightly-$NIGHTLY_DATE + branch: create-pull-request/automated-nightly-update