Skip to content

Commit 0cc10f4

Browse files
committed
workflows: Auto go mod tidy dependabot PRs
Do to our repo structure of go modules, we frequently hit issues that dependabout bumps versions, but other modules that reference the changes module don't get updated, so we have error with go mod and sum not being tidied. Attempt to create a workflow that will automatically do this change, so that we don't need to do it manually anymore. Signed-off-by: stevenhorsman <[email protected]>
1 parent 131d6ae commit 0cc10f4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Automatically run go mod tidy on dependabot PRs
2+
on:
3+
pull_request:
4+
branches: [ main ]
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
8+
cancel-in-progress: true
9+
10+
permissions: {}
11+
12+
jobs:
13+
tidy-dependabot-pr:
14+
name: Run go mod tidy on dependabot PR
15+
runs-on: ubuntu-24.04
16+
if: github.event.pull_request.user.login == 'dependabot[bot]'
17+
permissions:
18+
contents: write # We need permissions to push new content to the PR
19+
pull-requests: write # Permissions to create a new PR and close the original
20+
21+
steps:
22+
- name: Checkout the pull request code
23+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
24+
with:
25+
persist-credentials: false
26+
27+
- name: Run go mod tidy
28+
run: |
29+
./hack/go-tidy.sh
30+
31+
- name: Commit and push changes
32+
uses: devops-infra/action-commit-push@8a2d9d73c3f506468129be2e4409e60dbed70357 # v1.0.3
33+
with:
34+
github_token: ${{ secrets.GITHUB_TOKEN }}
35+
commit_message: "chore: Auto-run go mod tidy after Dependabot update"
36+
37+
- name: Create new pull request
38+
id: create_pr
39+
uses: devops-infra/action-pull-request@b2895bff2ff66579f6704d717a1ea75fad919e84 # v1.0.2
40+
with:
41+
github_token: ${{ secrets.GITHUB_TOKEN }}
42+
body: "**Automated pull request**<br><br>Updating dependabot PR with go mod tidy"
43+
title: ${{ github.event.commits[0].message }}
44+
45+
- name: Close original Pull Request
46+
run: gh pr close "${ORIGINAL_PR}" --comment "PR replaced with ${REPLACEMENT_PR}"
47+
env:
48+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
ORIGINAL_PR: ${{ github.event.pull_request.number }}
50+
REPLACEMENT_PR: ${{ steps.create_pr.outputs.pr_number }}

0 commit comments

Comments
 (0)