1
+ # Copyright 2025 Deutsche Telekom IT GmbH
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ name : Dependabot Tidy
6
+
7
+ on :
8
+ pull_request :
9
+ paths :
10
+ - ' **/go.mod'
11
+ - ' **/go.sum'
12
+ workflow_dispatch :
13
+
14
+ jobs :
15
+ tidy :
16
+ name : Run go mod tidy
17
+ if : github.actor == 'dependabot[bot]' || github.event_name == 'workflow_dispatch'
18
+ runs-on : ubuntu-latest
19
+ permissions :
20
+ contents : write
21
+ pull-requests : write
22
+
23
+ steps :
24
+ - uses : actions/checkout@v5
25
+ with :
26
+ ref : ${{ github.head_ref }}
27
+ fetch-depth : 0
28
+
29
+ - name : Set up Go
30
+ uses : actions/setup-go@v5
31
+ with :
32
+ go-version : ' stable'
33
+ check-latest : true
34
+
35
+ - name : Run go mod tidy on all modules
36
+ run : |
37
+ echo "Identified modules:"
38
+ MODULES=$(find . -name 'go.mod' -exec dirname {} \; | sort)
39
+ echo "$MODULES"
40
+ echo "\nRunning go mod tidy on all modules..."
41
+ echo "$MODULES" | while read -r module_dir; do
42
+ if [ -n "$module_dir" ]; then
43
+ echo "Processing: $module_dir"
44
+ (cd "$module_dir" && go mod tidy)
45
+ fi
46
+ done
47
+
48
+ - name : Check for changes
49
+ id : check_changes
50
+ run : |
51
+ if [[ -n "$(git status --porcelain)" ]]; then
52
+ echo "changes=true" >> $GITHUB_OUTPUT
53
+ echo "Changes detected after running go mod tidy:"
54
+ git diff --name-only
55
+ else
56
+ echo "changes=false" >> $GITHUB_OUTPUT
57
+ echo "No changes detected after running go mod tidy"
58
+ fi
59
+
60
+ - name : Commit and push changes
61
+ if : steps.check_changes.outputs.changes == 'true'
62
+ run : |
63
+ git config user.name "github-actions[bot]"
64
+ git config user.email "github-actions[bot]@users.noreply.github.com"
65
+ git add .
66
+ git commit -m "chore: run go mod tidy for modules updated by dependabot"
67
+ git push
68
+
69
+ - name : Add comment to PR
70
+ if : steps.check_changes.outputs.changes == 'true'
71
+ uses : actions/github-script@v7
72
+ with :
73
+ github-token : ${{ secrets.GITHUB_TOKEN }}
74
+ script : |
75
+ github.rest.issues.createComment({
76
+ issue_number: context.issue.number,
77
+ owner: context.repo.owner,
78
+ repo: context.repo.repo,
79
+ body: '✅ `go mod tidy` has been run for all Go modules and changes have been committed to this PR.'
80
+ })
0 commit comments