Skip to content

Commit f1812ad

Browse files
committed
GitHub Actions: Notify Go Module Major Version Updates
When Go modules mature and their major version has exceeded one, the module path requires a version suffix, such as "/v2"[0]. Unfortunately, the Dependabot is unable to detect such a Go module major version bump for suffixed major versions[1], resulting in stalling dependencies. By introducing another GitHub Actions Workflow utilizing gomajor[2], those major version updates for Go modules can be identified. As a scheduled workflow, running each Monday morning, it will either create or update an open GitHub issue with all currently available major version updates for referenced Go modules. [0]: https://go.dev/ref/mod#major-version-suffixes [1]: dependabot/dependabot-core#2213 [2]: https://github.com/icholy/gomajor
1 parent 112f6d7 commit f1812ad

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

.github/workflows/go-mod-major.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/sh
2+
3+
# A GitHub issue with this title and those labels (might be just one)
4+
# will be created or, if it already exists and is open, will be reused.
5+
GH_ISSUE_TITLE="Go Module Major Version Updates"
6+
GH_ISSUE_LABELS="dependencies"
7+
8+
set -eu
9+
10+
# UPDATE_MSG will be altered from within check_updates()
11+
UPDATE_MSG=""
12+
13+
# check_updates DIR check if any major updates are within DIR.
14+
# Found updates are being added to UPDATE_MSG
15+
check_updates() {
16+
available_updates="$(gomajor list -major -dir "$1" 2>&1 \
17+
| grep -v "no module versions found" \
18+
| awk '{ print NR ". `" $0 "`" }')"
19+
20+
if [ -z "$available_updates" ]; then
21+
echo "Nothing to do in $1"
22+
return
23+
fi
24+
25+
echo "Found $(echo "$available_updates" | wc -l) updates in $1"
26+
UPDATE_MSG="$(cat <<EOF
27+
$UPDATE_MSG
28+
29+
### Updates in \`$1\`
30+
$available_updates
31+
32+
EOF
33+
)"
34+
}
35+
36+
for DIR in "$@"; do
37+
check_updates "$DIR"
38+
done
39+
40+
if [ -z "$UPDATE_MSG" ]; then
41+
echo "Nothing to do at all :-)"
42+
exit 0
43+
fi
44+
45+
UPDATE_MSG="$(cat <<EOF
46+
## $GH_ISSUE_TITLE
47+
There are major version updates available for used Go modules.
48+
49+
$UPDATE_MSG
50+
EOF
51+
)"
52+
53+
active_issue="$(gh issue list \
54+
--label "$GH_ISSUE_LABELS" \
55+
--state "open" \
56+
--search "in:title \"$GH_ISSUE_TITLE\"" \
57+
--json "number" \
58+
--jq ".[0].number")"
59+
60+
if [ -n "$active_issue" ]; then
61+
gh issue comment "$active_issue" \
62+
--body "$UPDATE_MSG"
63+
else
64+
gh issue create \
65+
--title "$GH_ISSUE_TITLE" \
66+
--label "$GH_ISSUE_LABELS" \
67+
--body "$UPDATE_MSG"
68+
fi

.github/workflows/go-mod-major.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Go Module Major Update Check
2+
on:
3+
schedule:
4+
- cron: '30 6 * * 1' # at 06:30 every Monday morning
5+
6+
jobs:
7+
go_mod_update_issue:
8+
name: Go Module Major Update Check and Issue Creation
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
issues: write
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version: stable
19+
20+
- run: go install github.com/icholy/gomajor@latest
21+
22+
- run: .github/workflows/go-mod-major.sh "." "tests"
23+
env:
24+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
GH_REPO: ${{ github.repository }}

0 commit comments

Comments
 (0)