update-rust-version.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. name: Update Rust Version
  2. on:
  3. schedule:
  4. # Run weekly on Monday at 9 AM UTC
  5. - cron: '0 9 * * 1'
  6. workflow_dispatch: # Allow manual triggering
  7. permissions: {}
  8. jobs:
  9. check-rust-version:
  10. name: Check and update Rust version
  11. runs-on: ubuntu-latest
  12. permissions:
  13. contents: write
  14. pull-requests: write
  15. steps:
  16. - name: Checkout repository
  17. uses: actions/checkout@v4
  18. with:
  19. ref: main
  20. persist-credentials: false
  21. token: ${{ secrets.BACKPORT_TOKEN }}
  22. - name: Get latest stable Rust version
  23. id: latest-rust
  24. run: |
  25. # Fetch the latest stable Rust version from GitHub releases API
  26. LATEST_VERSION=$(curl -s https://api.github.com/repos/rust-lang/rust/releases | jq -r '[.[] | select(.prerelease == false and .draft == false)][0].tag_name')
  27. echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT
  28. echo "Latest stable Rust version: $LATEST_VERSION"
  29. - name: Get current Rust version
  30. id: current-rust
  31. run: |
  32. # Extract current version from rust-toolchain.toml
  33. CURRENT_VERSION=$(grep '^channel=' rust-toolchain.toml | sed 's/channel="\(.*\)"/\1/')
  34. echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
  35. echo "Current Rust version: $CURRENT_VERSION"
  36. - name: Compare versions
  37. id: compare
  38. run: |
  39. if [ "${{ steps.latest-rust.outputs.version }}" != "${{ steps.current-rust.outputs.version }}" ]; then
  40. echo "needs_update=true" >> $GITHUB_OUTPUT
  41. echo "Rust version needs update: ${{ steps.current-rust.outputs.version }} -> ${{ steps.latest-rust.outputs.version }}"
  42. else
  43. echo "needs_update=false" >> $GITHUB_OUTPUT
  44. echo "Rust version is up to date"
  45. fi
  46. - name: Update rust-toolchain.toml
  47. if: steps.compare.outputs.needs_update == 'true'
  48. run: |
  49. sed -i 's/channel="[0-9]*\.[0-9]*\.[0-9]*"/channel="${{ steps.latest-rust.outputs.version }}"/' rust-toolchain.toml
  50. echo "Updated rust-toolchain.toml"
  51. - name: Update flake.nix
  52. if: steps.compare.outputs.needs_update == 'true'
  53. run: |
  54. # Update stable_toolchain version in flake.nix
  55. sed -i 's/stable_toolchain = pkgs\.rust-bin\.stable\."[0-9]*\.[0-9]*\.[0-9]*"\.default/stable_toolchain = pkgs.rust-bin.stable."${{ steps.latest-rust.outputs.version }}".default/' flake.nix
  56. echo "Updated flake.nix"
  57. - name: Create Pull Request
  58. if: steps.compare.outputs.needs_update == 'true'
  59. uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
  60. with:
  61. token: ${{ secrets.BACKPORT_TOKEN }}
  62. author: Rust Update Bot <bot@cashudevkit.org>
  63. title: "chore: update Rust to ${{ steps.latest-rust.outputs.version }}"
  64. body: |
  65. Automated Rust version update from **${{ steps.current-rust.outputs.version }}** to **${{ steps.latest-rust.outputs.version }}**.
  66. ## Changes
  67. - Updated `rust-toolchain.toml` to use Rust ${{ steps.latest-rust.outputs.version }}
  68. - Updated `flake.nix` stable_toolchain to use Rust ${{ steps.latest-rust.outputs.version }}
  69. ## Testing
  70. The CI will run all tests with the new Rust version. Please review the test results before merging.
  71. ## Release Notes
  72. Check the [Rust release notes](https://github.com/rust-lang/rust/blob/master/RELEASES.md) for details on what's new in this version.
  73. ---
  74. 🤖 Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action
  75. commit-message: "chore: update Rust to ${{ steps.latest-rust.outputs.version }}"
  76. labels: rust-version
  77. branch: rust-update-${{ steps.latest-rust.outputs.version }}
  78. - name: No update needed
  79. if: steps.compare.outputs.needs_update == 'false'
  80. run: |
  81. echo "✓ Rust version is already up to date (${{ steps.current-rust.outputs.version }})"