From 7a1629aa9dc5802fbe4311d8956d89595d382586 Mon Sep 17 00:00:00 2001 From: Raj Babu Das Date: Tue, 23 Feb 2021 04:18:11 +0530 Subject: [PATCH] Adding parallel GitHub pipeline to reduce the build time (#1635) * refactoring github workflow Signed-off-by: rajdas98 * refactoring github workflow Signed-off-by: rajdas98 * stage-pipeline Signed-off-by: rajdas98 * Refactoring release and push github workflow Signed-off-by: rajdas98 * refactoring github workflow Signed-off-by: rajdas98 * adding release-cli-via-krew Signed-off-by: rajdas98 --- .github/workflows/build.yaml | 132 ++++++++++++++++++++++++++++--- .github/workflows/image.yaml | 58 +++++++++++++- .github/workflows/krew.yaml | 19 ----- .github/workflows/release.yaml | 139 ++++++++++++++++++++++++++++++++- 4 files changed, 313 insertions(+), 35 deletions(-) delete mode 100644 .github/workflows/krew.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 900a13743a..196eb0e7a0 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -8,7 +8,7 @@ on: - 'main' jobs: - build-kyverno: + pre-checks: runs-on: ubuntu-latest steps: - name: Checkout @@ -32,17 +32,40 @@ jobs: - name: gofmt check run: | - if [ "$(gofmt -s -l . | wc -l)" -ne 0 ] - then - echo "The following files were found to be not go formatted:" - gofmt -s -l . - echo "Please run 'make fmt' to go format the above files." - exit 1 - fi + if [ "$(gofmt -s -l . | wc -l)" -ne 0 ] + then + echo "The following files were found to be not go formatted:" + gofmt -s -l . + echo "Please run 'make fmt' to go format the above files." + exit 1 + fi - name: golangci-lint uses: reviewdog/action-golangci-lint@v1 + build-init-kyverno: + runs-on: ubuntu-latest + needs: pre-checks + 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: Set up Docker Buildx uses: docker/setup-buildx-action@v1 id: buildx @@ -51,11 +74,98 @@ jobs: - name: docker images build run: | - make docker-build-all + make docker-build-initContainer + + build-kyverno: + runs-on: ubuntu-latest + needs: pre-checks + 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: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: true + + - name: docker images build + run: | + make docker-build-kyverno + + build-kyverno-cli: + runs-on: ubuntu-latest + needs: pre-checks + 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: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: true + + - name: docker images build + run: | + make docker-build-cli + + tests: + runs-on: ubuntu-latest + needs: pre-checks + 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: Kyverno unit test run: | export PROJECT_PATH=$(pwd) make test-all - - diff --git a/.github/workflows/image.yaml b/.github/workflows/image.yaml index 911f17c0a6..77702a0699 100644 --- a/.github/workflows/image.yaml +++ b/.github/workflows/image.yaml @@ -4,7 +4,7 @@ on: branches: - 'main' jobs: - push-docker-images: + push-init-kyverno: runs-on: ubuntu-latest steps: - name: Checkout @@ -29,4 +29,58 @@ jobs: - name: docker images publish run: | - make docker-publish-all \ No newline at end of file + make docker-publish-initContainer + + push-kyverno: + 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: login to GitHub Container Registry + run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: true + + - name: docker images publish + run: | + make docker-publish-kyverno + + push-kyverno-cli: + 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: login to GitHub Container Registry + run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: true + + - name: docker images publish + run: | + make docker-publish-cli \ No newline at end of file diff --git a/.github/workflows/krew.yaml b/.github/workflows/krew.yaml deleted file mode 100644 index 350ae1fdba..0000000000 --- a/.github/workflows/krew.yaml +++ /dev/null @@ -1,19 +0,0 @@ -name: release kyverno-cli plugin -on: - push: - tags: - - 'v*' - - '!v*-rc*' - -jobs: - release-cli-via-krew: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Unshallow - run: git fetch --prune --unshallow - - - name: Update new version in krew-index - uses: rajatjindal/krew-release-bot@v0.0.38 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a93463d008..d529e106da 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,9 +3,8 @@ on: push: tags: - 'v*' - jobs: - create-release: + release-init-kyverno: runs-on: ubuntu-latest steps: - name: Checkout @@ -43,7 +42,121 @@ jobs: - name : docker images publish run: | - make docker-publish-all + make docker-publish-initContainer + + release-kyverno: + 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: 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 + with: + go-version: 1.14 + - uses: creekorful/goreportcard-action@v1.0 + + - name: login to GitHub Container Registry + run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: true + + - name : docker images publish + run: | + make docker-publish-kyverno + + release-kyverno-cli: + 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: 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 + with: + go-version: 1.14 + - uses: creekorful/goreportcard-action@v1.0 + + - name: login to GitHub Container Registry + run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: true + + - name : docker images publish + run: | + make docker-publish-cli + + create-release: + runs-on: ubuntu-latest + needs: + - release-init-kyverno + - release-kyverno + - release-kyverno-cli + 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: 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 + with: + go-version: 1.14 + - uses: creekorful/goreportcard-action@v1.0 + + - name: login to GitHub Container Registry + run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 @@ -68,3 +181,23 @@ jobs: env: CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + release-cli-via-krew: + runs-on: ubuntu-latest + needs: create-release + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Unshallow + run: git fetch --prune --unshallow + + - name: Check Tag + id: check-tag + run: | + if [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo ::set-output name=match::true + fi + + - name: Update new version in krew-index + if: steps.check-tag.outputs.match == 'true' + uses: rajatjindal/krew-release-bot@v0.0.38