From cfd7fb369aff8db6436e6251c72bcc11462b0e49 Mon Sep 17 00:00:00 2001 From: cucadmuh <49571317+cucadmuh@users.noreply.github.com> Date: Mon, 27 Apr 2026 21:20:19 +0300 Subject: [PATCH] ci(nix): auto-sync npmDepsHash when package-lock changes (#340) Add a GitHub Actions workflow that recomputes prefetch-npm-deps from package-lock.json and updates nix/upstream-sources.json so Nix builds stay aligned without manual hash edits. --- .github/workflows/nix-npm-deps-hash-sync.yml | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/nix-npm-deps-hash-sync.yml diff --git a/.github/workflows/nix-npm-deps-hash-sync.yml b/.github/workflows/nix-npm-deps-hash-sync.yml new file mode 100644 index 00000000..16ce6f23 --- /dev/null +++ b/.github/workflows/nix-npm-deps-hash-sync.yml @@ -0,0 +1,70 @@ +# Keeps `nix/upstream-sources.json` (`npmDepsHash`) in sync with `package-lock.json`. +# Runs in CI with Nix — contributors do not need Nix locally. +# +# Skips fork PRs (cannot push to the contributor branch); after merge to main, +# the push workflow updates the hash on main if needed. +name: Sync Nix npmDepsHash + +on: + push: + branches: [main] + paths: + - package-lock.json + - package.json + - nix/upstream-sources.json + pull_request: + paths: + - package-lock.json + - package.json + - nix/upstream-sources.json + workflow_dispatch: + +concurrency: + group: nix-npm-hash-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + sync: + runs-on: ubuntu-24.04 + permissions: + contents: write + # Fork PRs: token cannot push to the fork — merge to main will run the push workflow instead. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }} + + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@v15 + + - name: Recompute npmDepsHash from package-lock.json + run: | + set -euo pipefail + HASH="$(nix run nixpkgs/nixos-unstable#prefetch-npm-deps -- package-lock.json)" + echo "Computed npmDepsHash: $HASH" + TMP="$(mktemp)" + jq --arg h "$HASH" '.npmDepsHash = $h' nix/upstream-sources.json > "$TMP" + mv "$TMP" nix/upstream-sources.json + + - name: Commit and push if changed + env: + PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} + run: | + set -euo pipefail + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add nix/upstream-sources.json + if git diff --cached --quiet; then + echo "npmDepsHash already matches package-lock.json — nothing to commit." + exit 0 + fi + git commit -m "chore(nix): sync npmDepsHash with package-lock.json" + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + git push origin "HEAD:${PR_HEAD_REF}" + else + git push origin "HEAD:${{ github.ref_name }}" + fi