From 9877b7de4626d747ff1b085cd250ded82ef8d0c7 Mon Sep 17 00:00:00 2001 From: Michael Nairn Date: Wed, 15 May 2024 12:11:25 +0100 Subject: [PATCH] Add verify generate and go.mod make targets Add new make targets to verify that `make generate` and `go mod tidy` have been executed against the current code and the results committed. Add verify-generate and verify-go-mod jobs to CI github workflow. --- .github/workflows/ci.yaml | 32 ++++++++++++++++++++++++++++++++ make/verify.mk | 11 ++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6834531d..f6d8d3e1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -98,6 +98,38 @@ jobs: - name: Run make verify-imports run: | make verify-imports + verify-generate: + name: Verify generate + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.21.x + uses: actions/setup-go@v5 + with: + go-version: 1.21.x + cache: false + id: go + - name: Check out code + uses: actions/checkout@v4 + - name: Verify generate command + run: | + make verify-generate + + verify-go-mod: + name: Verify go.mod + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.21.x + uses: actions/setup-go@v5 + with: + go-version: 1.21.x + cache: false + id: go + - name: Check out code + uses: actions/checkout@v4 + - name: Verify generate command + run: | + make verify-go-mod + unit_test_suite: name: Unit Test Suite runs-on: ubuntu-latest diff --git a/make/verify.mk b/make/verify.mk index 6c8971d3..8bd633b1 100644 --- a/make/verify.mk +++ b/make/verify.mk @@ -4,7 +4,7 @@ ## Targets to verify actions that generate/modify code have been executed and output committed .PHONY: verify-all -verify-all: verify-code verify-bundle verify-imports verify-manifests +verify-all: verify-code verify-bundle verify-imports verify-manifests verify-generate verify-go-mod .PHONY: verify-code verify-code: vet ## Verify code formatting @@ -23,3 +23,12 @@ verify-bundle: bundle ## Verify bundle update. .PHONY: verify-imports verify-imports: ## Verify go imports are sorted and grouped correctly. hack/verify-imports.sh + +.PHONY: verify-generate +verify-generate: generate ## Verify generate update. + git diff --exit-code ./api ./internal/controller + +.PHONY: verify-go-mod +verify-go-mod: ## Verify go.mod matches source code + go mod tidy + git diff --exit-code ./go.mod