Skip to content

Commit f709131

Browse files
committed
Adding a custom go-setup command
The new action will centralize go version so we stop having them peppered accross different files. It also provides simple "strategies" that cover all our cases (canary, latest-stable, old-stable). Signed-off-by: apostasie <[email protected]>
1 parent 6e913a6 commit f709131

File tree

6 files changed

+100
-70
lines changed

6 files changed

+100
-70
lines changed

.github/actions/install-go/action.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: "Checkout and install go"
2+
description: "This action will install go (currently supported version by default). Operator may optionally require the `strategy` input:
3+
- 'canary', for the latest RC/beta
4+
- 'latest-stable', for the latest patch release for the currently supported version (this is normally the default, unless nerdctl is lagging)
5+
- 'old-stable' for the latest patch release of the minimum minor go version nerdctl is supporting"
6+
inputs:
7+
cache-dependency-path:
8+
description: 'Used to specify the path to a dependency file - go.sum'
9+
strategy:
10+
default: ""
11+
description: "You may set this to `canary`, `latest-stable`, or `old-stable`. Otherwise defauls to the explicitly supported version."
12+
# These below are technically not input variables (that we expect people to specific or change).
13+
# We are just abusing the system here for convenience, since a composite action does not let you define env.
14+
# This here is the one, central location where we would update go versions when there is a newly supported go version.
15+
_current:
16+
default: "1.23.4"
17+
description: "What we consider the current blessed go version (typically the latest patch release of the last major.minor version)"
18+
_stable:
19+
default: "1.23.x"
20+
description: "The latest major.minor version we support"
21+
_old_stable:
22+
default: "1.22.x"
23+
description: "The minimum major.minor go version that we still support"
24+
25+
runs:
26+
using: composite
27+
steps:
28+
- name: "Set GO_VERSION environment variable from user strategy"
29+
shell: bash
30+
run: |
31+
golang::canary(){
32+
# Enable extended globbing features to use advanced pattern matching
33+
shopt -s extglob
34+
# Get latest golang version and split it in components
35+
norm=()
36+
while read -r line; do
37+
line_trimmed="${line//+([[:space:]])/}"
38+
norm+=("$line_trimmed")
39+
done < \
40+
<(sed -E 's/^go([0-9]+)[.]([0-9]+)([.]([0-9]+))?(([a-z]+)([0-9]+))?/\1.\2\n\4\n\6\n\7/i' \
41+
<(curl -fsSL "https://go.dev/dl/?mode=json&include=all" | jq -rc .[0].version) \
42+
)
43+
# Serialize version, making sure we have a patch version, and separate possible rcX into .rc-X
44+
[ "${norm[1]}" != "" ] || norm[1]="0"
45+
norm[1]=".${norm[1]}"
46+
[ "${norm[2]}" == "" ] || norm[2]="-${norm[2]}"
47+
[ "${norm[3]}" == "" ] || norm[3]=".${norm[3]}"
48+
# Save it
49+
IFS=
50+
echo "GO_VERSION=${norm[*]}" >> "$GITHUB_ENV"
51+
}
52+
53+
if [ "${{ inputs.strategy }}" == "canary" ]; then
54+
golang::canary
55+
elif [ "${{ inputs.strategy }}" == "latest-stable" ]; then
56+
echo "GO_VERSION=${{ inputs._stable }}" >> "$GITHUB_ENV"
57+
elif [ "${{ inputs.strategy }}" == "old-stable" ]; then
58+
echo "GO_VERSION=${{ inputs._old_stable }}" >> "$GITHUB_ENV"
59+
else
60+
echo "GO_VERSION=${{ inputs._current }}" >> "$GITHUB_ENV"
61+
fi
62+
- name: "Setup Go"
63+
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
64+
with:
65+
go-version: ${{ env.GO_VERSION }}
66+
cache-dependency-path: ${{ inputs.cache-dependency-path }}
67+
cache: true
68+
- name: "Cleanup go version string"
69+
shell: bash
70+
# Remove possible trailing .x
71+
run: |
72+
echo "GO_VERSION=${GO_VERSION%.x*}" >> "$GITHUB_ENV"

.github/workflows/lint.yml

+11-19
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ on:
77
- 'release/**'
88
pull_request:
99

10-
env:
11-
GO_VERSION: 1.23.x
12-
1310
jobs:
1411
go:
1512
timeout-minutes: 5
16-
name: "go | ${{ matrix.goos }} | ${{ matrix.canary }}"
13+
name: "go | ${{ matrix.goos }} | ${{ matrix.goversion }}"
1714
runs-on: "${{ matrix.os }}"
1815
defaults:
1916
run:
@@ -23,33 +20,28 @@ jobs:
2320
include:
2421
- os: ubuntu-24.04
2522
goos: linux
23+
goversion: latest-stable
2624
- os: ubuntu-24.04
2725
goos: freebsd
26+
goversion: latest-stable
2827
# FIXME: this is currently failing in a non-sensical way, so, running on linux instead...
2928
# - os: windows-2022
3029
- os: ubuntu-24.04
3130
goos: windows
31+
goversion: latest-stable
3232
- os: ubuntu-24.04
3333
goos: linux
34-
# This allows the canary script to select any upcoming golang alpha/beta/RC
35-
canary: go-canary
34+
goversion: canary
3635
env:
3736
GOOS: "${{ matrix.goos }}"
3837
steps:
3938
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4039
with:
4140
fetch-depth: 1
42-
- name: Set GO env
43-
run: |
44-
# If canary is specified, get the latest available golang pre-release instead of the major version
45-
if [ "$canary" != "" ]; then
46-
. ./hack/build-integration-canary.sh
47-
canary::golang::latest
48-
fi
49-
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
41+
- name: "Install go"
42+
uses: ./.github/actions/install-go
5043
with:
51-
go-version: ${{ env.GO_VERSION }}
52-
check-latest: true
44+
strategy: ${{ matrix.goversion }}
5345
- name: golangci-lint
5446
uses: golangci/golangci-lint-action@774c35bcccffb734694af9e921f12f57d882ef74 # v6.1.1
5547
with:
@@ -62,10 +54,10 @@ jobs:
6254
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6355
with:
6456
fetch-depth: 1
65-
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
57+
- name: "Install go"
58+
uses: ./.github/actions/install-go
6659
with:
67-
go-version: ${{ env.GO_VERSION }}
68-
check-latest: true
60+
strategy: latest-stable
6961
- name: yaml
7062
run: make lint-yaml
7163
- name: shell

.github/workflows/project.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ jobs:
1717
with:
1818
path: src/github.com/containerd/nerdctl
1919
fetch-depth: 100
20-
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
20+
- uses: ./src/github.com/containerd/nerdctl/.github/actions/install-go
2121
with:
22-
go-version: ${{ env.GO_VERSION }}
2322
cache-dependency-path: src/github.com/containerd/nerdctl
2423
- uses: containerd/project-checks@434a07157608eeaa1d5c8d4dd506154204cd9401 # v1.1.0
2524
with:
2625
working-directory: src/github.com/containerd/nerdctl
27-
repo-access-token: ${{ secrets.GITHUB_TOKEN }}
2826
- run: ./hack/verify-no-patent.sh
2927
working-directory: src/github.com/containerd/nerdctl
3028
- run: ./hack/verify-pkg-isolation.sh

.github/workflows/test-canary.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5959
with:
6060
fetch-depth: 1
61-
- name: Set GO env
61+
- name: Set Containerd version
6262
run: |
6363
# Get latest containerd
6464
args=(curl --proto '=https' --tlsv1.2 -fsSL -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28")
@@ -67,13 +67,10 @@ jobs:
6767
} || args+=(-H "Authorization: Bearer $GITHUB_TOKEN")
6868
ctd_v="$("${args[@]}" https://api.github.com/repos/containerd/containerd/tags | jq -rc .[0].name)"
6969
echo "CONTAINERD_VERSION=${ctd_v:1}" >> "$GITHUB_ENV"
70-
71-
. ./hack/build-integration-canary.sh
72-
canary::golang::latest
73-
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
70+
- name: "Install go"
71+
uses: ./.github/actions/install-go
7472
with:
75-
go-version: ${{ env.GO_VERSION }}
76-
check-latest: true
73+
strategy: canary
7774
- run: go install ./cmd/nerdctl
7875
- run: go install -v gotest.tools/gotestsum@v1
7976
# This here is solely to get the cni install script, which has not been modified in 3+ years.

.github/workflows/test.yml

+12-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010
- '**.md'
1111

1212
env:
13-
GO_VERSION: 1.23.x
1413
SHORT_TIMEOUT: 5
1514
LONG_TIMEOUT: 60
1615

@@ -76,10 +75,10 @@ jobs:
7675
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
7776
with:
7877
fetch-depth: 1
79-
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
78+
- name: "Install go"
79+
uses: ./.github/actions/install-go
8080
with:
81-
go-version: ${{ env.GO_VERSION }}
82-
check-latest: true
81+
strategy: latest-stable
8382
- if: ${{ matrix.goos=='windows' }}
8483
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
8584
with:
@@ -310,17 +309,17 @@ jobs:
310309
runs-on: ubuntu-24.04
311310
strategy:
312311
matrix:
313-
go-version: ["1.22.x", "1.23.x"]
312+
go-version: ["old-stable", "latest-stable"]
314313
steps:
315314
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
316315
with:
317316
fetch-depth: 1
318-
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
317+
- name: "Install go"
318+
uses: ./.github/actions/install-go
319319
with:
320-
go-version: ${{ matrix.go-version }}
321-
check-latest: true
320+
strategy: ${{ matrix.go-version }}
322321
- name: "build"
323-
run: GO_VERSION="$(echo ${{ matrix.go-version }} | sed -e s/.x//)" make binaries
322+
run: make binaries
324323

325324
test-integration-docker-compatibility:
326325
timeout-minutes: 30
@@ -330,10 +329,8 @@ jobs:
330329
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
331330
with:
332331
fetch-depth: 1
333-
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
334-
with:
335-
go-version: ${{ env.GO_VERSION }}
336-
check-latest: true
332+
- name: "Install go"
333+
uses: ./.github/actions/install-go
337334
- name: "Register QEMU (tonistiigi/binfmt)"
338335
run: |
339336
# `--install all` will only install emulation for architectures that cannot be natively executed
@@ -365,10 +362,8 @@ jobs:
365362
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
366363
with:
367364
fetch-depth: 1
368-
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
369-
with:
370-
go-version: ${{ env.GO_VERSION }}
371-
check-latest: true
365+
- name: "Install go"
366+
uses: ./.github/actions/install-go
372367
- run: go install ./cmd/nerdctl
373368
- run: go install -v gotest.tools/gotestsum@v1
374369
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

hack/build-integration-canary.sh

-24
Original file line numberDiff line numberDiff line change
@@ -322,27 +322,3 @@ canary::golang::hublatest(){
322322

323323
printf "%s" "$available_version"
324324
}
325-
326-
canary::golang::latest(){
327-
# Enable extended globbing features to use advanced pattern matching
328-
shopt -s extglob
329-
330-
# Get latest golang version and split it in components
331-
norm=()
332-
while read -r line; do
333-
line_trimmed="${line//+([[:space:]])/}"
334-
norm+=("$line_trimmed")
335-
done < \
336-
<(sed -E 's/^go([0-9]+)[.]([0-9]+)([.]([0-9]+))?(([a-z]+)([0-9]+))?/\1.\2\n\4\n\6\n\7/i' \
337-
<(curl -fsSL "https://go.dev/dl/?mode=json&include=all" | jq -rc .[0].version) \
338-
)
339-
340-
# Serialize version, making sure we have a patch version, and separate possible rcX into .rc-X
341-
[ "${norm[1]}" != "" ] || norm[1]="0"
342-
norm[1]=".${norm[1]}"
343-
[ "${norm[2]}" == "" ] || norm[2]="-${norm[2]}"
344-
[ "${norm[3]}" == "" ] || norm[3]=".${norm[3]}"
345-
# Save it
346-
IFS=
347-
echo "GO_VERSION=${norm[*]}" >> "$GITHUB_ENV"
348-
}

0 commit comments

Comments
 (0)