update-nix-hashes.yml 3.0 KB

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