From 3a22b815237bf7268387467bc9ae0e3bcaff2bf8 Mon Sep 17 00:00:00 2001 From: Abhinandan Purkait Date: Fri, 26 Jul 2024 12:45:18 +0000 Subject: [PATCH] ci: add manifests and codegen validation in pull request Signed-off-by: Abhinandan Purkait --- .github/workflows/build_and_push.yml | 40 ++++++++++++++++++++++++++- .github/workflows/pull_request.yml | 41 +++++++++++++++++++++++++++- .github/workflows/release.yml | 40 ++++++++++++++++++++++++++- Makefile | 20 ++++++++++---- buildscripts/check-diff.sh | 5 ++++ buildscripts/generate-manifests.sh | 4 +-- buildscripts/push | 1 - 7 files changed, 140 insertions(+), 11 deletions(-) create mode 100755 buildscripts/check-diff.sh diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml index 9fb984f4a..0c63f1dca 100644 --- a/.github/workflows/build_and_push.yml +++ b/.github/workflows/build_and_push.yml @@ -35,12 +35,50 @@ jobs: run: | ct lint --config ct.yaml + validate_codegen: + runs-on: ubuntu-latest + env: + GOPATH: ${{ github.workspace }}/go + GOBIN: ${{ github.workspace }}/go/bin + defaults: + run: + working-directory: ${{ env.GOPATH }}/src/github.com/openebs/zfs-localpv + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + path: ${{ env.GOPATH }}/src/github.com/openebs/zfs-localpv + + - name: Set up Go 1.19 + uses: actions/setup-go@v4 + with: + go-version: 1.19.9 + cache: false + + - name: Helm tool installer + uses: Azure/setup-helm@v4.2.0 + + - name: Verify kubegen + run: | + make verify-kubegen + + - name: Verify manifests + run: | + make verify-manifests + unit-tests: runs-on: ubuntu-latest + needs: ["lint", "validate_codegen"] steps: - name: Checkout uses: actions/checkout@v4 + - name: Set up Go 1.19 + uses: actions/setup-go@v4 + with: + go-version: 1.19.9 + cache: false + - name: Unit test run: make test @@ -111,7 +149,7 @@ jobs: csi-driver: runs-on: ubuntu-latest - needs: ["lint", "bdd-tests"] + needs: ["bdd-tests"] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 033fd6894..3a0b54d79 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -33,6 +33,7 @@ jobs: - uses: rrbutani/use-nix-shell-action@v1.1.0 with: file: shell.nix + - name: Check if the chart follows a valid semver version run: | branch_name="${{ github.event.pull_request.base.ref }}" @@ -42,12 +43,50 @@ jobs: run: | ct lint --config ct.yaml + validate_codegen: + runs-on: ubuntu-latest + env: + GOPATH: ${{ github.workspace }}/go + GOBIN: ${{ github.workspace }}/go/bin + defaults: + run: + working-directory: ${{ env.GOPATH }}/src/github.com/openebs/zfs-localpv + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + path: ${{ env.GOPATH }}/src/github.com/openebs/zfs-localpv + + - name: Set up Go 1.19 + uses: actions/setup-go@v4 + with: + go-version: 1.19.9 + cache: false + + - name: Helm tool installer + uses: Azure/setup-helm@v4.2.0 + + - name: Verify kubegen + run: | + make verify-kubegen + + - name: Verify manifests + run: | + make verify-manifests + unit-tests: runs-on: ubuntu-latest + needs: ["lint", "validate_codegen"] steps: - name: Checkout uses: actions/checkout@v4 + - name: Set up Go 1.19 + uses: actions/setup-go@v4 + with: + go-version: 1.19.9 + cache: false + - name: Unit test run: make test @@ -118,7 +157,7 @@ jobs: csi-driver: runs-on: ubuntu-latest - needs: ["lint", "bdd-tests"] + needs: ["bdd-tests"] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 810b49012..bd2030fb7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,12 +28,50 @@ jobs: run: | ct lint --config ct.yaml + validate_codegen: + runs-on: ubuntu-latest + env: + GOPATH: ${{ github.workspace }}/go + GOBIN: ${{ github.workspace }}/go/bin + defaults: + run: + working-directory: ${{ env.GOPATH }}/src/github.com/openebs/zfs-localpv + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + path: ${{ env.GOPATH }}/src/github.com/openebs/zfs-localpv + + - name: Set up Go 1.19 + uses: actions/setup-go@v4 + with: + go-version: 1.19.9 + cache: false + + - name: Helm tool installer + uses: Azure/setup-helm@v4.2.0 + + - name: Verify kubegen + run: | + make verify-kubegen + + - name: Verify manifests + run: | + make verify-manifests + unit-tests: runs-on: ubuntu-latest + needs: ["lint", "validate_codegen"] steps: - name: Checkout uses: actions/checkout@v4 + - name: Set up Go 1.19 + uses: actions/setup-go@v4 + with: + go-version: 1.19.9 + cache: false + - name: Unit test run: make test @@ -104,7 +142,7 @@ jobs: csi-driver: runs-on: ubuntu-latest - needs: ["lint", "bdd-tests"] + needs: ["bdd-tests"] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/Makefile b/Makefile index 00e5ed44e..01cbba674 100644 --- a/Makefile +++ b/Makefile @@ -125,7 +125,7 @@ bootstrap: controller-gen .PHONY: controller-gen controller-gen: - TMP_DIR=$(shell mktemp -d) && cd $$TMP_DIR && go mod init tmp && go install -mod=mod sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.0 && rm -rf $$TMP_DIR; + @go install -mod=mod sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.0 # SRC_PKG is the path of code files SRC_PKG := github.com/openebs/zfs-localpv/pkg @@ -144,7 +144,7 @@ kubegendelete: .PHONY: deepcopy-install deepcopy-install: - @go install -mod=mod k8s.io/code-generator/cmd/deepcopy-gen + @go install -mod=mod k8s.io/code-generator/cmd/deepcopy-gen@v0.27.2 .PHONY: deepcopy deepcopy: @@ -156,7 +156,7 @@ deepcopy: .PHONY: clientset-install clientset-install: - @go install -mod=mod k8s.io/code-generator/cmd/client-gen + @go install -mod=mod k8s.io/code-generator/cmd/client-gen@v0.27.2 .PHONY: clientset clientset: @@ -170,7 +170,7 @@ clientset: .PHONY: lister-install lister-install: - @go install -mod=mod k8s.io/code-generator/cmd/lister-gen + @go install -mod=mod k8s.io/code-generator/cmd/lister-gen@v0.27.2 .PHONY: lister lister: @@ -182,7 +182,7 @@ lister: .PHONY: informer-install informer-install: - @go install -mod=mod k8s.io/code-generator/cmd/informer-gen + @go install -mod=mod k8s.io/code-generator/cmd/informer-gen@v0.27.2 .PHONY: informer informer: @@ -236,4 +236,14 @@ golint: @echo "--------------------------------" @echo "" +.PHONY: verify-manifests +verify-manifests: bootstrap manifests + @./buildscripts/check-diff.sh + @echo "Completed verify-manifests no changes detected !!" + +.PHONY: verify-kubegen +verify-kubegen: bootstrap kubegen + @./buildscripts/check-diff.sh + @echo "Completed verify-codegen no changes detected !!" + include Makefile.buildx.mk diff --git a/buildscripts/check-diff.sh b/buildscripts/check-diff.sh new file mode 100755 index 000000000..34c182bed --- /dev/null +++ b/buildscripts/check-diff.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +git --no-pager diff --exit-code pkg/generated pkg/apis/ deploy/yamls diff --git a/buildscripts/generate-manifests.sh b/buildscripts/generate-manifests.sh index 3eec6f61c..168cbc958 100755 --- a/buildscripts/generate-manifests.sh +++ b/buildscripts/generate-manifests.sh @@ -18,7 +18,7 @@ if [ "$CONTROLLER_GEN" = "" ]; then exit 1; fi -$CONTROLLER_GEN crd:trivialVersions=false,preserveUnknownFields=false paths=./pkg/apis/... output:crd:artifacts:config=$DEPLOY_YAML_DIR +$CONTROLLER_GEN crd:trivialVersions=false,preserveUnknownFields=false paths=./pkg/apis/... output:crd:artifacts:config="$DEPLOY_YAML_DIR" for FILE in "$DEPLOY_YAML_DIR"/zfs.openebs.io_*; do BASE_NAME=$(basename "$FILE" | sed -e 's/^zfs.openebs.io_//' -e 's/s\.yaml$/.yaml/') @@ -32,4 +32,4 @@ for FILE in "$DEPLOY_YAML_DIR"/zfs.openebs.io_*; do awk 'BEGIN { print "{{- if .Values.zfsLocalPv.enabled -}}" } { print } END { if (NR > 0) print "{{- end -}}" }' "$TARGET_FILE" > "$TARGET_FILE.tmp" && mv "$TARGET_FILE.tmp" "$TARGET_FILE" done -helm template $RELEASE_NAME $HELM_CHART_DIR -n $RELEASE_NAMESPACE --set analytics.installerType="zfs-operator" > $DEPLOY_YAML_DIR/../zfs-operator.yaml +helm template "$RELEASE_NAME" "$HELM_CHART_DIR" -n "$RELEASE_NAMESPACE" --set analytics.installerType="zfs-operator" > "$DEPLOY_YAML_DIR"/../zfs-operator.yaml diff --git a/buildscripts/push b/buildscripts/push index 01c2f6e95..5d16ff5bd 100755 --- a/buildscripts/push +++ b/buildscripts/push @@ -118,4 +118,3 @@ then # Push COMMIT tagged image - :COMMIT TagAndPushImage "${DIMAGE}" "${COMMIT}" fi; - \ No newline at end of file