sync-gomod2nix.yml

 1name: Sync gomod2nix.toml
 2
 3on:
 4  push:
 5    branches: [master]
 6    paths:
 7      - go.mod
 8      - go.sum
 9  workflow_dispatch:
10
11permissions:
12  contents: write
13  pull-requests: write
14
15jobs:
16  sync:
17    runs-on: ubuntu-latest
18    steps:
19      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
20
21      - name: Install Nix
22        uses: cachix/install-nix-action@8aa03977d8d733052d78f4e008a241fd1dbf36b3 # v31
23        with:
24          nix_path: nixpkgs=channel:nixpkgs-unstable
25
26      - name: Generate gomod2nix.toml
27        run: nix develop --command gomod2nix generate
28
29      - name: Create Pull Request
30        env:
31          GH_TOKEN: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}
32        run: |
33          git diff --quiet gomod2nix.toml && exit 0
34          BRANCH="chore/sync-gomod2nix"
35          git config user.name "Floatpane Bot"
36          git config user.email "us@floatpane.com"
37          git checkout -b "$BRANCH"
38          git add gomod2nix.toml
39          git commit -m "chore: sync gomod2nix.toml"
40          git push -f origin "$BRANCH"
41          if ! gh pr list --head "$BRANCH" --state open | grep -q .; then
42            BODY=$(cat <<'EOF'
43          ## What?
44
45          Regenerates `gomod2nix.toml` to reflect the current `go.mod` / `go.sum`.
46
47          ## Why?
48
49          Keeps the Nix build in sync with Go module changes. Without this, `nix build` fails when new or upgraded Go deps are missing from `gomod2nix.toml`. Generated automatically by the gomod2nix sync workflow.
50          EOF
51          )
52            gh pr create --title "chore: sync gomod2nix.toml" --body "$BODY" --base master --label chore --label area/nix
53          fi