From 5ecdfda4e093efc9c20027acb34c29b19c6f1e27 Mon Sep 17 00:00:00 2001 From: Yuvraj <10830562+evalsocket@users.noreply.github.com> Date: Wed, 16 Dec 2020 01:16:53 +0530 Subject: [PATCH] Improve github action (#1385) * Improve github action Improve the github action fix issue Trigger Krew on relese and skip prerelease Updated create infrastructure script * More changes * More changes * Added check for prerelease * Added check for prerelease * Revert change --- .github/workflows/build.yaml | 42 ++++++------ .github/workflows/e2e.yaml | 66 +++++++++++++++++++ .github/workflows/image.yaml | 2 +- .github/workflows/krew.yaml | 10 +-- .github/workflows/release.yaml | 51 +++++--------- .github/workflows/test.yaml | 58 ---------------- Makefile | 9 ++- .../{ci.sh => create-e2e-infrastruture.sh} | 2 +- 8 files changed, 115 insertions(+), 125 deletions(-) create mode 100644 .github/workflows/e2e.yaml delete mode 100644 .github/workflows/test.yaml rename scripts/{ci.sh => create-e2e-infrastruture.sh} (90%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 01fa8b0fdb..2c24e9eda1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -8,38 +8,38 @@ on: - 'main' jobs: - releaser: + build-kyverno: runs-on: ubuntu-latest steps: - - - name: Checkout + - name: Checkout uses: actions/checkout@v2 - - - name: Unshallow + + - name: Unshallow run: git fetch --prune --unshallow - - - name: Set up Go + + - name: Set up Go uses: actions/setup-go@v2 with: go-version: 1.14 + - name: Cache Go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: golangci-lint + uses: reviewdog/action-golangci-lint@v1 + - name: docker images build run: | make docker-build-all - - name : Create Kind Cluster and setup kustomize + - name: Kyverno unit test run: | - make ci + export PROJECT_PATH=$(pwd) + make test-all + - - name: e2e testing - run: | - echo ">>> Install Kyverno" - sed 's/imagePullPolicy:.*$/imagePullPolicy: IfNotPresent/g' ${GITHUB_WORKSPACE}/definitions/install.yaml | kubectl apply -f - - kubectl apply -f ${GITHUB_WORKSPACE}/definitions/github/rbac.yaml - chmod a+x ${GITHUB_WORKSPACE}/scripts/verify-deployment.sh - sleep 50 - echo ">>> Check kyverno" - kubectl get pods -n kyverno - ${GITHUB_WORKSPACE}/scripts/verify-deployment.sh -n kyverno kyverno - echo ">>> Run Kyverno e2e test" - make test-e2e diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml new file mode 100644 index 0000000000..b93b895750 --- /dev/null +++ b/.github/workflows/e2e.yaml @@ -0,0 +1,66 @@ +name: build +on: + push: + branches: + - 'main' + paths-ignore: + - 'README.md' + - 'samples/**' + - 'charts/**' + - 'documentation/**' + pull_request: + branches: + - 'main' + paths-ignore: + - 'README.md' + - 'samples/**' + - 'charts/**' + - 'documentation/**' + +jobs: + e2e-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Unshallow + run: git fetch --prune --unshallow + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.14 + + - name: Cache Go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: golangci-lint + uses: reviewdog/action-golangci-lint@v1 + + - name: docker images build + run: | + make docker-build-all + + - name : Create Kind Cluster and setup kustomize + run: | + make create-e2e-infrastruture + + - name: e2e testing + run: | + echo ">>> Install Kyverno" + sed 's/imagePullPolicy:.*$/imagePullPolicy: IfNotPresent/g' ${GITHUB_WORKSPACE}/definitions/install.yaml | kubectl apply -f - + kubectl apply -f ${GITHUB_WORKSPACE}/definitions/github/rbac.yaml + chmod a+x ${GITHUB_WORKSPACE}/scripts/verify-deployment.sh + sleep 50 + echo ">>> Check kyverno" + kubectl get pods -n kyverno + ${GITHUB_WORKSPACE}/scripts/verify-deployment.sh -n kyverno kyverno + echo ">>> Run Kyverno e2e test" + make test-e2e + diff --git a/.github/workflows/image.yaml b/.github/workflows/image.yaml index d58f4c1957..be6bed0367 100644 --- a/.github/workflows/image.yaml +++ b/.github/workflows/image.yaml @@ -4,7 +4,7 @@ on: branches: - 'main' jobs: - push-images: + push-docker-images: runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.github/workflows/krew.yaml b/.github/workflows/krew.yaml index 17dda2b37b..30c7b4e9e2 100644 --- a/.github/workflows/krew.yaml +++ b/.github/workflows/krew.yaml @@ -1,9 +1,8 @@ -name: prereleaser +name: release kyverno-cli plugin on: - push: - tags: - - 'v*' - - '!v*-rc*' + release: + types: + - published jobs: release-cli-via-krew: runs-on: ubuntu-latest @@ -15,4 +14,5 @@ jobs: run: git fetch --prune --unshallow - name: Update new version in krew-index + if: "!github.event.release.prerelease" uses: rajatjindal/krew-release-bot@v0.0.38 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 99818e870c..2012666c25 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,18 +1,30 @@ -name: prereleaser +name: releaser on: push: tags: - 'v*' jobs: - docker-and-e2e: + create-release: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 + with: + fetch-depth: 0 - - name: Unshallow - run: git fetch --prune --unshallow + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.14 + + - name: Cache Go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: Set up Go uses: actions/setup-go@v2 @@ -27,36 +39,6 @@ jobs: run: | make docker-publish-all - - name : Create Kind Cluster and setup kustomize - run: | - make ci - - - name: e2e testing - run: | - echo ">>> Install Kyverno" - sed 's/imagePullPolicy:.*$/imagePullPolicy: IfNotPresent/g' ${GITHUB_WORKSPACE}/definitions/install.yaml | kubectl apply -f - - kubectl apply -f ${GITHUB_WORKSPACE}/definitions/github/rbac.yaml - chmod a+x ${GITHUB_WORKSPACE}/scripts/verify-deployment.sh - sleep 50 - echo ">>> Check kyverno" - kubectl get pods -n kyverno - ${GITHUB_WORKSPACE}/scripts/verify-deployment.sh -n kyverno kyverno - echo ">>> Run Kyverno e2e test" - make test-e2e - - create-release: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.14 - - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 with: @@ -79,3 +61,4 @@ jobs: uses: helm/chart-releaser-action@v1.1.0 env: CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index 69cc164b71..0000000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,58 +0,0 @@ -name: test -on: - push: - branches: - - main - pull_request: - branches: - - main - - -jobs: - releaser: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Unshallow - run: git fetch --prune --unshallow - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.14 - - - name: Cache Go modules - uses: actions/cache@v1 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: golangci-lint - uses: reviewdog/action-golangci-lint@v1 - - - name: Go Get - run: | - go get ./... - - - name: Build - run: | - make initContainer - make kyverno - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 - with: - version: latest - args: --rm-dist --skip-publish --snapshot - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Kyverno Test - run: | - export PROJECT_PATH=$(pwd) - make test-all diff --git a/Makefile b/Makefile index fe2b0e39a9..d44f952d90 100644 --- a/Makefile +++ b/Makefile @@ -116,13 +116,12 @@ docker-build-all: docker-build-initContainer docker-build-kyverno docker-build-c docker-tag-all: docker-tag-repo-initContainer docker-tag-repo-kyverno docker-tag-repo-cli ################################## -# CI Testing +# Create e2e Infrastruture ################################## -ci: - echo "kustomize input" - chmod a+x $(PWD)/scripts/ci.sh - $(PWD)/scripts/ci.sh +create-e2e-infrastruture: + chmod a+x $(PWD)/scripts/create-e2e-infrastruture.sh + $(PWD)/scripts/create-e2e-infrastruture.sh ################################## diff --git a/scripts/ci.sh b/scripts/create-e2e-infrastruture.sh similarity index 90% rename from scripts/ci.sh rename to scripts/create-e2e-infrastruture.sh index cf24d9fac5..b4424743d6 100755 --- a/scripts/ci.sh +++ b/scripts/create-e2e-infrastruture.sh @@ -20,4 +20,4 @@ echo "Installing kustomize" curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash kustomize edit set image ghcr.io/kyverno/kyverno:$hash kustomize edit set image ghcr.io/kyverno/kyvernopre:$hash -kustomize build $pwd/definitions/ > $pwd/definitions/install.yaml \ No newline at end of file +kustomize build $pwd/definitions/ -o $pwd/definitions/install.yaml