|
| 1 | +name: Update gomod2nix on Dependabot PRs |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - 'go.mod' |
| 7 | + - 'go.sum' |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + update-gomod2nix: |
| 15 | + if: ${{ github.actor == 'dependabot[bot]' }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout PR |
| 20 | + uses: actions/checkout@v5 |
| 21 | + with: |
| 22 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 23 | + ref: ${{ github.event.pull_request.head.ref }} |
| 24 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + |
| 26 | + - name: Install Nix |
| 27 | + uses: cachix/install-nix-action@v31 |
| 28 | + with: |
| 29 | + nix_path: nixpkgs=channel:nixos-22.11 |
| 30 | + extra_nix_config: | |
| 31 | + access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} |
| 32 | + |
| 33 | + - name: Run gomod2nix |
| 34 | + run: nix develop -c gomod2nix |
| 35 | + |
| 36 | + - name: Check for changes |
| 37 | + id: changes |
| 38 | + run: | |
| 39 | + if git diff --quiet gomod2nix.toml; then |
| 40 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 41 | + else |
| 42 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 43 | + fi |
| 44 | + |
| 45 | + - name: Commit and push gomod2nix.toml |
| 46 | + if: steps.changes.outputs.changed == 'true' |
| 47 | + uses: EndBug/add-and-commit@v9 |
| 48 | + with: |
| 49 | + default_author: user_info |
| 50 | + message: "chore: update gomod2nix.toml" |
| 51 | + add: 'gomod2nix.toml' |
| 52 | + |
| 53 | + - name: Comment on PR |
| 54 | + if: steps.changes.outputs.changed == 'true' |
| 55 | + uses: actions/github-script@v7 |
| 56 | + with: |
| 57 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + script: | |
| 59 | + github.rest.issues.createComment({ |
| 60 | + issue_number: context.issue.number, |
| 61 | + owner: context.repo.owner, |
| 62 | + repo: context.repo.repo, |
| 63 | + body: '✅ Updated `gomod2nix.toml` automatically via `nix develop -c gomod2nix`' |
| 64 | + }) |
0 commit comments