Skip to content

Commit 701007c

Browse files
committed
infra: refactor govulncheck target and hack script.
The govulncheck script now uses the same mechanism for the other tools in hack/tools/bin.
1 parent e371598 commit 701007c

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ lint-api-fix: $(GOLANGCI_LINT_KAL)
178178
lint-config: $(GOLANGCI_LINT) ## Verify golangci-lint linter configuration
179179
$(GOLANGCI_LINT) config verify
180180

181-
.PHONY: govulncheck
182-
govulncheck: $(GOVULNCHECK) ## Run govulncheck to detect known vulnerabilities.
183-
$(GOVULNCHECK) -scan package ./...
181+
.PHONY: verify-govulncheck
182+
verify-govulncheck: $(GOVULNCHECK) ## Run govulncheck verification against base branch.
183+
GOVULNCHECK="$(GOVULNCHECK)" ./hack/verify-govulncheck.sh
184184

185185
.PHONY: verify
186186
verify: ## Run all verification scripts.
@@ -449,6 +449,9 @@ $(GOLANGCI_LINT_BIN): $(GOLANGCI_LINT) ## Build a local copy of golangci-lint.
449449
.PHONY: $(KIND_BIN)
450450
$(KIND_BIN): $(KIND) ## Build a local copy of kind.
451451

452+
.PHONY: $(GOVULNCHECK_BIN)
453+
$(GOVULNCHECK_BIN): $(GOVULNCHECK) ## Build a local copy of govulncheck.
454+
452455
$(KUSTOMIZE): # Build kustomize from tools folder.
453456
CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)
454457

hack/verify-govulncheck.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ set -o errexit
1818
set -o nounset
1919
set -o pipefail
2020

21-
GOVULNCHECK_VERSION="${GOVULNCHECK_VERSION:-v1.1.4}"
21+
KUBE_ROOT="$(dirname "${BASH_SOURCE[0]}")/.."
22+
cd "${KUBE_ROOT}"
2223

23-
# Install govulncheck if not already present.
24-
if ! command -v govulncheck &>/dev/null; then
25-
echo "Installing govulncheck@${GOVULNCHECK_VERSION}..."
26-
go install "golang.org/x/vuln/cmd/govulncheck@${GOVULNCHECK_VERSION}"
24+
GOVULNCHECK="${GOVULNCHECK:-${KUBE_ROOT}/hack/tools/bin/govulncheck}"
25+
26+
# Ensure govulncheck binary is built
27+
if [[ ! -x "${GOVULNCHECK}" ]]; then
28+
make -C "${KUBE_ROOT}" govulncheck
2729
fi
2830

2931
# NRC_VERIFY_GIT_BRANCH is populated in verify CI jobs (e.g. GITHUB_BASE_REF
@@ -47,11 +49,11 @@ git worktree add -f -q "${WORKTREE}" "${BRANCH}"
4749
trap 'git worktree remove -f "${WORKTREE}"; rm -rf "${TMPDIR}"' EXIT
4850

4951
echo "Running govulncheck on HEAD (PR branch)..."
50-
govulncheck -scan package ./... > "${TMPDIR}/head.txt" || true
52+
"${GOVULNCHECK}" -scan package ./... > "${TMPDIR}/head.txt" || true
5153

5254
echo "Running govulncheck on base branch '${BRANCH}'..."
5355
pushd "${WORKTREE}" >/dev/null
54-
govulncheck -scan package ./... > "${TMPDIR}/pr-base.txt" || true
56+
"${GOVULNCHECK}" -scan package ./... > "${TMPDIR}/pr-base.txt" || true
5557
popd >/dev/null
5658

5759
echo -e "\n=== HEAD (PR branch) ===\n$(cat "${TMPDIR}/head.txt")"

0 commit comments

Comments
 (0)