update-nix-hashes.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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-flake:
  18. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
  19. runs-on: blacksmith-4vcpu-ubuntu-2404
  20. env:
  21. TITLE: flake.lock
  22. steps:
  23. - name: Checkout repository
  24. uses: actions/checkout@v4
  25. with:
  26. token: ${{ secrets.GITHUB_TOKEN }}
  27. fetch-depth: 0
  28. ref: ${{ github.head_ref || github.ref_name }}
  29. repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
  30. - name: Setup Nix
  31. uses: nixbuild/nix-quick-install-action@v34
  32. - name: Configure git
  33. run: |
  34. git config --global user.email "[email protected]"
  35. git config --global user.name "Github Action"
  36. - name: Update ${{ env.TITLE }}
  37. run: |
  38. set -euo pipefail
  39. echo "📦 Updating $TITLE..."
  40. nix flake update
  41. echo "✅ $TITLE updated successfully"
  42. - name: Commit ${{ env.TITLE }} changes
  43. env:
  44. TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
  45. run: |
  46. set -euo pipefail
  47. echo "🔍 Checking for changes in tracked files..."
  48. summarize() {
  49. local status="$1"
  50. {
  51. echo "### Nix $TITLE"
  52. echo ""
  53. echo "- ref: ${GITHUB_REF_NAME}"
  54. echo "- status: ${status}"
  55. } >> "$GITHUB_STEP_SUMMARY"
  56. if [ -n "${GITHUB_SERVER_URL:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ] && [ -n "${GITHUB_RUN_ID:-}" ]; then
  57. echo "- run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" >> "$GITHUB_STEP_SUMMARY"
  58. fi
  59. echo "" >> "$GITHUB_STEP_SUMMARY"
  60. }
  61. FILES=(flake.lock flake.nix)
  62. STATUS="$(git status --short -- "${FILES[@]}" || true)"
  63. if [ -z "$STATUS" ]; then
  64. echo "✅ No changes detected."
  65. summarize "no changes"
  66. exit 0
  67. fi
  68. echo "📝 Changes detected:"
  69. echo "$STATUS"
  70. echo "🔗 Staging files..."
  71. git add "${FILES[@]}"
  72. echo "💾 Committing changes..."
  73. git commit -m "Update $TITLE"
  74. echo "✅ Changes committed"
  75. BRANCH="${TARGET_BRANCH:-${GITHUB_REF_NAME}}"
  76. echo "🌳 Pulling latest from branch: $BRANCH"
  77. git pull --rebase origin "$BRANCH"
  78. echo "🚀 Pushing changes to branch: $BRANCH"
  79. git push origin HEAD:"$BRANCH"
  80. echo "✅ Changes pushed successfully"
  81. summarize "committed $(git rev-parse --short HEAD)"
  82. update-node-modules-hash:
  83. needs: update-flake
  84. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
  85. strategy:
  86. fail-fast: false
  87. matrix:
  88. include:
  89. - system: x86_64-linux
  90. host: blacksmith-4vcpu-ubuntu-2404
  91. - system: aarch64-linux
  92. host: blacksmith-4vcpu-ubuntu-2404-arm
  93. - system: x86_64-darwin
  94. host: macos-15-intel
  95. - system: aarch64-darwin
  96. host: macos-latest
  97. runs-on: ${{ matrix.host }}
  98. env:
  99. SYSTEM: ${{ matrix.system }}
  100. TITLE: node_modules hash (${{ matrix.system }})
  101. steps:
  102. - name: Checkout repository
  103. uses: actions/checkout@v4
  104. with:
  105. token: ${{ secrets.GITHUB_TOKEN }}
  106. fetch-depth: 0
  107. ref: ${{ github.head_ref || github.ref_name }}
  108. repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
  109. - name: Setup Nix
  110. uses: nixbuild/nix-quick-install-action@v34
  111. - name: Configure git
  112. run: |
  113. git config --global user.email "[email protected]"
  114. git config --global user.name "Github Action"
  115. - name: Pull latest changes
  116. env:
  117. TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
  118. run: |
  119. BRANCH="${TARGET_BRANCH:-${GITHUB_REF_NAME}}"
  120. git pull origin "$BRANCH"
  121. - name: Update ${{ env.TITLE }}
  122. run: |
  123. set -euo pipefail
  124. echo "🔄 Updating $TITLE..."
  125. nix/scripts/update-hashes.sh
  126. echo "✅ $TITLE updated successfully"
  127. - name: Commit ${{ env.TITLE }} changes
  128. env:
  129. TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
  130. run: |
  131. set -euo pipefail
  132. echo "🔍 Checking for changes in tracked files..."
  133. summarize() {
  134. local status="$1"
  135. {
  136. echo "### Nix $TITLE"
  137. echo ""
  138. echo "- ref: ${GITHUB_REF_NAME}"
  139. echo "- status: ${status}"
  140. } >> "$GITHUB_STEP_SUMMARY"
  141. if [ -n "${GITHUB_SERVER_URL:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ] && [ -n "${GITHUB_RUN_ID:-}" ]; then
  142. echo "- run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" >> "$GITHUB_STEP_SUMMARY"
  143. fi
  144. echo "" >> "$GITHUB_STEP_SUMMARY"
  145. }
  146. FILES=(nix/hashes.json)
  147. STATUS="$(git status --short -- "${FILES[@]}" || true)"
  148. if [ -z "$STATUS" ]; then
  149. echo "✅ No changes detected."
  150. summarize "no changes"
  151. exit 0
  152. fi
  153. echo "📝 Changes detected:"
  154. echo "$STATUS"
  155. echo "🔗 Staging files..."
  156. git add "${FILES[@]}"
  157. echo "💾 Committing changes..."
  158. git commit -m "Update $TITLE"
  159. echo "✅ Changes committed"
  160. BRANCH="${TARGET_BRANCH:-${GITHUB_REF_NAME}}"
  161. echo "🌳 Pulling latest from branch: $BRANCH"
  162. git pull --rebase origin "$BRANCH"
  163. echo "🚀 Pushing changes to branch: $BRANCH"
  164. git push origin HEAD:"$BRANCH"
  165. echo "✅ Changes pushed successfully"
  166. summarize "committed $(git rev-parse --short HEAD)"