From 760f2cd97cf30a77ac2dd5e4af959815ef27fd02 Mon Sep 17 00:00:00 2001 From: Marco Iorio Date: Tue, 25 Jun 2024 18:25:01 +0200 Subject: [PATCH 1/7] golangci-lint: fix deprecation warnings Addressed the following two deprecation warnings reported by golangci-lint: WARN [config_reader] The configuration option `linters.staticcheck.go` is deprecated, please use global `run.go`. WARN [lintersdb] The name "goerr113" is deprecated. The linter has been renamed to: err113. Signed-off-by: Marco Iorio --- cmapisrv-mock/.golangci.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cmapisrv-mock/.golangci.yaml b/cmapisrv-mock/.golangci.yaml index 3316cbd9..564a800d 100644 --- a/cmapisrv-mock/.golangci.yaml +++ b/cmapisrv-mock/.golangci.yaml @@ -49,10 +49,6 @@ linters-settings: - nilness goimports: local-prefixes: github.com/cilium - staticcheck: - go: "1.20" - unused: - go: "1.20" goheader: values: regexp: @@ -92,7 +88,7 @@ issues: text: "SA9003: empty branch" - linters: [staticcheck] text: "SA2001: empty critical section" - - linters: [goerr113] + - linters: [err113] text: "do not define dynamic errors, use wrapped static errors instead" # This rule to avoid opinionated check fmt.Errorf("text") # Skip goimports check on generated files - path: \\.(generated\\.deepcopy|pb)\\.go$ @@ -106,7 +102,7 @@ issues: linters: disable-all: true enable: - - goerr113 + - err113 - gofmt - goimports - govet From dbe27d0d6f68a79025bb398c67204ab755a70882 Mon Sep 17 00:00:00 2001 From: Marco Iorio Date: Wed, 26 Jun 2024 11:59:16 +0200 Subject: [PATCH 2/7] cmapisrv-mock: fix line-ending of vendored files Apparently, these two vendored files do originally use CRLF line ending, but got committed using the LF line ending. This causes the new lint workflow to fail due to the difference introduced when running go mod vendor. Let's fix this by committing them with the CRLF line ending. Signed-off-by: Marco Iorio --- .../github.com/hashicorp/hcl/.gitignore | 18 +++++----- .../vendor/github.com/hashicorp/hcl/Makefile | 36 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/cmapisrv-mock/vendor/github.com/hashicorp/hcl/.gitignore b/cmapisrv-mock/vendor/github.com/hashicorp/hcl/.gitignore index 822fa09f..15586a2b 100644 --- a/cmapisrv-mock/vendor/github.com/hashicorp/hcl/.gitignore +++ b/cmapisrv-mock/vendor/github.com/hashicorp/hcl/.gitignore @@ -1,9 +1,9 @@ -y.output - -# ignore intellij files -.idea -*.iml -*.ipr -*.iws - -*.test +y.output + +# ignore intellij files +.idea +*.iml +*.ipr +*.iws + +*.test diff --git a/cmapisrv-mock/vendor/github.com/hashicorp/hcl/Makefile b/cmapisrv-mock/vendor/github.com/hashicorp/hcl/Makefile index 9fafd501..84fd743f 100644 --- a/cmapisrv-mock/vendor/github.com/hashicorp/hcl/Makefile +++ b/cmapisrv-mock/vendor/github.com/hashicorp/hcl/Makefile @@ -1,18 +1,18 @@ -TEST?=./... - -default: test - -fmt: generate - go fmt ./... - -test: generate - go get -t ./... - go test $(TEST) $(TESTARGS) - -generate: - go generate ./... - -updatedeps: - go get -u golang.org/x/tools/cmd/stringer - -.PHONY: default generate test updatedeps +TEST?=./... + +default: test + +fmt: generate + go fmt ./... + +test: generate + go get -t ./... + go test $(TEST) $(TESTARGS) + +generate: + go generate ./... + +updatedeps: + go get -u golang.org/x/tools/cmd/stringer + +.PHONY: default generate test updatedeps From 32ea0bf4c1cd6ae06a5d199aebfb7edf3974754d Mon Sep 17 00:00:00 2001 From: Marco Iorio Date: Wed, 26 Jun 2024 12:04:03 +0200 Subject: [PATCH 3/7] cmapisrv-mock: fix Dockerfile keyword casing mismatch warning Signed-off-by: Marco Iorio --- cmapisrv-mock/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmapisrv-mock/Dockerfile b/cmapisrv-mock/Dockerfile index 8c1be31a..c11ac3a5 100644 --- a/cmapisrv-mock/Dockerfile +++ b/cmapisrv-mock/Dockerfile @@ -2,13 +2,13 @@ ARG BASE_IMAGE=docker.io/library/alpine:3.19.1@sha256:c5b1261d6d3e43071626931fc0 ARG GOLANG_IMAGE=docker.io/library/golang:1.22.1@sha256:0b55ab82ac2a54a6f8f85ec8b943b9e470c39e32c109b766bbc1b801f3fa8d3b ARG ETCD_SERVER_IMAGE=gcr.io/etcd-development/etcd:v3.5.12@sha256:cebe24b890641de3e7ff8a640c4597bdda321090c29f4dedcedaa8cadbbe08e1 -FROM ${GOLANG_IMAGE} as builder +FROM ${GOLANG_IMAGE} AS builder ADD . /go/src/github.com/cilium/scaffolding/cmapisrv-mock WORKDIR /go/src/github.com/cilium/scaffolding/cmapisrv-mock RUN make cmapisrv-mock RUN strip cmapisrv-mock -FROM ${ETCD_SERVER_IMAGE} as etcd +FROM ${ETCD_SERVER_IMAGE} AS etcd FROM ${BASE_IMAGE} From fad172b1b5862b1961c2e00c337d2b81b74d0cf5 Mon Sep 17 00:00:00 2001 From: Marco Iorio Date: Wed, 26 Jun 2024 14:45:43 +0200 Subject: [PATCH 4/7] cmapisrv-mock: add makefile targets to the phony list As they need to be executed independently of whether a file with the same name already exists or not. Signed-off-by: Marco Iorio --- cmapisrv-mock/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmapisrv-mock/Makefile b/cmapisrv-mock/Makefile index 8bb2d492..c7241ce6 100644 --- a/cmapisrv-mock/Makefile +++ b/cmapisrv-mock/Makefile @@ -1,5 +1,7 @@ DOCKER_IMAGE ?= quay.io/cilium/cmapisrv-mock:latest +.PHONY: all docker-image docker-image-load docker-image-push tests cmapisrv-mock local clean + all: local docker-image: From eb9a01c8ff6f632fab346a213e562e9cce770230 Mon Sep 17 00:00:00 2001 From: Marco Iorio Date: Wed, 26 Jun 2024 12:05:36 +0200 Subject: [PATCH 5/7] cmapisrv-mock: don't run tests before building the binary Currently, the cmapisrv-mock does not include unit tests, hence this is effectively a no-op. Yet, if added, they should be run in a separate workflow, to not impact the image build task. Signed-off-by: Marco Iorio --- cmapisrv-mock/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmapisrv-mock/Makefile b/cmapisrv-mock/Makefile index c7241ce6..4dd1ed67 100644 --- a/cmapisrv-mock/Makefile +++ b/cmapisrv-mock/Makefile @@ -17,7 +17,7 @@ docker-image-push: docker-image tests: go test -mod=vendor ./... -cmapisrv-mock: tests +cmapisrv-mock: CGO_ENABLED=0 go build -mod=vendor -o $@ *.go local: cmapisrv-mock From 7c5f41a5ea9cf0be5f718cd53dce2b0f903652a1 Mon Sep 17 00:00:00 2001 From: Marco Iorio Date: Tue, 25 Jun 2024 18:38:08 +0200 Subject: [PATCH 6/7] gha: add build workflow for cmapisrv-mock Signed-off-by: Marco Iorio --- .github/workflows/build.yaml | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..dd315568 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,46 @@ +name: Image build + +on: + pull_request: {} + push: + branches: + - main + +jobs: + build-and-push: + name: Build and Push + runs-on: ubuntu-latest + + strategy: + matrix: + include: + - name: cmapisrv-mock + context: cmapisrv-mock + dockerfile: ./cmapisrv-mock/Dockerfile + + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0 + + - name: Login to quay.io + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 + if: ${{ github.event_name == 'push' }} + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME_SCAFFOLDING }} + password: ${{ secrets.QUAY_PASSWORD_SCAFFOLDING }} + + - name: Checkout Source Code + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + persist-credentials: false + + - name: Build and Push + uses: docker/build-push-action@c382f710d39a5bb4e430307530a720f50c2d3318 # v6.0.0 + with: + context: ${{ matrix.context }} + file: ${{ matrix.dockerfile }} + push: ${{ github.event_name == 'push' }} + platforms: linux/amd64,linux/arm64 + tags: | + quay.io/${{ github.repository_owner }}/${{ matrix.name }}:${{ github.event.pull_request.head.sha || github.sha }} From a0f6a86f14fc30bf3e57e7863196d652f86e7297 Mon Sep 17 00:00:00 2001 From: Marco Iorio Date: Tue, 25 Jun 2024 18:18:48 +0200 Subject: [PATCH 7/7] gha: add linting workflow for cmapisrv-mock Signed-off-by: Marco Iorio --- .github/workflows/lint.yaml | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/lint.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 00000000..99db28e9 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,42 @@ +name: Lint Go files + +on: + pull_request: {} + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + + strategy: + matrix: + include: + - workdir: cmapisrv-mock + + steps: + - name: Install Go + uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 + with: + # renovate: datasource=golang-version depName=go + go-version: 1.22.4 + + - name: Checkout code + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + persist-credentials: false + + - name: Check module vendoring + working-directory: ${{ matrix.workdir }} + run: | + go mod tidy + go mod vendor + test -z "$(git status --porcelain)" || (echo "please run 'go mod tidy && go mod vendor', and submit your changes"; exit 1) + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1 + with: + # renovate: datasource=docker depName=golangci/golangci-lint + version: v1.59.1 + skip-cache: true + working-directory: ${{ matrix.workdir }} + args: "--out-format colored-line-number --verbose --modules-download-mode=vendor"