master
yml 61 lines 1.97 KB
Raw
1 # Dependabot only updates go.mod/go.sum in the root module, but this repo has
2 # multiple Go modules (see docs/examples/). This workflow runs `make mod_tidy`
3 # on Dependabot PRs to keep all go.sum files in sync, preventing go-check CI
4 # failures.
5 name: Dependabot Tidy
6
7 on:
8 pull_request_target:
9 types: [opened, synchronize]
10 workflow_dispatch:
11 inputs:
12 pr_number:
13 description: 'PR number to run mod_tidy on'
14 required: true
15 type: number
16
17 permissions:
18 contents: write
19 pull-requests: write
20
21 jobs:
22 tidy:
23 if: github.actor == 'dependabot[bot]' || github.event_name == 'workflow_dispatch'
24 runs-on: ubuntu-latest
25 steps:
26 - name: Get PR info
27 id: pr
28 env:
29 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30 run: |
31 if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
32 pr_number="${{ inputs.pr_number }}"
33 else
34 pr_number="${{ github.event.pull_request.number }}"
35 fi
36 echo "number=$pr_number" >> $GITHUB_OUTPUT
37 branch=$(gh pr view "$pr_number" --repo "${{ github.repository }}" --json headRefName -q '.headRefName')
38 echo "branch=$branch" >> $GITHUB_OUTPUT
39 - uses: actions/checkout@v6
40 with:
41 ref: ${{ steps.pr.outputs.branch }}
42 token: ${{ secrets.GITHUB_TOKEN }}
43 - uses: actions/setup-go@v6
44 with:
45 go-version-file: go.mod
46 - name: Run make mod_tidy
47 run: make mod_tidy
48 - name: Check for changes
49 id: git-check
50 run: |
51 if [[ -n $(git status --porcelain) ]]; then
52 echo "modified=true" >> $GITHUB_OUTPUT
53 fi
54 - name: Commit changes
55 if: steps.git-check.outputs.modified == 'true'
56 run: |
57 git config user.name "github-actions[bot]"
58 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
59 git add -A
60 git commit -m "chore: run make mod_tidy"
61 git push