-
Notifications
You must be signed in to change notification settings - Fork 168
106 lines (94 loc) · 3.77 KB
/
bump-go-toolchain.yml
File metadata and controls
106 lines (94 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: Bump Go toolchain
on:
schedule:
# Run daily at 05:00 UTC.
- cron: "0 5 * * *"
workflow_dispatch:
inputs:
version:
description: >
Go toolchain version to use (e.g. "go1.25.9").
If empty, the latest patch release is detected automatically.
required: false
permissions:
contents: write
pull-requests: write
jobs:
bump-go-toolchain:
runs-on:
group: databricks-protected-runner-group-large
labels: linux-ubuntu-latest-large
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Determine current toolchain version
id: current
run: |
toolchain=$(grep '^toolchain' go.mod | awk '{print $2}')
minor=$(echo "$toolchain" | sed 's/^go//' | cut -d. -f1,2)
echo "toolchain=$toolchain" >> "$GITHUB_OUTPUT"
echo "minor=$minor" >> "$GITHUB_OUTPUT"
- name: Determine latest patch release
id: latest
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
if [ -n "$INPUT_VERSION" ]; then
if ! echo "$INPUT_VERSION" | grep -qE '^go[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Invalid version format: $INPUT_VERSION"
exit 1
fi
toolchain="$INPUT_VERSION"
else
minor=${{ steps.current.outputs.minor }}
toolchain=$(
curl -fsSL 'https://go.dev/dl/?mode=json' |
jq -r --arg minor "go${minor}." '[.[] | select(.version | startswith($minor))][0].version // empty'
)
if [ -z "$toolchain" ]; then
echo "No release found for go${minor}.x"
exit 1
fi
fi
echo "toolchain=$toolchain" >> "$GITHUB_OUTPUT"
- name: Check if update is needed
id: check
run: |
if [ "${{ steps.current.outputs.toolchain }}" = "${{ steps.latest.outputs.toolchain }}" ]; then
echo "Up to date: ${{ steps.current.outputs.toolchain }}"
echo "needed=false" >> "$GITHUB_OUTPUT"
else
echo "Update available: ${{ steps.current.outputs.toolchain }} -> ${{ steps.latest.outputs.toolchain }}"
echo "needed=true" >> "$GITHUB_OUTPUT"
fi
- name: Setup Go
if: steps.check.outputs.needed == 'true'
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
- name: Update go.mod files
if: steps.check.outputs.needed == 'true'
env:
TOOLCHAIN: ${{ steps.latest.outputs.toolchain }}
run: |
while IFS= read -r modfile; do
dir=$(dirname "$modfile")
if grep -q '^toolchain' "$modfile"; then
(cd "$dir" && go mod edit -toolchain="$TOOLCHAIN")
fi
done < <(git ls-files '**/go.mod' 'go.mod')
- name: Show diff
if: steps.check.outputs.needed == 'true'
run: git diff
- name: Create pull request
if: steps.check.outputs.needed == 'true' && inputs.version == ''
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
branch: auto/bump-go-toolchain
commit-message: "Bump Go toolchain to ${{ steps.latest.outputs.toolchain }}"
title: "Bump Go toolchain to ${{ steps.latest.outputs.toolchain }}"
body: |
Bump Go toolchain from `${{ steps.current.outputs.toolchain }}` to `${{ steps.latest.outputs.toolchain }}`.
Release notes: https://go.dev/doc/devel/release#${{ steps.latest.outputs.toolchain }}
reviewers: simonfaltum,andrewnester,anton-107,denik,janniklasrose,pietern,shreyas-goenka
labels: dependencies