Skip to content

Commit bcdba76

Browse files
authored
govulncheck: update Go before running the vuln checks (#161)
The `entrypoint.sh` runs the `go mod verify` command which will download the version of Go matching the `toolchain` in `go.mod`. This requires the `GOTOOLCHAIN` env var to be set to `auto` This change sure that the vuln check is executed with the same version of Go as the one used to build the binary :) see https://go.dev/doc/toolchain also, upgrade the code and the builder image to Go 1.24 also, upgrade other GitHub actions to their latest versions also, rename the binary to `govulncheckx` to avoid mixing with the standard `govulncheck` tool --------- Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
1 parent bc2c77b commit bcdba76

5 files changed

Lines changed: 25 additions & 10 deletions

File tree

.github/workflows/govulncheck-action-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-24.04
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v5
16+
uses: actions/checkout@v6
1717

1818
- name: Set short SHA
1919
id: short-sha

.github/workflows/govulncheck-action-test-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
uses: actions/checkout@v4
1717

1818
- name: Install Go
19-
uses: actions/setup-go@v5
19+
uses: actions/setup-go@v6
2020
with:
2121
go-version-file: govulncheck-action/go.mod
2222

govulncheck-action/Containerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23 as builder
1+
FROM golang:1.24 as builder
22

33
ARG GOOS=linux
44
ARG GOARCH=amd64
@@ -7,14 +7,17 @@ WORKDIR /usr/src/app/
77

88
COPY . .
99

10-
RUN echo "Building for govulncheck $GOOS/$GOARCH"
11-
RUN GOOS=$GOOS GOARCH=$GOARCH go build -v -o govulncheck main.go
10+
RUN echo "Building govulncheckx binary for $GOOS/$GOARCH"
11+
RUN GOOS=$GOOS GOARCH=$GOARCH go build -v -o govulncheckx main.go
1212

13-
FROM golang:1.23
13+
FROM golang:1.24
1414
# using a fresh golang image without the `WORKDIR` from the builder stage
1515
# see https://docs.github.com/en/actions/reference/workflows-and-actions/dockerfile-support#workdir
16+
# using golang 1.24 but the entrypoint will trigger an install of the actual go version,
17+
# even if it is 1.23
1618

1719
# copy the binary from the builder stage
18-
COPY --from=builder /usr/src/app/govulncheck /usr/local/bin/govulncheck
20+
COPY --from=builder /usr/src/app/govulncheckx /usr/local/bin/govulncheckx
21+
COPY --from=builder /usr/src/app/entrypoint.sh /usr/local/bin/entrypoint.sh
1922

20-
ENTRYPOINT ["/usr/local/bin/govulncheck"]
23+
ENTRYPOINT ["entrypoint.sh"]

govulncheck-action/entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
# upgrade the go version to match the `toolchain` directive in the `go.mod` file
4+
# see https://go.dev/doc/toolchain
5+
export GOTOOLCHAIN=auto
6+
go mod verify
7+
8+
# Check the version of Go
9+
go version
10+
11+
# Run the govulncheck command
12+
govulncheckx "$@"

govulncheck-action/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/codeready-toolchain/toolchain-cicd/govulncheck-action
22

3-
go 1.23.0
3+
go 1.24.0
44

5-
toolchain go1.23.12
5+
toolchain go1.24.11
66

77
require (
88
github.com/spf13/cobra v1.9.1

0 commit comments

Comments
 (0)