update-nix-hashes.yml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. 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. SYSTEM: x86_64-linux
  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: DeterminateSystems/nix-installer-action@v20
  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 flake.lock
  37. run: |
  38. set -euo pipefail
  39. echo "📦 Updating flake.lock..."
  40. nix flake update
  41. echo "✅ flake.lock updated successfully"
  42. - name: Update node_modules hash
  43. run: |
  44. set -euo pipefail
  45. echo "🔄 Updating node_modules hash..."
  46. nix/scripts/update-hashes.sh
  47. echo "✅ node_modules hash updated successfully"
  48. - name: Commit hash changes
  49. env:
  50. TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
  51. run: |
  52. set -euo pipefail
  53. echo "🔍 Checking for changes in tracked Nix files..."
  54. summarize() {
  55. local status="$1"
  56. {
  57. echo "### Nix Hash Update"
  58. echo ""
  59. echo "- ref: ${GITHUB_REF_NAME}"
  60. echo "- status: ${status}"
  61. } >> "$GITHUB_STEP_SUMMARY"
  62. if [ -n "${GITHUB_SERVER_URL:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ] && [ -n "${GITHUB_RUN_ID:-}" ]; then
  63. echo "- run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" >> "$GITHUB_STEP_SUMMARY"
  64. fi
  65. echo "" >> "$GITHUB_STEP_SUMMARY"
  66. }
  67. FILES=(flake.lock flake.nix nix/node-modules.nix nix/hashes.json)
  68. STATUS="$(git status --short -- "${FILES[@]}" || true)"
  69. if [ -z "$STATUS" ]; then
  70. echo "✅ No changes detected. Hashes are already up to date."
  71. summarize "no changes"
  72. exit 0
  73. fi
  74. echo "📝 Changes detected:"
  75. echo "$STATUS"
  76. echo "🔗 Staging files..."
  77. git add "${FILES[@]}"
  78. echo "💾 Committing changes..."
  79. git commit -m "Update Nix flake.lock and hashes"
  80. echo "✅ Changes committed"
  81. BRANCH="${TARGET_BRANCH:-${GITHUB_REF_NAME}}"
  82. echo "🌳 Pulling latest from branch: $BRANCH"
  83. git pull --rebase origin "$BRANCH"
  84. echo "🚀 Pushing changes to branch: $BRANCH"
  85. git push origin HEAD:"$BRANCH"
  86. echo "✅ Changes pushed successfully"
  87. summarize "committed $(git rev-parse --short HEAD)"