Skip to content

Commit ef6c80b

Browse files
authored
Merge pull request #3321 from apostasie/b-dev-3320-canary-lint
Add linter to Canary and fix go 1.23 linting issues
2 parents 7dd3050 + 787b4ac commit ef6c80b

13 files changed

+152
-136
lines changed

Diff for: .github/workflows/test-canary.yml

+29-26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ env:
1515
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1616

1717
jobs:
18+
lint:
19+
runs-on: "ubuntu-24.04"
20+
timeout-minutes: 20
21+
steps:
22+
- uses: actions/[email protected]
23+
with:
24+
fetch-depth: 1
25+
- name: Set GO env
26+
run: |
27+
. ./hack/build-integration-canary.sh
28+
canary::golang::latest
29+
- uses: actions/setup-go@v5
30+
with:
31+
go-version: ${{ env.GO_VERSION }}
32+
check-latest: true
33+
cache: true
34+
- name: golangci-lint
35+
uses: golangci/[email protected]
36+
with:
37+
args: --verbose
38+
1839
linux:
1940
runs-on: "ubuntu-24.04"
2041
timeout-minutes: 40
@@ -24,7 +45,8 @@ jobs:
2445
fetch-depth: 1
2546
- name: "Prepare integration test environment"
2647
run: |
27-
./hack/build-integration-canary.sh
48+
. ./hack/build-integration-canary.sh
49+
canary::build::integration
2850
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
2951
run: |
3052
sudo systemctl disable --now snapd.service snapd.socket
@@ -53,40 +75,21 @@ jobs:
5375
run:
5476
shell: bash
5577
steps:
78+
- uses: actions/[email protected]
79+
with:
80+
fetch-depth: 1
5681
- name: Set GO env
5782
run: |
58-
# Enable extended globbing features to use advanced pattern matching
59-
shopt -s extglob
60-
6183
# Get latest containerd
6284
args=(curl --proto '=https' --tlsv1.2 -fsSL -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28")
6385
[ "${GITHUB_TOKEN:-}" == "" ] && {
6486
>&2 printf "GITHUB_TOKEN is not set - you might face rate limitations with the Github API\n"
6587
} || args+=(-H "Authorization: Bearer $GITHUB_TOKEN")
6688
ctd_v="$("${args[@]}" https://api.github.com/repos/containerd/containerd/tags | jq -rc .[0].name)"
67-
echo "CONTAINERD_VERSION=${ctd_v:1}" >> $GITHUB_ENV
68-
69-
# Get latest golang version and split it in components
70-
norm=()
71-
while read -r line; do
72-
line_trimmed="${line//+([[:space:]])/}"
73-
norm+=("$line_trimmed")
74-
done < \
75-
<(sed -E 's/^go([0-9]+)[.]([0-9]+)([.]([0-9]+))?(([a-z]+)([0-9]+))?/\1.\2\n\4\n\6\n\7/i' \
76-
<(curl -fsSL "https://go.dev/dl/?mode=json&include=all" | jq -rc .[0].version) \
77-
)
89+
echo "CONTAINERD_VERSION=${ctd_v:1}" >> "$GITHUB_ENV"
7890
79-
# Serialize version, making sure we have a patch version, and separate possible rcX into .rc-X
80-
[ "${norm[1]}" != "" ] || norm[1]="0"
81-
norm[1]=".${norm[1]}"
82-
[ "${norm[2]}" == "" ] || norm[2]="-${norm[2]}"
83-
[ "${norm[3]}" == "" ] || norm[3]=".${norm[3]}"
84-
# Save it
85-
IFS=
86-
echo "GO_VERSION=${norm[*]}" >> $GITHUB_ENV
87-
- uses: actions/[email protected]
88-
with:
89-
fetch-depth: 1
91+
. ./hack/build-integration-canary.sh
92+
canary::golang::latest
9093
- uses: actions/setup-go@v5
9194
with:
9295
go-version: ${{ env.GO_VERSION }}

Diff for: .github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ jobs:
222222
if echo "${ROOTLESSKIT_VERSION}" | grep -q v1; then
223223
WORKAROUND_ISSUE_622=1
224224
fi
225-
echo "WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622}" >>$GITHUB_ENV
225+
echo "WORKAROUND_ISSUE_622=${WORKAROUND_ISSUE_622}" >> "$GITHUB_ENV"
226226
- name: "Test (network driver=slirp4netns, port driver=builtin)"
227227
uses: nick-fields/retry@v3
228228
with:

Diff for: cmd/nerdctl/compose_exec_linux_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"errors"
2121
"fmt"
2222
"net"
23-
"runtime"
2423
"strings"
2524
"testing"
2625

@@ -98,7 +97,7 @@ services:
9897
if !strings.Contains(stdout, "\nBAR=bar1 bar2\n") {
9998
return errors.New("got bad BAR")
10099
}
101-
if !strings.Contains(stdout, "\nBAZ=\n") && runtime.GOOS != "windows" {
100+
if !strings.Contains(stdout, "\nBAZ=\n") {
102101
return errors.New("got bad BAZ")
103102
}
104103
if strings.Contains(stdout, "QUX") {
@@ -113,10 +112,10 @@ services:
113112
if !strings.Contains(stdout, "\nGRAULT=grault_key=grault_value\n") {
114113
return errors.New("got bad GRAULT")
115114
}
116-
if !strings.Contains(stdout, "\nGARPLY=\n") && runtime.GOOS != "windows" {
115+
if !strings.Contains(stdout, "\nGARPLY=\n") {
117116
return errors.New("got bad GARPLY")
118117
}
119-
if !strings.Contains(stdout, "\nWALDO=\n") && runtime.GOOS != "windows" {
118+
if !strings.Contains(stdout, "\nWALDO=\n") {
120119
return errors.New("got bad WALDO")
121120
}
122121

Diff for: cmd/nerdctl/container_create_linux_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package main
1818

1919
import (
2020
"fmt"
21-
"runtime"
2221
"strings"
2322
"testing"
2423

@@ -154,9 +153,6 @@ func TestCreateWithMACAddress(t *testing.T) {
154153
}
155154

156155
func TestCreateWithTty(t *testing.T) {
157-
if runtime.GOOS == "windows" {
158-
t.Skip("json-file log driver is not yet implemented on Windows")
159-
}
160156
base := testutil.NewBase(t)
161157
imageName := testutil.CommonImage
162158
withoutTtyContainerName := "without-terminal-" + testutil.Identifier(t)

Diff for: cmd/nerdctl/container_run_linux_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"net/http"
2727
"os"
2828
"path/filepath"
29-
"runtime"
3029
"strconv"
3130
"strings"
3231
"syscall"
@@ -400,9 +399,6 @@ func TestRunSigProxy(t *testing.T) {
400399
}
401400

402401
func TestRunWithFluentdLogDriver(t *testing.T) {
403-
if runtime.GOOS == "windows" {
404-
t.Skip("fluentd log driver is not yet implemented on Windows")
405-
}
406402
base := testutil.NewBase(t)
407403
tempDirectory := t.TempDir()
408404
err := os.Chmod(tempDirectory, 0777)
@@ -432,9 +428,6 @@ func TestRunWithFluentdLogDriver(t *testing.T) {
432428
}
433429

434430
func TestRunWithFluentdLogDriverWithLogOpt(t *testing.T) {
435-
if runtime.GOOS == "windows" {
436-
t.Skip("fluentd log driver is not yet implemented on Windows")
437-
}
438431
base := testutil.NewBase(t)
439432
tempDirectory := t.TempDir()
440433
err := os.Chmod(tempDirectory, 0777)

Diff for: cmd/nerdctl/image_convert_linux_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package main
1818

1919
import (
2020
"fmt"
21-
"runtime"
2221
"testing"
2322

2423
"gotest.tools/v3/icmd"
@@ -29,9 +28,6 @@ import (
2928
)
3029

3130
func TestImageConvertNydus(t *testing.T) {
32-
if runtime.GOOS == "windows" {
33-
t.Skip("no windows support yet")
34-
}
3531
testutil.RequireExecutable(t, "nydus-image")
3632
testutil.DockerIncompatible(t)
3733

Diff for: hack/build-integration-canary.sh

+107-80
Original file line numberDiff line numberDiff line change
@@ -215,91 +215,118 @@ assets::get(){
215215
# Script
216216
######################
217217

218-
docker_args=(docker build -t test-integration --target test-integration)
219-
220-
for dep in "${dependencies[@]}"; do
221-
shortname="${dep##*/}"
222-
[ "$shortname" != "plugins" ] || shortname="cni-plugins"
223-
[ "$shortname" != "fuse-overlayfs-snapshotter" ] || shortname="containerd-fuse-overlayfs"
224-
for bl in "${blacklist[@]}"; do
225-
if [ "$bl" == "$shortname" ]; then
226-
log::warning "Dependency $shortname is blacklisted and will be left to its currently pinned version"
227-
break
228-
fi
229-
done
230-
[ "$bl" != "$shortname" ] || continue
231-
232-
shortsafename="$(printf "%s" "$shortname" | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
233-
234-
exclusion="${shortsafename}_EXCLUDE"
235-
latest::release "$dep" "${!exclusion:-}"
236-
237-
# XXX containerd does not display "v" in its released versions
238-
[ "${higher_readable:0:1}" == v ] || higher_readable="v$higher_readable"
239-
240-
checksum="${shortsafename}_CHECKSUM"
241-
if [ "${!checksum:-}" != "" ]; then
242-
# Checksum file
243-
checksum_file=./Dockerfile.d/SHA256SUMS.d/"${shortname}-${higher_readable}"
244-
if [ ! -e "$checksum_file" ]; then
245-
# Get assets - try first os/arch - fallback on gnu style arch otherwise
246-
assets=()
247-
248-
# Most well behaved go projects will tag with a go os and arch
249-
candidate="$(assets::get "${!checksum:-}" "amd64")"
250-
# Then non go projects tend to use gnu style
251-
[ "$candidate" != "" ] || candidate="$(assets::get "" "x86_64")"
252-
# And then some projects which are linux only do not specify the OS
253-
[ "$candidate" != "" ] || candidate="$(assets::get "" "amd64")"
254-
[ "$candidate" == "" ] || assets+=("$candidate")
255-
256-
candidate="$(assets::get "${!checksum:-}" "arm64")"
257-
[ "$candidate" != "" ] || candidate="$(assets::get "" "aarch64")"
258-
[ "$candidate" != "" ] || candidate="$(assets::get "" "arm64")"
259-
[ "$candidate" == "" ] || assets+=("$candidate")
260-
# Fallback to source if there is nothing else
261-
262-
[ "${#assets[@]}" != 0 ] || candidate="$(assets::get "" "source")"
263-
[ "$candidate" == "" ] || assets+=("$candidate")
264-
265-
# XXX very special...
266-
if [ "$shortsafename" == "STARGZ_SNAPSHOTTER" ]; then
267-
assets+=("https://raw.githubusercontent.com/containerd/stargz-snapshotter/${higher_readable}/script/config/etc/systemd/system/stargz-snapshotter.service")
218+
canary::build::integration(){
219+
docker_args=(docker build -t test-integration --target test-integration)
220+
221+
for dep in "${dependencies[@]}"; do
222+
shortname="${dep##*/}"
223+
[ "$shortname" != "plugins" ] || shortname="cni-plugins"
224+
[ "$shortname" != "fuse-overlayfs-snapshotter" ] || shortname="containerd-fuse-overlayfs"
225+
for bl in "${blacklist[@]}"; do
226+
if [ "$bl" == "$shortname" ]; then
227+
log::warning "Dependency $shortname is blacklisted and will be left to its currently pinned version"
228+
break
268229
fi
269-
270-
# Write the checksum for what we found
271-
if [ "${#assets[@]}" == 0 ]; then
272-
log::error "No asset found for this checksum-able dependency. Dropping off."
273-
exit 1
230+
done
231+
[ "$bl" != "$shortname" ] || continue
232+
233+
shortsafename="$(printf "%s" "$shortname" | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
234+
235+
exclusion="${shortsafename}_EXCLUDE"
236+
latest::release "$dep" "${!exclusion:-}"
237+
238+
# XXX containerd does not display "v" in its released versions
239+
[ "${higher_readable:0:1}" == v ] || higher_readable="v$higher_readable"
240+
241+
checksum="${shortsafename}_CHECKSUM"
242+
if [ "${!checksum:-}" != "" ]; then
243+
# Checksum file
244+
checksum_file=./Dockerfile.d/SHA256SUMS.d/"${shortname}-${higher_readable}"
245+
if [ ! -e "$checksum_file" ]; then
246+
# Get assets - try first os/arch - fallback on gnu style arch otherwise
247+
assets=()
248+
249+
# Most well behaved go projects will tag with a go os and arch
250+
candidate="$(assets::get "${!checksum:-}" "amd64")"
251+
# Then non go projects tend to use gnu style
252+
[ "$candidate" != "" ] || candidate="$(assets::get "" "x86_64")"
253+
# And then some projects which are linux only do not specify the OS
254+
[ "$candidate" != "" ] || candidate="$(assets::get "" "amd64")"
255+
[ "$candidate" == "" ] || assets+=("$candidate")
256+
257+
candidate="$(assets::get "${!checksum:-}" "arm64")"
258+
[ "$candidate" != "" ] || candidate="$(assets::get "" "aarch64")"
259+
[ "$candidate" != "" ] || candidate="$(assets::get "" "arm64")"
260+
[ "$candidate" == "" ] || assets+=("$candidate")
261+
# Fallback to source if there is nothing else
262+
263+
[ "${#assets[@]}" != 0 ] || candidate="$(assets::get "" "source")"
264+
[ "$candidate" == "" ] || assets+=("$candidate")
265+
266+
# XXX very special...
267+
if [ "$shortsafename" == "STARGZ_SNAPSHOTTER" ]; then
268+
assets+=("https://raw.githubusercontent.com/containerd/stargz-snapshotter/${higher_readable}/script/config/etc/systemd/system/stargz-snapshotter.service")
269+
fi
270+
271+
# Write the checksum for what we found
272+
if [ "${#assets[@]}" == 0 ]; then
273+
log::error "No asset found for this checksum-able dependency. Dropping off."
274+
exit 1
275+
fi
276+
http::checksum "${assets[@]}" > "$checksum_file"
274277
fi
275-
http::checksum "${assets[@]}" > "$checksum_file"
276278
fi
277-
fi
278279

279-
while read -r line; do
280-
# Extract value after "=" from a possible dockerfile `ARG XXX_VERSION`
281-
old_version=$(echo "$line" | grep "ARG ${shortsafename}_VERSION=") || true
282-
old_version="${old_version##*=}"
283-
[ "$old_version" != "" ] || continue
284-
# If the Dockerfile version does NOT start with a v, adapt to that
285-
[ "${old_version:0:1}" == "v" ] || higher_readable="${higher_readable:1}"
286-
287-
if [ "$old_version" != "$higher_readable" ]; then
288-
log::warning "Dependency ${shortsafename} is going to use an updated version $higher_readable (currently: $old_version)"
289-
fi
290-
done < ./Dockerfile
280+
while read -r line; do
281+
# Extract value after "=" from a possible dockerfile `ARG XXX_VERSION`
282+
old_version=$(echo "$line" | grep "ARG ${shortsafename}_VERSION=") || true
283+
old_version="${old_version##*=}"
284+
[ "$old_version" != "" ] || continue
285+
# If the Dockerfile version does NOT start with a v, adapt to that
286+
[ "${old_version:0:1}" == "v" ] || higher_readable="${higher_readable:1}"
291287

292-
docker_args+=(--build-arg "${shortsafename}_VERSION=$higher_readable")
293-
done
288+
if [ "$old_version" != "$higher_readable" ]; then
289+
log::warning "Dependency ${shortsafename} is going to use an updated version $higher_readable (currently: $old_version)"
290+
fi
291+
done < ./Dockerfile
292+
293+
docker_args+=(--build-arg "${shortsafename}_VERSION=$higher_readable")
294+
done
294295

295296

296-
GO_VERSION="$(curl -fsSL "https://go.dev/dl/?mode=json&include=all" | jq -rc .[0].version)"
297-
GO_VERSION="${GO_VERSION##*go}"
298-
# If a release candidate, docker hub may not have the corresponding image yet.
299-
# So, soften the version to just "rc", as they provide that as an alias to the latest available rc on their side
300-
# See https://github.com/containerd/nerdctl/issues/3223
301-
! grep -Eq "rc[0-9]+$" <<<"$GO_VERSION" || GO_VERSION="${GO_VERSION%rc[0-9]*}-rc"
302-
docker_args+=(--build-arg "GO_VERSION=$GO_VERSION")
297+
GO_VERSION="$(curl -fsSL "https://go.dev/dl/?mode=json&include=all" | jq -rc .[0].version)"
298+
GO_VERSION="${GO_VERSION##*go}"
299+
# If a release candidate, docker hub may not have the corresponding image yet.
300+
# So, soften the version to just "rc", as they provide that as an alias to the latest available rc on their side
301+
# See https://github.com/containerd/nerdctl/issues/3223
302+
! grep -Eq "rc[0-9]+$" <<<"$GO_VERSION" || GO_VERSION="${GO_VERSION%rc[0-9]*}-rc"
303+
docker_args+=(--build-arg "GO_VERSION=$GO_VERSION")
304+
305+
log::debug "${docker_args[*]} ."
306+
"${docker_args[@]}" "."
307+
}
308+
303309

304-
log::debug "${docker_args[*]} ."
305-
"${docker_args[@]}" "."
310+
canary::golang::latest(){
311+
# Enable extended globbing features to use advanced pattern matching
312+
shopt -s extglob
313+
314+
# Get latest golang version and split it in components
315+
norm=()
316+
while read -r line; do
317+
line_trimmed="${line//+([[:space:]])/}"
318+
norm+=("$line_trimmed")
319+
done < \
320+
<(sed -E 's/^go([0-9]+)[.]([0-9]+)([.]([0-9]+))?(([a-z]+)([0-9]+))?/\1.\2\n\4\n\6\n\7/i' \
321+
<(curl -fsSL "https://go.dev/dl/?mode=json&include=all" | jq -rc .[0].version) \
322+
)
323+
324+
# Serialize version, making sure we have a patch version, and separate possible rcX into .rc-X
325+
[ "${norm[1]}" != "" ] || norm[1]="0"
326+
norm[1]=".${norm[1]}"
327+
[ "${norm[2]}" == "" ] || norm[2]="-${norm[2]}"
328+
[ "${norm[3]}" == "" ] || norm[3]=".${norm[3]}"
329+
# Save it
330+
IFS=
331+
echo "GO_VERSION=${norm[*]}" >> "$GITHUB_ENV"
332+
}

0 commit comments

Comments
 (0)