Skip to content

Commit db91b4f

Browse files
committed
fix(ci): vendor multiple changed go.mod directories on Renovate PRs
Closes #505 vendor.yml always regenerated govendor.toml at the repo root regardless of which go.mod/go.sum actually changed, so Renovate bumps to `templates/{default,workspace,image}` left those directories' manifests drifted and silently broke CI (#474). Add a detect job that diffs the PR's base/head SHAs for changed go.mod/go.sum files and passes every affected directory to govendor-update.yml, which now loops over each one and folds all regenerated manifests into a single amended commit. Signed-off-by: purpleclay <purpleclaygh@gmail.com>
1 parent 685717c commit db91b4f

2 files changed

Lines changed: 54 additions & 6 deletions

File tree

.github/workflows/govendor-update.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
workflow_call:
44
inputs:
55
working-directory:
6-
description: "Working directory for govendor manifest generation"
6+
description: "Working directory (or newline-separated list of directories) for govendor manifest generation"
77
required: false
88
type: string
99
default: "."
@@ -45,13 +45,27 @@ jobs:
4545
passphrase: ${{ secrets.gpg-passphrase }}
4646

4747
- name: Update govendor.toml
48-
working-directory: ${{ inputs.working-directory }}
4948
env:
5049
CO_AUTHOR: ${{ inputs.co-author }}
50+
DIRS: ${{ inputs.working-directory }}
5151
run: |
52-
nix run github:purpleclay/go-overlay#govendor
52+
changed=0
53+
while IFS= read -r dir; do
54+
[ -z "$dir" ] && continue
55+
echo "::group::govendor ($dir)"
56+
(cd "$dir" && nix run github:purpleclay/go-overlay#govendor) || {
57+
echo "::error::govendor failed for $dir"
58+
exit 1
59+
}
60+
echo "::endgroup::"
5361
54-
if git diff --quiet govendor.toml; then
62+
if ! git diff --quiet -- "$dir/govendor.toml"; then
63+
git add "$dir/govendor.toml"
64+
changed=1
65+
fi
66+
done <<< "$DIRS"
67+
68+
if [ "$changed" -eq 0 ]; then
5569
echo "No changes to govendor.toml"
5670
exit 0
5771
fi
@@ -60,6 +74,5 @@ jobs:
6074
CO_AUTHOR="$(git config user.name) <$(git config user.email)>"
6175
fi
6276
63-
git add govendor.toml
6477
git commit --amend --no-edit --trailer "Co-authored-by: $CO_AUTHOR"
6578
git push --force-with-lease

.github/workflows/vendor.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,44 @@ on:
55
paths: ["**/go.mod", "**/go.sum"]
66

77
jobs:
8-
vendor:
8+
detect:
99
if: startsWith(github.head_ref, 'renovate/')
10+
runs-on: ubuntu-24.04
11+
permissions:
12+
contents: read
13+
outputs:
14+
dirs: ${{ steps.detect.outputs.dirs }}
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
18+
with:
19+
fetch-depth: 0
20+
persist-credentials: false
21+
22+
- name: Detect changed module directories
23+
id: detect
24+
env:
25+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
26+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
27+
run: |
28+
dirs=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" \
29+
| awk '/(^|\/)go\.(mod|sum)$/{print}' \
30+
| xargs -r -n1 dirname | sort -u)
31+
32+
{
33+
echo "dirs<<EOF"
34+
echo "$dirs"
35+
echo "EOF"
36+
} >> "$GITHUB_OUTPUT"
37+
38+
vendor:
39+
needs: detect
40+
if: needs.detect.outputs.dirs != ''
41+
permissions:
42+
contents: read
1043
uses: purpleclay/go-overlay/.github/workflows/govendor-update.yml@main
44+
with:
45+
working-directory: ${{ needs.detect.outputs.dirs }}
1146
secrets:
1247
token: ${{ secrets.GH_NSV }}
1348
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}

0 commit comments

Comments
 (0)