From d126f44e6b187575e42bfff73240d9f84df823f7 Mon Sep 17 00:00:00 2001 From: Cameron Meissner Date: Fri, 18 Oct 2024 08:08:20 -0700 Subject: [PATCH 01/10] refactor: add shellspec workflow, remove shellspec from generate target --- .github/workflows/shellspec.yaml | 14 ++++++++++++++ Makefile | 4 +--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/shellspec.yaml diff --git a/.github/workflows/shellspec.yaml b/.github/workflows/shellspec.yaml new file mode 100644 index 00000000000..dff05644fd3 --- /dev/null +++ b/.github/workflows/shellspec.yaml @@ -0,0 +1,14 @@ +name: shellspec +on: pull_request + +jobs: + shellspec: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v3 + with: + go-version: '1.22' + - run: | + make shellspec + name: Run bash unit tests with shellspec diff --git a/Makefile b/Makefile index f83f0281a85..aeda54a74a1 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,7 @@ validate-shell: @./.pipelines/scripts/verify_shell.sh .PHONY: shellspec -shellspec: +shellspec: bootstrap @bash ./hack/tools/bin/shellspec .PHONY: validate-image-version @@ -101,8 +101,6 @@ generate: bootstrap GENERATE_TEST_DATA="true" go test ./pkg/agent... @echo "running validate-shell to make sure generated cse scripts are correct" @$(MAKE) validate-shell - @echo "Running shellspec tests to validate shell/bash scripts" - @$(MAKE) shellspec @echo "Validating if components.json conforms to the schema schemas/components.cue." @echo "Error will be shown if any." @$(MAKE) validate-components From ce59f9f6fca97f9d2070a8ddd37762d7d33f13d7 Mon Sep 17 00:00:00 2001 From: Cameron Meissner Date: Fri, 18 Oct 2024 08:09:51 -0700 Subject: [PATCH 02/10] chore: log --- .github/workflows/shellspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/shellspec.yaml b/.github/workflows/shellspec.yaml index dff05644fd3..cb681e18e99 100644 --- a/.github/workflows/shellspec.yaml +++ b/.github/workflows/shellspec.yaml @@ -10,5 +10,6 @@ jobs: with: go-version: '1.22' - run: | + echo "Running shellspec tests to validate shell/bash scripts" make shellspec name: Run bash unit tests with shellspec From f77d07306a4a8917e9a72a22b575ca23a8a5385e Mon Sep 17 00:00:00 2001 From: Cameron Meissner Date: Fri, 18 Oct 2024 08:12:18 -0700 Subject: [PATCH 03/10] chore: cleanup --- .github/workflows/shellspec.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/shellspec.yaml b/.github/workflows/shellspec.yaml index cb681e18e99..d128c2edc2e 100644 --- a/.github/workflows/shellspec.yaml +++ b/.github/workflows/shellspec.yaml @@ -1,4 +1,4 @@ -name: shellspec +name: Shell/Bash Script Unit Tests on: pull_request jobs: @@ -10,6 +10,5 @@ jobs: with: go-version: '1.22' - run: | - echo "Running shellspec tests to validate shell/bash scripts" make shellspec - name: Run bash unit tests with shellspec + name: Run shell/bash script unit tests with shellspec From de3d157d922a4d52ad5a9effd8538d1b6c04498f Mon Sep 17 00:00:00 2001 From: Cameron Meissner Date: Fri, 18 Oct 2024 08:13:49 -0700 Subject: [PATCH 04/10] chore: comments --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index aeda54a74a1..4f5fd07f346 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ validate-go: validate-shell: @./.pipelines/scripts/verify_shell.sh -.PHONY: shellspec +.PHONY: shellspec # TODO: have this run in a container with a stable bash installation shellspec: bootstrap @bash ./hack/tools/bin/shellspec From 52086b3c258803a8126a692f816ce75a496775f6 Mon Sep 17 00:00:00 2001 From: Cameron Meissner Date: Fri, 18 Oct 2024 08:17:34 -0700 Subject: [PATCH 05/10] chore: cleanup --- .github/workflows/check-shell.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-shell.yml b/.github/workflows/check-shell.yml index 6b19ffda224..321f30b0148 100644 --- a/.github/workflows/check-shell.yml +++ b/.github/workflows/check-shell.yml @@ -1,8 +1,8 @@ -name: check-shell +name: Lint Shell/Bash Scripts on: pull_request jobs: - check-tests: + shellcheck: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -11,4 +11,4 @@ jobs: go-version: '1.22' - run: | make validate-shell - name: Verify Shell scripts + name: Lint shell/bash scripts with ShellCheck From 9d79fe507409518d5c065d9ff2d54b8be9b14a27 Mon Sep 17 00:00:00 2001 From: Cameron Meissner Date: Fri, 18 Oct 2024 08:24:44 -0700 Subject: [PATCH 06/10] chore: renaming --- .github/workflows/check-generated.yml | 6 +++--- .github/workflows/{check-shell.yml => shellcheck.yml} | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{check-shell.yml => shellcheck.yml} (100%) diff --git a/.github/workflows/check-generated.yml b/.github/workflows/check-generated.yml index 1e198ad84ff..077fdb719ed 100644 --- a/.github/workflows/check-generated.yml +++ b/.github/workflows/check-generated.yml @@ -1,8 +1,8 @@ -name: check-generated +name: Validate testdata on: pull_request jobs: - check-generated: + check-generated-testdata: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -12,4 +12,4 @@ jobs: - run: | make git diff --exit-code - name: Make generate and diff + name: Ensure testdata is updated as necessary diff --git a/.github/workflows/check-shell.yml b/.github/workflows/shellcheck.yml similarity index 100% rename from .github/workflows/check-shell.yml rename to .github/workflows/shellcheck.yml From a4a56b1aef9ed3cacf1edcbd6161d0ce1b44774a Mon Sep 17 00:00:00 2001 From: Cameron Meissner Date: Fri, 18 Oct 2024 08:41:03 -0700 Subject: [PATCH 07/10] chore: changes --- ...rated.yml => check-generated-testdata.yml} | 0 .github/workflows/check-tests.yml | 8 +++---- .github/workflows/validate-components.yml | 20 ++++------------ Makefile | 23 ++++++++++++------- 4 files changed, 23 insertions(+), 28 deletions(-) rename .github/workflows/{check-generated.yml => check-generated-testdata.yml} (100%) diff --git a/.github/workflows/check-generated.yml b/.github/workflows/check-generated-testdata.yml similarity index 100% rename from .github/workflows/check-generated.yml rename to .github/workflows/check-generated-testdata.yml diff --git a/.github/workflows/check-tests.yml b/.github/workflows/check-tests.yml index e0e7e629c9c..7cf0b56c141 100644 --- a/.github/workflows/check-tests.yml +++ b/.github/workflows/check-tests.yml @@ -1,8 +1,8 @@ -name: check-tests +name: Go Unit Tests on: pull_request jobs: - check-tests: + go-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -10,7 +10,5 @@ jobs: with: go-version: '1.22' - run: | - E2E_TEST=true - export E2E_TEST make test - name: Unit Test + name: Run unit tests for go code in pkg/agent diff --git a/.github/workflows/validate-components.yml b/.github/workflows/validate-components.yml index 3e8f0109257..611c84ebcdd 100644 --- a/.github/workflows/validate-components.yml +++ b/.github/workflows/validate-components.yml @@ -1,12 +1,8 @@ -name: Validate component manifest -on: - pull_request: - branches: - - master - workflow_dispatch: {} +name: Validate Components +on: pull_request jobs: - build-and-deploy: + cue: runs-on: ubuntu-latest environment: test steps: @@ -14,7 +10,7 @@ jobs: - uses: actions/setup-go@v3 with: go-version: '1.22' - - name: 'install cue' + - name: Install cue run: | go version GOPATH="$(go env | grep GOPATH | cut -d= -f2 | tr -d '"')" @@ -22,13 +18,7 @@ jobs: pushd /tmp GO111MODULE=on go install cuelang.org/go/cmd/cue@latest popd - - name: 'validate components.json' - run: | - GOPATH="$(go env | grep GOPATH | cut -d= -f2 | tr -d '"')" - export PATH="$PATH:$GOPATH/bin" - cue vet -c ./schemas/manifest.cue - cue eval ./schemas/manifest.cue - - name: 'validate components.json' + - name: Validate components.json conforms to cue schema run: | GOPATH="$(go env | grep GOPATH | cut -d= -f2 | tr -d '"')" export PATH="$PATH:$GOPATH/bin" diff --git a/Makefile b/Makefile index 4f5fd07f346..25ae1388240 100644 --- a/Makefile +++ b/Makefile @@ -93,18 +93,26 @@ generate-kubelet-flags: compile-proto-files: @./hack/tools/bin/buf generate -o . --path ./pkg/proto/ --template ./pkg/proto/buf.gen.yaml -.PHONY: generate -generate: bootstrap - @echo $(GOFLAGS) +.PHONY: generate-manifest +generate-manifest: ./hack/tools/bin/cue export ./schemas/manifest.cue > ./parts/linux/cloud-init/artifacts/manifest.json @echo "#EOF" >> ./parts/linux/cloud-init/artifacts/manifest.json - GENERATE_TEST_DATA="true" go test ./pkg/agent... - @echo "running validate-shell to make sure generated cse scripts are correct" + +# To replace the old monolithic 'generate' target for running go tests, generating test data, and other validations +.PHONY: validate +validate: generate + @echo "Running validate-shell to make sure generated cse scripts are correct" @$(MAKE) validate-shell + @echo "Running shellspec tests to validate shell/bash scripts" + @$(MAKE) shellspec @echo "Validating if components.json conforms to the schema schemas/components.cue." - @echo "Error will be shown if any." @$(MAKE) validate-components +.PHONY: generate +generate: bootstrap + @echo $(GOFLAGS) + GENERATE_TEST_DATA="true" go test ./pkg/agent... + .PHONY: validate-prefetch validate-prefetch: make -C ./vhdbuilder/prefetch generate @@ -171,10 +179,9 @@ endif ginkgoBuild: generate make -C ./test/e2e ginkgo-build -test: generate +test: go test ./... - .PHONY: test-style test-style: validate-go validate-shell validate-copyright-headers From 92a4c2eea9e48124bb457192609baf1f029dc021 Mon Sep 17 00:00:00 2001 From: Cameron Meissner Date: Fri, 18 Oct 2024 08:45:11 -0700 Subject: [PATCH 08/10] chore: remove check-generated --- .github/workflows/check-generated-testdata.yml | 15 --------------- .../workflows/{check-tests.yml => go-test.yml} | 0 2 files changed, 15 deletions(-) delete mode 100644 .github/workflows/check-generated-testdata.yml rename .github/workflows/{check-tests.yml => go-test.yml} (100%) diff --git a/.github/workflows/check-generated-testdata.yml b/.github/workflows/check-generated-testdata.yml deleted file mode 100644 index 077fdb719ed..00000000000 --- a/.github/workflows/check-generated-testdata.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Validate testdata -on: pull_request - -jobs: - check-generated-testdata: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v3 - with: - go-version: '1.22' - - run: | - make - git diff --exit-code - name: Ensure testdata is updated as necessary diff --git a/.github/workflows/check-tests.yml b/.github/workflows/go-test.yml similarity index 100% rename from .github/workflows/check-tests.yml rename to .github/workflows/go-test.yml From 6243806e2296e8e55dddc7fb7bf42c6b88ea654b Mon Sep 17 00:00:00 2001 From: Cameron Meissner Date: Fri, 18 Oct 2024 08:59:16 -0700 Subject: [PATCH 09/10] chore: preserve generate validation --- Makefile | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 25ae1388240..cf1d88fb7d4 100644 --- a/Makefile +++ b/Makefile @@ -98,21 +98,15 @@ generate-manifest: ./hack/tools/bin/cue export ./schemas/manifest.cue > ./parts/linux/cloud-init/artifacts/manifest.json @echo "#EOF" >> ./parts/linux/cloud-init/artifacts/manifest.json -# To replace the old monolithic 'generate' target for running go tests, generating test data, and other validations -.PHONY: validate -validate: generate +.PHONY: generate # TODO: ONLY generate go testdata +generate: bootstrap + @echo $(GOFLAGS) + GENERATE_TEST_DATA="true" go test ./pkg/agent... @echo "Running validate-shell to make sure generated cse scripts are correct" @$(MAKE) validate-shell - @echo "Running shellspec tests to validate shell/bash scripts" - @$(MAKE) shellspec @echo "Validating if components.json conforms to the schema schemas/components.cue." @$(MAKE) validate-components -.PHONY: generate -generate: bootstrap - @echo $(GOFLAGS) - GENERATE_TEST_DATA="true" go test ./pkg/agent... - .PHONY: validate-prefetch validate-prefetch: make -C ./vhdbuilder/prefetch generate From 85035ff1ebdcd184a157a5ec3c873fdff8b8f5d0 Mon Sep 17 00:00:00 2001 From: Cameron Meissner Date: Fri, 18 Oct 2024 09:03:55 -0700 Subject: [PATCH 10/10] chore: refactor --- Makefile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index cf1d88fb7d4..0c3368acb08 100644 --- a/Makefile +++ b/Makefile @@ -98,13 +98,20 @@ generate-manifest: ./hack/tools/bin/cue export ./schemas/manifest.cue > ./parts/linux/cloud-init/artifacts/manifest.json @echo "#EOF" >> ./parts/linux/cloud-init/artifacts/manifest.json -.PHONY: generate # TODO: ONLY generate go testdata -generate: bootstrap +.PHONY: generate-testdata +generate-testdata: @echo $(GOFLAGS) GENERATE_TEST_DATA="true" go test ./pkg/agent... + +.PHONY: generate # TODO: ONLY generate go testdata +generate: bootstrap + @echo "Generating go testdata" + @$(MAKE) generate-testdata + @echo "Generating manifest.cue" + @$(MAKE) generate-manifest @echo "Running validate-shell to make sure generated cse scripts are correct" @$(MAKE) validate-shell - @echo "Validating if components.json conforms to the schema schemas/components.cue." + @echo "Validating components.json conforms to the schema schemas/components.cue." @$(MAKE) validate-components .PHONY: validate-prefetch