Skip to content

Commit d38a92c

Browse files
committed
[BUILD] Upgrade go dependencies using a custom github action
1 parent e659d88 commit d38a92c

File tree

6 files changed

+133
-24
lines changed

6 files changed

+133
-24
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches:
66
- master
77
pull_request:
8+
repository_dispatch:
9+
types: [run-tests-for-generated-pr]
810

911
concurrency:
1012
group: ${{ github.workflow }}-${{ github.ref }}
@@ -18,6 +20,8 @@ jobs:
1820
steps:
1921
- name: Checkout code
2022
uses: actions/checkout@v5
23+
with:
24+
ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.pr_branch || github.ref }}
2125

2226
- name: Set up Go
2327
uses: actions/setup-go@v6
@@ -54,6 +58,8 @@ jobs:
5458
steps:
5559
- name: Checkout code
5660
uses: actions/checkout@v5
61+
with:
62+
ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.pr_branch || github.ref }}
5763

5864
- name: Set up Go
5965
uses: actions/setup-go@v6

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ on:
1717
pull_request:
1818
# The branches below must be a subset of the branches above
1919
branches: [ master ]
20+
repository_dispatch:
21+
types: [run-tests-for-generated-pr]
2022
schedule:
2123
- cron: '34 23 * * 4'
2224

@@ -44,6 +46,8 @@ jobs:
4446
steps:
4547
- name: Checkout repository
4648
uses: actions/checkout@v5
49+
with:
50+
ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.pr_branch || github.ref }}
4751

4852
# Initializes the CodeQL tools for scanning.
4953
- name: Initialize CodeQL

.github/workflows/e2e-test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches:
66
- master
77
pull_request:
8+
repository_dispatch:
9+
types: [run-tests-for-generated-pr]
810

911
concurrency:
1012
group: ${{ github.workflow }}-${{ github.ref }}
@@ -20,6 +22,8 @@ jobs:
2022
steps:
2123
- name: Checkout code
2224
uses: actions/checkout@v5
25+
with:
26+
ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.pr_branch || github.ref }}
2327

2428
- name: Clean workspace
2529
run: |
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Update Go Dependencies
2+
3+
on:
4+
schedule:
5+
# Run every Monday at 9:00 AM UTC
6+
- cron: '0 9 * * 1'
7+
workflow_dispatch: # Allow manual trigger
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
update-dependencies:
15+
name: Update Go Dependencies
16+
runs-on: ubuntu-24.04
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v5
21+
with:
22+
ref: master
23+
fetch-depth: 0
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v6
27+
with:
28+
go-version: '1.25'
29+
30+
- name: Update Go dependencies
31+
run: make update-go-deps
32+
33+
- name: Tidy dependencies
34+
run: make tidy
35+
36+
- name: Generate manifests
37+
run: make generate manifests
38+
39+
- name: Format and lint fix
40+
run: make fmt lint-fix
41+
42+
- name: Check for changes
43+
id: check_changes
44+
run: |
45+
if [ -n "$(git status --porcelain)" ]; then
46+
echo "has_changes=true" >> $GITHUB_OUTPUT
47+
else
48+
echo "has_changes=false" >> $GITHUB_OUTPUT
49+
fi
50+
51+
- name: Create Pull Request
52+
if: steps.check_changes.outputs.has_changes == 'true'
53+
id: create_pr
54+
uses: peter-evans/create-pull-request@v7
55+
with:
56+
token: ${{ secrets.GITHUB_TOKEN }}
57+
commit-message: 'chore(deps): update Go dependencies'
58+
title: 'chore(deps): update Go dependencies'
59+
body: |
60+
## Automated Go Dependencies Update
61+
62+
This PR updates Go module dependencies to their latest versions.
63+
64+
### Changes made:
65+
- Updated Go module dependencies via `make update-go-deps`
66+
- Regenerated manifests via `make generate manifests`
67+
- Applied formatting and linting fixes via `make fmt lint-fix`
68+
69+
Please review the changes and ensure all tests pass before merging.
70+
branch: automated/update-go-deps
71+
delete-branch: true
72+
labels: |
73+
dependencies
74+
go
75+
automated
76+
77+
- name: Trigger CI workflows for generated PR
78+
if: steps.check_changes.outputs.has_changes == 'true' && steps.create_pr.outputs.pull-request-number
79+
run: |
80+
curl -X POST \
81+
-H "Accept: application/vnd.github.v3+json" \
82+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
83+
https://api.github.com/repos/${{ github.repository }}/dispatches \
84+
-d '{
85+
"event_type": "run-tests-for-generated-pr",
86+
"client_payload": {
87+
"pr_number": "${{ steps.create_pr.outputs.pull-request-number }}",
88+
"pr_head_sha": "${{ steps.create_pr.outputs.pull-request-head-sha }}",
89+
"pr_branch": "automated/update-go-deps",
90+
"trigger_source": "update-go-deps"
91+
}
92+
}'
93+

Makefile

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,32 @@ release: check-release ## Tag and push a release.
294294
git tag -a ${REL_TAG} -m ${RELEASE_MSG}
295295
git push origin ${REL_TAG}
296296

297+
define update-module-deps
298+
echo "Updating $(1) deps"; \
299+
cd $(1); \
300+
go mod tidy; \
301+
for m in $$(go list -mod=readonly -m -f '{{ if and (not .Replace) (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
302+
go get -u $$m; \
303+
done; \
304+
go mod tidy
305+
endef
306+
297307
update-go-deps: ## Update Go modules dependencies.
298-
@echo "Finding all directories with go.mod files..."
299-
@for gomod in $$(find . -name "go.mod" | sort); do \
308+
@echo "Updating third_party modules first (deepest to shallowest)..."
309+
@for gomod in $$(find ./third_party -name "go.mod" 2>/dev/null | awk '{print length, $$0}' | sort -rn | cut -d' ' -f2-); do \
300310
dir=$$(dirname $$gomod); \
301-
( \
302-
echo "Updating $$dir deps"; \
303-
cd $$dir; \
304-
go mod tidy; \
305-
for m in $$(go list -mod=readonly -m -f '{{ if and (not .Replace) (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
306-
go get -u $$m; \
307-
done; \
308-
go mod tidy \
309-
) \
311+
($(call update-module-deps,$$dir)); \
310312
done
313+
@echo "Updating properties, api, and root modules..."
314+
@for dir in ./properties ./api .; do \
315+
if [ -f $$dir/go.mod ]; then \
316+
($(call update-module-deps,$$dir)); \
317+
fi \
318+
done
319+
@echo "Updating tests/e2e module last..."
320+
@if [ -f ./tests/e2e/go.mod ]; then \
321+
($(call update-module-deps,./tests/e2e)); \
322+
fi
311323

312324
tidy: ## Run go mod tidy in all Go modules.
313325
@echo "Finding all directories with go.mod files..."

renovate.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
"docker:enableMajor",
1515
"group:allDigest"
1616
],
17-
"postUpdateOptions": [
18-
"gomodTidy",
19-
"gomodUpdateImportPaths"
20-
],
17+
2118
"customManagers": [
2219
{
2320
"customType": "regex",
@@ -36,8 +33,8 @@
3633
"matchManagers": [
3734
"gomod"
3835
],
39-
"rangeStrategy": "replace",
40-
"description": "Prevent downgrades for all Go modules - only allow upgrades"
36+
"enabled": false,
37+
"description": "Disable Go module updates - handled by automated workflow: .github/workflows/update-go-deps.yml"
4138
},
4239
{
4340
"matchCategories": [
@@ -52,7 +49,6 @@
5249
"major"
5350
],
5451
"matchManagers": [
55-
"gomod",
5652
"github-actions",
5753
"maven",
5854
"dockerfile",
@@ -70,7 +66,6 @@
7066
"digest"
7167
],
7268
"matchManagers": [
73-
"gomod",
7469
"github-actions",
7570
"maven",
7671
"dockerfile",
@@ -79,11 +74,6 @@
7974
"helm-values",
8075
"docker"
8176
]
82-
},
83-
{
84-
"matchManagers": ["gomod"],
85-
"matchDepTypes": ["indirect"],
86-
"enabled": false
8777
}
8878
]
8979
}

0 commit comments

Comments
 (0)