update-nix-hashes.yml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 flake.lock
  34. run: |
  35. set -euo pipefail
  36. nix flake update
  37. - name: Update node_modules hash
  38. run: |
  39. set -euo pipefail
  40. nix/scripts/update-hashes.sh
  41. - name: Commit hash changes
  42. env:
  43. TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
  44. run: |
  45. set -euo pipefail
  46. summarize() {
  47. local status="$1"
  48. {
  49. echo "### Nix Hash Update"
  50. echo ""
  51. echo "- ref: ${GITHUB_REF_NAME}"
  52. echo "- status: ${status}"
  53. } >> "$GITHUB_STEP_SUMMARY"
  54. if [ -n "${GITHUB_SERVER_URL:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ] && [ -n "${GITHUB_RUN_ID:-}" ]; then
  55. echo "- run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" >> "$GITHUB_STEP_SUMMARY"
  56. fi
  57. echo "" >> "$GITHUB_STEP_SUMMARY"
  58. }
  59. FILES=(flake.lock flake.nix nix/node-modules.nix nix/hashes.json)
  60. STATUS="$(git status --short -- "${FILES[@]}" || true)"
  61. if [ -z "$STATUS" ]; then
  62. summarize "no changes"
  63. echo "No changes to tracked Nix files. Hashes are already up to date."
  64. exit 0
  65. fi
  66. git add "${FILES[@]}"
  67. git commit -m "Update Nix flake.lock and hashes"
  68. BRANCH="${TARGET_BRANCH:-${GITHUB_REF_NAME}}"
  69. git push origin HEAD:"$BRANCH"
  70. summarize "committed $(git rev-parse --short HEAD)"