|
| 1 | +# Nix builds require a pre-computed hash (vendorHash) of all Go dependencies. |
| 2 | +# This hash lives in flake.nix and must match the actual dependencies exactly — |
| 3 | +# if go.mod/go.sum change but vendorHash isn't updated, the Nix build breaks. |
| 4 | +# |
| 5 | +# This workflow automatically recalculates the hash whenever Go dependencies |
| 6 | +# change, so contributors don't need Nix installed locally to keep it in sync. |
| 7 | +# |
| 8 | +# Similar workflows in other repos: |
| 9 | +# https://github.com/open-component-model/ocm/blob/main/.github/workflows/flake_vendorhash.yaml |
| 10 | +# https://github.com/Tarow/dockdns/blob/main/.github/workflows/go_vendorhash.yaml |
| 11 | +# https://github.com/Mic92/sops-nix/blob/master/.github/workflows/update-vendor-hash.yml |
| 12 | +name: Update Nix vendorHash |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: |
| 17 | + - master |
| 18 | + paths: |
| 19 | + - go.mod |
| 20 | + - go.sum |
| 21 | + pull_request: |
| 22 | + branches: |
| 23 | + - master |
| 24 | + paths: |
| 25 | + - go.mod |
| 26 | + - go.sum |
| 27 | + |
| 28 | +jobs: |
| 29 | + update-vendor-hash: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + permissions: |
| 32 | + contents: write |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v6 |
| 35 | + with: |
| 36 | + ref: ${{ github.head_ref || github.ref_name }} |
| 37 | + |
| 38 | + - uses: DeterminateSystems/nix-installer-action@main |
| 39 | + |
| 40 | + # nix-update recalculates vendorHash by building the Go module fetcher, |
| 41 | + # comparing the expected vs actual hash, and patching flake.nix in-place. |
| 42 | + # --version=skip tells it to only update hashes, not the package version. |
| 43 | + - name: Update vendorHash |
| 44 | + run: nix run nixpkgs#nix-update -- --flake --version=skip flow-cli |
| 45 | + |
| 46 | + - name: Commit updated vendorHash |
| 47 | + run: | |
| 48 | + git diff --quiet flake.nix && exit 0 |
| 49 | + git config user.name "github-actions[bot]" |
| 50 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 51 | + git add flake.nix |
| 52 | + git commit -m "flake: update vendorHash" |
| 53 | + git push |
0 commit comments