nix-hashes.yml 4.1 KB

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