nix-hashes.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. name: 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. - "flake.lock"
  12. - ".github/workflows/nix-hashes.yml"
  13. pull_request:
  14. paths:
  15. - "bun.lock"
  16. - "package.json"
  17. - "packages/*/package.json"
  18. - "flake.lock"
  19. - ".github/workflows/nix-hashes.yml"
  20. jobs:
  21. # Native runners required: bun install cross-compilation flags (--os/--cpu)
  22. # do not produce byte-identical node_modules as native installs.
  23. compute-hash:
  24. strategy:
  25. fail-fast: false
  26. matrix:
  27. include:
  28. - system: x86_64-linux
  29. runner: blacksmith-4vcpu-ubuntu-2404
  30. - system: aarch64-linux
  31. runner: blacksmith-4vcpu-ubuntu-2404-arm
  32. - system: x86_64-darwin
  33. runner: macos-15-intel
  34. - system: aarch64-darwin
  35. runner: macos-latest
  36. runs-on: ${{ matrix.runner }}
  37. steps:
  38. - name: Checkout repository
  39. uses: actions/checkout@v6
  40. - name: Setup Nix
  41. uses: nixbuild/nix-quick-install-action@v34
  42. - name: Compute node_modules hash
  43. id: hash
  44. env:
  45. SYSTEM: ${{ matrix.system }}
  46. run: |
  47. set -euo pipefail
  48. BUILD_LOG=$(mktemp)
  49. trap 'rm -f "$BUILD_LOG"' EXIT
  50. # Build with fakeHash to trigger hash mismatch and reveal correct hash
  51. nix build ".#packages.${SYSTEM}.node_modules_updater" --no-link 2>&1 | tee "$BUILD_LOG" || true
  52. # Extract hash from build log with portability
  53. HASH="$(grep -oE 'sha256-[A-Za-z0-9+/=]+' "$BUILD_LOG" | tail -n1 || true)"
  54. if [ -z "$HASH" ]; then
  55. echo "::error::Failed to compute hash for ${SYSTEM}"
  56. cat "$BUILD_LOG"
  57. exit 1
  58. fi
  59. echo "$HASH" > hash.txt
  60. echo "Computed hash for ${SYSTEM}: $HASH"
  61. - name: Upload hash
  62. uses: actions/upload-artifact@v4
  63. with:
  64. name: hash-${{ matrix.system }}
  65. path: hash.txt
  66. retention-days: 1
  67. update-hashes:
  68. needs: compute-hash
  69. if: github.event_name != 'pull_request'
  70. runs-on: blacksmith-4vcpu-ubuntu-2404
  71. steps:
  72. - name: Checkout repository
  73. uses: actions/checkout@v4
  74. with:
  75. persist-credentials: false
  76. fetch-depth: 0
  77. ref: ${{ github.ref_name }}
  78. - name: Setup git committer
  79. uses: ./.github/actions/setup-git-committer
  80. with:
  81. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  82. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  83. - name: Pull latest changes
  84. run: |
  85. git pull --rebase --autostash origin "$GITHUB_REF_NAME"
  86. - name: Download hash artifacts
  87. uses: actions/download-artifact@v4
  88. with:
  89. path: hashes
  90. pattern: hash-*
  91. - name: Update hashes.json
  92. run: |
  93. set -euo pipefail
  94. HASH_FILE="nix/hashes.json"
  95. [ -f "$HASH_FILE" ] || echo '{"nodeModules":{}}' > "$HASH_FILE"
  96. for SYSTEM in x86_64-linux aarch64-linux x86_64-darwin aarch64-darwin; do
  97. FILE="hashes/hash-${SYSTEM}/hash.txt"
  98. if [ -f "$FILE" ]; then
  99. HASH="$(tr -d '[:space:]' < "$FILE")"
  100. echo "${SYSTEM}: ${HASH}"
  101. jq --arg sys "$SYSTEM" --arg h "$HASH" '.nodeModules[$sys] = $h' "$HASH_FILE" > tmp.json
  102. mv tmp.json "$HASH_FILE"
  103. else
  104. echo "::warning::Missing hash for ${SYSTEM}"
  105. fi
  106. done
  107. cat "$HASH_FILE"
  108. - name: Commit changes
  109. run: |
  110. set -euo pipefail
  111. HASH_FILE="nix/hashes.json"
  112. if [ -z "$(git status --short -- "$HASH_FILE")" ]; then
  113. echo "No changes to commit"
  114. echo "### Nix hashes" >> "$GITHUB_STEP_SUMMARY"
  115. echo "Status: no changes" >> "$GITHUB_STEP_SUMMARY"
  116. exit 0
  117. fi
  118. git add "$HASH_FILE"
  119. git commit -m "chore: update nix node_modules hashes"
  120. git pull --rebase --autostash origin "$GITHUB_REF_NAME"
  121. git push origin HEAD:"$GITHUB_REF_NAME"
  122. echo "### Nix hashes" >> "$GITHUB_STEP_SUMMARY"
  123. echo "Status: committed $(git rev-parse --short HEAD)" >> "$GITHUB_STEP_SUMMARY"