nightly-rustfmt.yml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. name: Nightly rustfmt
  2. on:
  3. schedule:
  4. - cron: "0 0 * * *" # runs daily at 00:00 UTC
  5. workflow_dispatch: # allows manual triggering
  6. permissions: {}
  7. jobs:
  8. format:
  9. name: Nightly rustfmt
  10. runs-on: ubuntu-latest
  11. permissions:
  12. contents: write
  13. pull-requests: write
  14. steps:
  15. - uses: actions/checkout@v4
  16. with:
  17. ref: main
  18. persist-credentials: false
  19. token: ${{ secrets.BACKPORT_TOKEN }}
  20. - name: Get flake hash
  21. id: flake-hash
  22. run: echo "hash=$(sha256sum flake.lock | cut -d' ' -f1 | cut -c1-8)" >> $GITHUB_OUTPUT
  23. - name: Install Nix
  24. uses: DeterminateSystems/nix-installer-action@v17
  25. - name: Nix Cache
  26. uses: DeterminateSystems/magic-nix-cache-action@main
  27. with:
  28. diagnostic-endpoint: ""
  29. use-flakehub: false
  30. - name: Rust Cache
  31. uses: Swatinem/rust-cache@v2
  32. with:
  33. shared-key: "nightly-${{ steps.flake-hash.outputs.hash }}"
  34. - name: Run Nightly rustfmt
  35. run: |
  36. nix develop -i -L .#nightly --command bash -c '
  37. # Force use of Nix-provided rustfmt
  38. export RUSTFMT=$(command -v rustfmt)
  39. cargo fmt
  40. '
  41. # Manually remove trailing whitespace
  42. git ls-files -- '*.rs' -z | xargs -0 sed -E -i'' -e 's/[[:space:]]+$//'
  43. - name: Get the current date
  44. run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
  45. - name: Create Pull Request
  46. uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
  47. with:
  48. token: ${{ secrets.BACKPORT_TOKEN }}
  49. author: Fmt Bot <bot@cashudevkit.org>
  50. title: Automated nightly rustfmt (${{ env.date }})
  51. body: |
  52. Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action
  53. commit-message: ${{ env.date }} automated rustfmt nightly
  54. labels: rustfmt
  55. branch: automated-rustfmt-${{ env.date }}