Skip to content

Commit abc1cec

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 abc1cec

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
cd "$1"
17+
available_updates="$(gomajor list -major 2>&1 \
18+
| grep -v "no module versions found" \
19+
| awk '{ print NR ". `" $0 "`" }')"
20+
cd - > /dev/null
21+
22+
if [ -z "$available_updates" ]; then
23+
echo "Nothing to do in $1"
24+
return
25+
fi
26+
27+
echo "Found $(echo "$available_updates" | wc -l) updates in $1"
28+
UPDATE_MSG="$(cat <<EOF
29+
$UPDATE_MSG
30+
31+
### Updates in \`$1\`
32+
$available_updates
33+
34+
EOF
35+
)"
36+
}
37+
38+
for DIR in "$@"; do
39+
check_updates "$DIR"
40+
done
41+
42+
if [ -z "$UPDATE_MSG" ]; then
43+
echo "Nothing to do at all :-)"
44+
exit 0
45+
fi
46+
47+
UPDATE_MSG="$(cat <<EOF
48+
## $GH_ISSUE_TITLE
49+
There are major version updates available for used Go modules.
50+
51+
$UPDATE_MSG
52+
EOF
53+
)"
54+
55+
active_issue="$(gh issue list \
56+
--label "$GH_ISSUE_LABELS" \
57+
--state "open" \
58+
--search "in:title \"$GH_ISSUE_TITLE\"" \
59+
--json "number" \
60+
--jq ".[0].number")"
61+
62+
if [ -n "$active_issue" ]; then
63+
gh issue comment "$active_issue" \
64+
--body "$UPDATE_MSG"
65+
else
66+
gh issue create \
67+
--title "$GH_ISSUE_TITLE" \
68+
--label "$GH_ISSUE_LABELS" \
69+
--body "$UPDATE_MSG"
70+
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)