-
Notifications
You must be signed in to change notification settings - Fork 61
Add automated Rust toolchain upgrade workflow #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
# Check if rust-toolchain.toml exists | ||
if [ ! -f "rust-toolchain.toml" ]; then | ||
echo "::error::rust-toolchain.toml not found" | ||
exit 1 | ||
fi | ||
|
||
# Read current channel from rust-toolchain.toml | ||
CURRENT_CHANNEL=$(grep '^channel = ' rust-toolchain.toml | head -1 | sed 's/channel = "\(.*\)"/\1/') | ||
CURRENT_DATE=$(echo "$CURRENT_CHANNEL" | sed 's/nightly-//') | ||
|
||
echo "Current toolchain: $CURRENT_CHANNEL" | ||
|
||
# Fetch latest nightly manifest | ||
MANIFEST_TOML_URL="https://static.rust-lang.org/dist/channel-rust-nightly.toml" | ||
MANIFEST_CONTENT=$(curl -sf "$MANIFEST_TOML_URL") || { | ||
echo "::error::Failed to fetch manifest from $MANIFEST_TOML_URL" | ||
exit 1 | ||
} | ||
|
||
LATEST_DATE=$(echo "$MANIFEST_CONTENT" | grep '^date = ' | head -1 | sed 's/date = "\(.*\)"/\1/') | ||
|
||
if [ -z "$LATEST_DATE" ]; then | ||
echo "::error::Could not extract date from manifest" | ||
exit 1 | ||
fi | ||
|
||
echo "Latest nightly date: $LATEST_DATE" | ||
|
||
# Convert dates to comparable format (remove dashes for numeric comparison) | ||
CURRENT_DATE_NUM=$(echo "$CURRENT_DATE" | tr -d '-') | ||
LATEST_DATE_NUM=$(echo "$LATEST_DATE" | tr -d '-') | ||
|
||
# Compare dates numerically | ||
if [ "$LATEST_DATE_NUM" -gt "$CURRENT_DATE_NUM" ]; then | ||
echo "::notice::New nightly available: $LATEST_DATE (current: $CURRENT_DATE)" | ||
|
||
# Get commit hash from the already fetched manifest | ||
COMMIT_HASH=$(echo "$MANIFEST_CONTENT" | grep -A 50 '\[pkg.rust\]' | grep 'git-commit-hash = ' | head -1 | sed 's/git-commit-hash = "\(.*\)"/\1/') | ||
|
||
if [ -z "$COMMIT_HASH" ]; then | ||
echo "::error::Could not extract commit hash from manifest" | ||
exit 1 | ||
fi | ||
|
||
echo "New commit hash: $COMMIT_HASH" | ||
|
||
# Write outputs for GitHub Actions | ||
echo "SHOULD_UPGRADE=true" >> "${GITHUB_OUTPUT:-/dev/stdout}" | ||
echo "NEW_DATE=$LATEST_DATE" >> "${GITHUB_OUTPUT:-/dev/stdout}" | ||
echo "NEW_COMMIT_HASH=$COMMIT_HASH" >> "${GITHUB_OUTPUT:-/dev/stdout}" | ||
else | ||
echo "::notice::No newer nightly available (current: $CURRENT_DATE, latest: $LATEST_DATE)" | ||
echo "SHOULD_UPGRADE=false" >> "${GITHUB_OUTPUT:-/dev/stdout}" | ||
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Rust Toolchain Upgrade | ||
|
||
on: | ||
schedule: | ||
# Run every day at 2 AM UTC | ||
- cron: '0 2 * * *' | ||
workflow_dispatch: # Allow manual triggering | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
check-and-upgrade: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Check for new nightly | ||
id: check-nightly | ||
run: .github/check-rust-toolchain-upgrade.sh | ||
|
||
- name: Update toolchain files | ||
if: steps.check-nightly.outputs.SHOULD_UPGRADE == 'true' | ||
run: | | ||
NEW_DATE="${{ steps.check-nightly.outputs.NEW_DATE }}" | ||
NEW_COMMIT_HASH="${{ steps.check-nightly.outputs.NEW_COMMIT_HASH }}" | ||
|
||
# Update rust-toolchain.toml | ||
sed -i "s/^channel = \"nightly-[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\"/channel = \"nightly-${NEW_DATE}\"/" rust-toolchain.toml | ||
sed -i "s/^# commit_hash = [a-f0-9]\+/# commit_hash = ${NEW_COMMIT_HASH}/" rust-toolchain.toml | ||
|
||
# Update REQUIRED_RUST_TOOLCHAIN in build.rs | ||
sed -i "s/^channel = \"nightly-[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\"/channel = \"nightly-${NEW_DATE}\"/" crates/rustc_codegen_spirv/build.rs | ||
sed -i "s/^# commit_hash = [a-f0-9]\+/# commit_hash = ${NEW_COMMIT_HASH}/" crates/rustc_codegen_spirv/build.rs | ||
|
||
- name: Build project | ||
if: steps.check-nightly.outputs.SHOULD_UPGRADE == 'true' | ||
run: | | ||
# The updated rust-toolchain.toml will cause cargo to download the required toolchain | ||
cargo build | ||
|
||
- name: Run tests | ||
if: steps.check-nightly.outputs.SHOULD_UPGRADE == 'true' | ||
run: | | ||
cargo compiletest | ||
|
||
- name: Create Pull Request | ||
if: steps.check-nightly.outputs.SHOULD_UPGRADE == 'true' | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: | | ||
Upgrade Rust toolchain to nightly-${{ steps.check-nightly.outputs.NEW_DATE }} | ||
|
||
Updates: | ||
- rust-toolchain.toml: nightly-${{ steps.check-nightly.outputs.NEW_DATE }} | ||
- commit hash: ${{ steps.check-nightly.outputs.NEW_COMMIT_HASH }} | ||
- REQUIRED_RUST_TOOLCHAIN in build.rs | ||
branch: rust-toolchain-upgrade | ||
delete-branch: true | ||
title: "Upgrade Rust toolchain to nightly-${{ steps.check-nightly.outputs.NEW_DATE }}" | ||
body: | | ||
This PR upgrades the Rust toolchain to the latest available nightly version. | ||
|
||
## Changes | ||
- Updated `rust-toolchain.toml` to use `nightly-${{ steps.check-nightly.outputs.NEW_DATE }}` | ||
- Updated commit hash to `${{ steps.check-nightly.outputs.NEW_COMMIT_HASH }}` | ||
- Updated `REQUIRED_RUST_TOOLCHAIN` in `crates/rustc_codegen_spirv/build.rs` | ||
|
||
## Verification | ||
- All required components are available | ||
- Project builds successfully | ||
- Tests pass | ||
|
||
This PR was automatically generated by the [Rust toolchain upgrade workflow](https://github.com/Rust-GPU/rust-gpu/blob/main/.github/workflows/rust-toolchain-upgrade.yml). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.