nix-hashes.yml 4.2 KB

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