update-nix-hashes.yml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. name: Update Nix Hashes
  2. permissions:
  3. contents: write
  4. on:
  5. workflow_dispatch:
  6. push:
  7. paths:
  8. - "bun.lock"
  9. - "package.json"
  10. - "packages/*/package.json"
  11. pull_request:
  12. paths:
  13. - "bun.lock"
  14. - "package.json"
  15. - "packages/*/package.json"
  16. jobs:
  17. update:
  18. runs-on: ubuntu-latest
  19. env:
  20. SYSTEM: x86_64-linux
  21. steps:
  22. - name: Checkout repository
  23. uses: actions/checkout@v4
  24. with:
  25. token: ${{ secrets.GITHUB_TOKEN }}
  26. fetch-depth: 0
  27. - name: Setup Nix
  28. uses: DeterminateSystems/nix-installer-action@v20
  29. - name: Configure git
  30. run: |
  31. git config --global user.email "[email protected]"
  32. git config --global user.name "Github Action"
  33. - name: Update node_modules hash
  34. run: |
  35. set -euo pipefail
  36. nix/scripts/update-hashes.sh
  37. - name: Commit hash changes
  38. env:
  39. TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
  40. run: |
  41. set -euo pipefail
  42. summarize() {
  43. local status="$1"
  44. {
  45. echo "### Nix Hash Update"
  46. echo ""
  47. echo "- ref: ${GITHUB_REF_NAME}"
  48. echo "- status: ${status}"
  49. } >> "$GITHUB_STEP_SUMMARY"
  50. if [ -n "${GITHUB_SERVER_URL:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ] && [ -n "${GITHUB_RUN_ID:-}" ]; then
  51. echo "- run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" >> "$GITHUB_STEP_SUMMARY"
  52. fi
  53. echo "" >> "$GITHUB_STEP_SUMMARY"
  54. }
  55. FILES=(flake.nix nix/node-modules.nix nix/hashes.json)
  56. STATUS="$(git status --short -- "${FILES[@]}" || true)"
  57. if [ -z "$STATUS" ]; then
  58. summarize "no changes"
  59. echo "No changes to tracked Nix files. Hashes are already up to date."
  60. exit 0
  61. fi
  62. git add "${FILES[@]}"
  63. git commit -m "Update Nix hashes"
  64. BRANCH="${TARGET_BRANCH:-${GITHUB_REF_NAME}}"
  65. git push origin HEAD:"$BRANCH"
  66. summarize "committed $(git rev-parse --short HEAD)"