Skip to content

Commit 3dee688

Browse files
lubronzhanchrischdi
authored andcommitted
Grouped CI related cherry-picks
- Add args to golangci-lint to show lines number kubernetes-sigs#2180 - Align github actions with upstream CAPI kubernetes-sigs#2167 - flavorgen generates all flavors by default kubernetes-sigs#2172 - only CI parts - Add verify-govulncheck target and integrate to scan action kubernetes-sigs#2174 - Use shellcheck binary instead of self-built docker image kubernetes-sigs#2211 - Add doctoc and generate + verify targets kubernetes-sigs#2147 - only CI parts
1 parent b9c175d commit 3dee688

File tree

121 files changed

+491
-14750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+491
-14750
lines changed

.github/dependabot.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@ updates:
1111
prefix: ":seedling:"
1212
labels:
1313
- "ok-to-test"
14+
1415
# Go
1516
- package-ecosystem: "gomod"
1617
directory: "/"
1718
schedule:
1819
interval: "weekly"
20+
day: "monday"
1921
ignore:
20-
# Ignore k8s modules as they are upgraded manually
21-
# together with controller-runtime and CAPI dependencies.
22+
# Ignore controller-runtime as its upgraded manually.
23+
- dependency-name: "sigs.k8s.io/controller-runtime"
24+
update-types: [ "version-update:semver-major", "version-update:semver-minor" ]
25+
# Ignore k8s and its transitives modules as they are upgraded manually
26+
# together with controller-runtime.
2227
- dependency-name: "k8s.io/*"
23-
- dependency-name: "sigs.k8s.io/*"
28+
update-types: [ "version-update:semver-major", "version-update:semver-minor" ]
2429
- dependency-name: "sigs.k8s.io/cluster-api/test"
2530
update-types: ["version-update:semver-major", "version-update:semver-minor"]
2631
commit-message:
2732
prefix: ":seedling:"
2833
labels:
29-
- "ok-to-test"
34+
- "ok-to-test"

.github/workflows/golangci-lint.yaml renamed to .github/workflows/pr-golangci-lint.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: golangci-lint
1+
name: PR golangci-lint
22

33
on:
44
pull_request:
@@ -17,10 +17,11 @@ jobs:
1717
id: vars
1818
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
1919
- name: Set up Go
20-
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # tag=v4.0.1
20+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # tag=v4.1.0
2121
with:
2222
go-version: ${{ steps.vars.outputs.go_version }}
2323
- name: golangci-lint
2424
uses: golangci/golangci-lint-action@639cd343e1d3b897ff35927a75193d57cfcba299 # tag=v3.6.0
2525
with:
26-
version: v1.53.3
26+
version: v1.53.3
27+
args: --out-format=colored-line-number
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: PR check Markdown links
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened]
6+
paths:
7+
- '**.md'
8+
9+
# Remove all permissions from GITHUB_TOKEN except metadata.
10+
permissions: {}
11+
12+
jobs:
13+
markdown-link-check:
14+
name: Broken Links
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # tag=v3.5.3
18+
- uses: gaurav-nelson/github-action-markdown-link-check@5c5dfc0ac2e225883c0e5f03a85311ec2830d368 # tag=v1
19+
with:
20+
use-quiet-mode: 'yes'
21+
config-file: .markdownlinkcheck.json
22+
check-modified-files-only: 'yes'
23+
base-branch: main

.github/workflows/verify-pr.yml renamed to .github/workflows/pr-verify.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Verify PR
1+
name: PR Verify
22

33
on:
44
pull_request_target:
@@ -14,6 +14,6 @@ jobs:
1414
steps:
1515
- name: Verifier action
1616
id: verifier
17-
uses: kubernetes-sigs/[email protected]
17+
uses: kubernetes-sigs/kubebuilder-release-tools@4f3d1085b4458a49ed86918b4b55505716715b77 # tag=v0.3.0
1818
with:
1919
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Calculate go version
2424
run: echo "go_version=$(make go-version)" >> $GITHUB_ENV
2525
- name: Set up Go
26-
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # tag=v4.0.1
26+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # tag=v4.1.0
2727
with:
2828
go-version: ${{ env.go_version }}
2929
- name: generate release artifacts

.github/workflows/scan.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Weekly check all Markdown links
2+
3+
on:
4+
schedule:
5+
# Cron for every Monday at 12:00 UTC.
6+
- cron: "0 12 * * 1"
7+
8+
# Remove all permissions from GITHUB_TOKEN except metadata.
9+
permissions: {}
10+
11+
jobs:
12+
markdown-link-check:
13+
name: Broken Links
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
branch: [ main, release-1.8, release-1.7, release-1.6, release-1.5 ]
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # tag=v3.5.3
21+
with:
22+
ref: ${{ matrix.branch }}
23+
- uses: gaurav-nelson/github-action-markdown-link-check@5c5dfc0ac2e225883c0e5f03a85311ec2830d368 # tag=v1
24+
with:
25+
use-quiet-mode: 'yes'
26+
config-file: .markdownlinkcheck.json
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Weekly security scan
2+
3+
on:
4+
schedule:
5+
# Cron for every Monday at 12:00 UTC.
6+
- cron: "0 12 * * 1"
7+
8+
# Remove all permissions from GITHUB_TOKEN except metadata.
9+
permissions: {}
10+
11+
jobs:
12+
scan:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
branch: [ main, release-1.8, release-1.7, release-1.6, release-1.5 ]
17+
name: Trivy
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Check out code
21+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # tag=v3.5.3
22+
with:
23+
ref: ${{ matrix.branch }}
24+
- name: Calculate go version
25+
id: vars
26+
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
27+
- name: Set up Go
28+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # tag=v4.1.0
29+
with:
30+
go-version: ${{ steps.vars.outputs.go_version }}
31+
- name: Run verify security target
32+
run: make verify-security
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Weekly release test
2+
3+
# Note: This workflow does not build for releases. It attempts to build release binaries periodically to ensure the repo
4+
# release machinery is in a good state.
5+
6+
on:
7+
schedule:
8+
# Cron for every day at 12:00 UTC.
9+
- cron: "0 12 * * *"
10+
11+
# Remove all permissions from GITHUB_TOKEN except metadata.
12+
permissions: {}
13+
14+
jobs:
15+
weekly-test-release:
16+
name: Test release
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
branch: [ main, release-1.8, release-1.7, release-1.6, release-1.5 ]
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # tag=v3.5.3
24+
with:
25+
ref: ${{ matrix.branch }}
26+
fetch-depth: 0
27+
- name: Set env
28+
run: echo "RELEASE_TAG=v9.9.9-fake" >> $GITHUB_ENV
29+
- name: Set fake tag for release
30+
run: |
31+
git tag ${{ env.RELEASE_TAG }}
32+
- name: Calculate go version
33+
run: echo "go_version=$(make go-version)" >> $GITHUB_ENV
34+
- name: Set up Go
35+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # tag=v4.1.0
36+
with:
37+
go-version: ${{ env.go_version }}
38+
- name: Test release
39+
run: |
40+
make release

.markdownlinkcheck.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"ignorePatterns": [{
3+
"pattern": "^http://localhost"
4+
}],
5+
"httpHeaders": [{
6+
"comment": "Workaround as suggested here: https://github.com/tcort/markdown-link-check/issues/201",
7+
"urls": ["https://docs.github.com/"],
8+
"headers": {
9+
"Accept-Encoding": "zstd, br, gzip, deflate"
10+
}
11+
}],
12+
"timeout": "10s",
13+
"retryOn429": true,
14+
"retryCount": 5,
15+
"fallbackRetryDelay": "30s",
16+
"aliveStatusCodes": [200, 206]
17+
}

Makefile

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ GO_APIDIFF_BIN := go-apidiff
134134
GO_APIDIFF := $(abspath $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)-$(GO_APIDIFF_VER))
135135
GO_APIDIFF_PKG := github.com/joelanford/go-apidiff
136136

137+
SHELLCHECK_VER := v0.9.0
138+
137139
KPROMO_VER := v4.0.4
138140
KPROMO_BIN := kpromo
139141
KPROMO := $(abspath $(TOOLS_BIN_DIR)/$(KPROMO_BIN)-$(KPROMO_VER))
@@ -150,10 +152,15 @@ GINKGO := $(abspath $(TOOLS_BIN_DIR)/$(GINKGO_BIN)-$(GINGKO_VER))
150152
GINKGO_PKG := github.com/onsi/ginkgo/v2/ginkgo
151153

152154
GOLANGCI_LINT_BIN := golangci-lint
153-
GOLANGCI_LINT_VER := $(shell cat .github/workflows/golangci-lint.yaml | grep [[:space:]]version: | sed 's/.*version: //')
155+
GOLANGCI_LINT_VER := $(shell cat .github/workflows/pr-golangci-lint.yaml | grep [[:space:]]version: | sed 's/.*version: //')
154156
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
155157
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
156158

159+
GOVULNCHECK_BIN := govulncheck
160+
GOVULNCHECK_VER := v1.0.0
161+
GOVULNCHECK := $(abspath $(TOOLS_BIN_DIR)/$(GOVULNCHECK_BIN)-$(GOVULNCHECK_VER))
162+
GOVULNCHECK_PKG := golang.org/x/vuln/cmd/govulncheck
163+
157164
GOVC_VER := $(shell cat go.mod | grep "github.com/vmware/govmomi" | awk '{print $$NF}')
158165
GOVC_BIN := govc
159166
GOVC := $(abspath $(TOOLS_BIN_DIR)/$(GOVC_BIN)-$(GOVC_VER))
@@ -228,7 +235,7 @@ help: # Display this help
228235

229236
.PHONY: generate
230237
generate: ## Run all generate targets
231-
$(MAKE) generate-modules generate-manifests generate-go-deepcopy generate-go-conversions
238+
$(MAKE) generate-modules generate-manifests generate-go-deepcopy generate-go-conversions generate-flavors
232239

233240
.PHONY: generate-manifests
234241
generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
@@ -276,6 +283,10 @@ generate-go-conversions: $(CONTROLLER_GEN) $(CONVERSION_GEN) ## Runs Go related
276283
generate-modules: ## Run go mod tidy to ensure modules are up to date
277284
go mod tidy
278285

286+
.PHONY: generate-doctoc
287+
generate-doctoc:
288+
TRACE=$(TRACE) ./hack/generate-doctoc.sh
289+
279290
.PHONY: generate-e2e-templates
280291
generate-e2e-templates: ## Generate e2e cluster templates
281292
$(MAKE) release-flavors
@@ -311,7 +322,6 @@ generate-e2e-templates: ## Generate e2e cluster templates
311322
lint: $(GOLANGCI_LINT) ## Lint the codebase
312323
$(MAKE) lint-go-full
313324
$(MAKE) lint-markdown
314-
$(MAKE) lint-shell
315325

316326
GOLANGCI_LINT_EXTRA_ARGS ?= --fast=true
317327
.PHONY: lint-go
@@ -326,10 +336,6 @@ lint-go-full: lint-go ## Run slower linters to detect possible issues
326336
lint-markdown: ## Lint the project's markdown
327337
docker run --rm -v "$$(pwd)":/build$(DOCKER_VOL_OPTS) gcr.io/cluster-api-provider-vsphere/extra/mdlint:0.17.0 -- /md/lint -i contrib/haproxy/openapi -i _releasenotes .
328338

329-
.PHONY: lint-shell
330-
lint-shell: ## Lint the project's shell scripts
331-
docker run --rm -t -v "$$(pwd)":/build:ro gcr.io/cluster-api-provider-vsphere/extra/shellcheck
332-
333339
.PHONY: lint-fix
334340
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter
335341
GOLANGCI_LINT_EXTRA_ARGS="--fast=false --fix" $(MAKE) lint-go
@@ -340,10 +346,10 @@ APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
340346
apidiff: $(GO_APIDIFF) ## Check for API differences
341347
$(GO_APIDIFF) $(APIDIFF_OLD_COMMIT) --print-compatible
342348

343-
ALL_VERIFY_CHECKS = boilerplate modules gen conversions
349+
ALL_VERIFY_CHECKS = boilerplate shellcheck modules gen conversions doctoc flavors
344350

345351
.PHONY: verify
346-
verify: $(addprefix verify-,$(ALL_VERIFY_CHECKS)) lint-markdown lint-shell ## Run all verify-* targets
352+
verify: $(addprefix verify-,$(ALL_VERIFY_CHECKS)) lint-markdown ## Run all verify-* targets
347353

348354
.PHONY: verify-modules
349355
verify-modules: generate-modules ## Verify go modules are up to date
@@ -367,14 +373,46 @@ verify-gen: generate ## Verify go generated files are up to date
367373
verify-conversions: $(CONVERSION_VERIFIER) ## Verifies expected API conversion are in place
368374
$(CONVERSION_VERIFIER)
369375

376+
.PHONY: verify-doctoc
377+
verify-doctoc: generate-doctoc
378+
@if !(git diff --quiet HEAD); then \
379+
git diff; \
380+
echo "doctoc is out of date, run make generate-doctoc"; exit 1; \
381+
fi
382+
370383
.PHONY: verify-boilerplate
371384
verify-boilerplate: ## Verify boilerplate text exists in each file
372385
TRACE=$(TRACE) ./hack/verify-boilerplate.sh
373386

387+
.PHONY: verify-shellcheck
388+
verify-shellcheck: ## Verify shell files
389+
TRACE=$(TRACE) ./hack/verify-shellcheck.sh $(SHELLCHECK_VER)
390+
374391
.PHONY: verify-container-images
375392
verify-container-images: ## Verify container images
376393
TRACE=$(TRACE) ./hack/verify-container-images.sh
377394

395+
.PHONY: verify-govulncheck
396+
verify-govulncheck: $(GOVULNCHECK) ## Verify code for vulnerabilities
397+
$(GOVULNCHECK) ./...
398+
399+
.PHONY: verify-security
400+
verify-security: ## Verify code and images for vulnerabilities
401+
$(MAKE) verify-container-images && R1=$$? || R1=$$?; \
402+
$(MAKE) verify-govulncheck && R2=$$? || R2=$$?; \
403+
if [ "$$R1" -ne "0" ] || [ "$$R2" -ne "0" ]; then \
404+
echo "Check for vulnerabilities failed! There are vulnerabilities to be fixed"; \
405+
exit 1; \
406+
fi
407+
408+
.PHONY: verify-flavors
409+
verify-flavors: $(FLAVOR_DIR) generate-flavors ## Verify generated flavors
410+
@if !(git diff --quiet HEAD -- $(FLAVOR_DIR)); then \
411+
git diff $(FLAVOR_DIR); \
412+
echo "flavor files in templates directory are out of date"; exit 1; \
413+
fi
414+
415+
378416
## --------------------------------------
379417
## Build
380418
## --------------------------------------
@@ -721,6 +759,9 @@ $(GINKGO_BIN): $(GINKGO) ## Build a local copy of ginkgo.
721759
.PHONY: $(GOLANGCI_LINT_BIN)
722760
$(GOLANGCI_LINT_BIN): $(GOLANGCI_LINT) ## Build a local copy of golangci-lint.
723761

762+
.PHONY: $(GOVULNCHECK_BIN)
763+
$(GOVULNCHECK_BIN): $(GOVULNCHECK) ## Build a local copy of govulncheck.
764+
724765
.PHONY: $(GOVC_BIN)
725766
$(GOVC_BIN): $(GOVC) ## Build a local copy of govc.
726767

@@ -770,6 +811,9 @@ $(GINKGO): # Build ginkgo.
770811
$(GOLANGCI_LINT): # Build golangci-lint.
771812
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOLANGCI_LINT_PKG) $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
772813

814+
$(GOVULNCHECK): # Build govulncheck.
815+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOVULNCHECK_PKG) $(GOVULNCHECK_BIN) $(GOVULNCHECK_VER)
816+
773817
$(GOVC): # Build GOVC.
774818
CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOVC_PKG) $(GOVC_BIN) $(GOVC_VER)
775819

0 commit comments

Comments
 (0)