update-nix-hashes.yml 2.4 KB

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