From 9d6d1cf49cb99043d58dc446d4354a7b696f7a77 Mon Sep 17 00:00:00 2001 From: SheryarButt Date: Wed, 18 Sep 2024 23:53:05 +0500 Subject: [PATCH 01/10] Add conditional checks for running golang tests and helm commands --- .github/workflows/operator_pull_request.yaml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/operator_pull_request.yaml b/.github/workflows/operator_pull_request.yaml index 05e6ef3..54638c4 100644 --- a/.github/workflows/operator_pull_request.yaml +++ b/.github/workflows/operator_pull_request.yaml @@ -14,7 +14,13 @@ on: default: "v1.50.1" required: false type: string - + + RUN_GOLANG_TESTS: + description: Run golang tests + default: false + required: false + type: boolean + DOCKERFILE_PATH: description: Dockerfile path required: true @@ -98,16 +104,19 @@ jobs: # Run Tests - name: Test + if: ${{ inputs.RUN_GOLANG_TESTS }} run: make test # Set up helm binary - name: Set up Helm + if: ${{ inputs.HELM_VERSION }} uses: azure/setup-helm@v4 with: version: ${{ inputs.HELM_VERSION }} # Test Helm Templating - name: Test Helm Template + if: ${{ inputs.HELM_VERSION }} run: | helm dependency build ${{ inputs.HELM_CHARTS_PATH }} helm template ${{ inputs.HELM_CHART_TEMPLATE_NAME }} ${{ inputs.HELM_CHARTS_PATH }} -n ${{ inputs.HELM_CHART_NAMESPACE_NAME }} @@ -128,7 +137,7 @@ jobs: driver-opts: | image=moby/buildkit:v0.9.3 buildkitd-flags: --debug - + - name: Login to Registry uses: docker/login-action@v3 with: From 71819568884f6aea7b7c2131a826ae934df7b4f6 Mon Sep 17 00:00:00 2001 From: SheryarButt Date: Wed, 18 Sep 2024 23:58:28 +0500 Subject: [PATCH 02/10] Update optional Helm chart parameters to be non-required --- .github/workflows/operator_pull_request.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/operator_pull_request.yaml b/.github/workflows/operator_pull_request.yaml index 54638c4..4f5a23e 100644 --- a/.github/workflows/operator_pull_request.yaml +++ b/.github/workflows/operator_pull_request.yaml @@ -28,17 +28,17 @@ on: HELM_CHARTS_PATH: description: Helm charts path - required: true + required: false type: string HELM_CHART_TEMPLATE_NAME: description: Helm template chart name - required: true + required: false type: string HELM_CHART_NAMESPACE_NAME: description: Helm chart namespace name for templates - required: true + required: false type: string HELM_VERSION: From 3e0d0b43ee935ad0a393657fc9590fb35e932515 Mon Sep 17 00:00:00 2001 From: SheryarButt Date: Thu, 19 Sep 2024 00:16:53 +0500 Subject: [PATCH 03/10] Update golangci/golangci-lint-action to v3 and skip package cache --- .github/workflows/operator_pull_request.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/operator_pull_request.yaml b/.github/workflows/operator_pull_request.yaml index 4f5a23e..7bf507f 100644 --- a/.github/workflows/operator_pull_request.yaml +++ b/.github/workflows/operator_pull_request.yaml @@ -11,7 +11,7 @@ on: GOLANG_CI_LINT_VERSION: description: golang-ci-lint version to use - default: "v1.50.1" + default: "v1.53.3" required: false type: string @@ -96,12 +96,13 @@ jobs: go-version: ${{ inputs.GOLANG_VERSION }} - name: Lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v3 with: version: ${{ inputs.GOLANG_CI_LINT_VERSION }} only-new-issues: false args: --timeout 10m - + skip-pkg-cache: true + # Run Tests - name: Test if: ${{ inputs.RUN_GOLANG_TESTS }} From ebe5245edd12a766b12e606be52fad8e4b80689a Mon Sep 17 00:00:00 2001 From: SheryarButt Date: Thu, 19 Sep 2024 00:27:58 +0500 Subject: [PATCH 04/10] Update operator_pull_request.yaml to include golangci-lint step --- .github/workflows/operator_pull_request.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/operator_pull_request.yaml b/.github/workflows/operator_pull_request.yaml index 7bf507f..2f71135 100644 --- a/.github/workflows/operator_pull_request.yaml +++ b/.github/workflows/operator_pull_request.yaml @@ -9,6 +9,12 @@ on: required: false type: string + Run_GOLANG_CI_LINT: + description: Run golangci-lint + default: true + required: false + type: boolean + GOLANG_CI_LINT_VERSION: description: golang-ci-lint version to use default: "v1.53.3" @@ -96,13 +102,14 @@ jobs: go-version: ${{ inputs.GOLANG_VERSION }} - name: Lint + if: ${{ inputs.Run_GOLANG_CI_LINT }} uses: golangci/golangci-lint-action@v3 with: version: ${{ inputs.GOLANG_CI_LINT_VERSION }} only-new-issues: false args: --timeout 10m skip-pkg-cache: true - + # Run Tests - name: Test if: ${{ inputs.RUN_GOLANG_TESTS }} From 9c185e7a59095db707b347df18d329597fd42572 Mon Sep 17 00:00:00 2001 From: SheryarButt Date: Thu, 19 Sep 2024 00:37:59 +0500 Subject: [PATCH 05/10] Add check for helm --- .github/workflows/operator_pull_request.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/operator_pull_request.yaml b/.github/workflows/operator_pull_request.yaml index 2f71135..04897ae 100644 --- a/.github/workflows/operator_pull_request.yaml +++ b/.github/workflows/operator_pull_request.yaml @@ -117,14 +117,14 @@ jobs: # Set up helm binary - name: Set up Helm - if: ${{ inputs.HELM_VERSION }} + if: ${{ inputs.HELM_CHARTS_PATH != '' }} uses: azure/setup-helm@v4 with: version: ${{ inputs.HELM_VERSION }} # Test Helm Templating - name: Test Helm Template - if: ${{ inputs.HELM_VERSION }} + if: ${{ inputs.HELM_CHARTS_PATH != '' }} run: | helm dependency build ${{ inputs.HELM_CHARTS_PATH }} helm template ${{ inputs.HELM_CHART_TEMPLATE_NAME }} ${{ inputs.HELM_CHARTS_PATH }} -n ${{ inputs.HELM_CHART_NAMESPACE_NAME }} From 9eb5fbc07ae845f67a02ed81be63b065da6478d9 Mon Sep 17 00:00:00 2001 From: SheryarButt Date: Mon, 23 Sep 2024 17:59:15 +0500 Subject: [PATCH 06/10] update operator_push.yaml for generic use --- .github/workflows/operator_pull_request.yaml | 2 +- .github/workflows/operator_push.yaml | 43 +++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/.github/workflows/operator_pull_request.yaml b/.github/workflows/operator_pull_request.yaml index 04897ae..9689c99 100644 --- a/.github/workflows/operator_pull_request.yaml +++ b/.github/workflows/operator_pull_request.yaml @@ -23,7 +23,7 @@ on: RUN_GOLANG_TESTS: description: Run golang tests - default: false + default: true required: false type: boolean diff --git a/.github/workflows/operator_push.yaml b/.github/workflows/operator_push.yaml index 486d3f7..6d1afec 100644 --- a/.github/workflows/operator_push.yaml +++ b/.github/workflows/operator_push.yaml @@ -9,12 +9,24 @@ on: required: false type: string + RUN_GOLANG_CI_LINT: + description: Run golangci-lint + default: true + required: false + type: boolean + GOLANG_CI_LINT_VERSION: description: golang-ci-lint version to use - default: "v1.50.1" + default: "v1.53.3" required: false type: string + RUN_GOLANG_TESTS: + description: Run golang tests + default: true + required: false + type: boolean + HELM_VERSION: description: Helm version to use default: "v3.8.2" @@ -28,17 +40,19 @@ on: HELM_CHARTS_PATH: description: Helm charts path - required: true + required: false type: string BOT_USERNAME: description: Bot username to create release - required: true + default: "stakater-github-root" + required: false type: string - + BOT_EMAIL: description: Bot email to create release - required: true + default: "github-root@stakater.com" + required: false type: string RELEASE_BRANCH: @@ -69,15 +83,15 @@ on: HELM_REGISTRY_URL: description: "Helm registry to publish helm chart" - required: true + required: false HELM_REGISTRY_USERNAME: description: "Username to login to helm registry" - required: true + required: false HELM_REGISTRY_PASSWORD: description: "Password to login to helm registry" - required: true + required: false jobs: push-operator-setup: @@ -98,6 +112,7 @@ jobs: fi - name: Check if helm registry secrets are set + if: ${{ inputs.HELM_CHARTS_PATH != '' }} run: | if [ "${{ secrets.HELM_REGISTRY_URL }}" == "" ] || [ "${{ secrets.HELM_REGISTRY_USERNAME }}" == "" ] || [ "${{ secrets.HELM_REGISTRY_PASSWORD }}" == "" ]; then echo "Required secrets 'HELM_REGISTRY_URL' or 'HELM_REGISTRY_USERNAME' or 'HELM_REGISTRY_PASSWORD' are not set!" @@ -118,6 +133,7 @@ jobs: go-version: ${{ inputs.GOLANG_VERSION }} - name: Lint + if: ${{ inputs.RUN_GOLANG_CI_LINT }} uses: golangci/golangci-lint-action@v6 with: version: ${{ inputs.GOLANG_CI_LINT_VERSION }} @@ -126,6 +142,7 @@ jobs: # Run Tests - name: Test + if: ${{ inputs.RUN_GOLANG_TESTS }} run: make test - name: Generate Tag @@ -167,6 +184,7 @@ jobs: # Set up helm binary - name: Set up Helm + if: ${{ inputs.HELM_CHARTS_PATH != '' }} uses: azure/setup-helm@v4 with: version: ${{ inputs.HELM_VERSION }} @@ -184,7 +202,7 @@ jobs: driver-opts: | image=moby/buildkit:v0.9.3 buildkitd-flags: --debug - + - name: Login to Container Registry uses: docker/login-action@v3 with: @@ -208,15 +226,18 @@ jobs: # Update chart tag to the latest semver tag - name: Update Chart Version + if: ${{ inputs.HELM_CHARTS_PATH != '' }} env: VERSION: ${{ needs.push-operator-setup.outputs.new_tag_without_v }} run: make bump-chart - name: Update Chart CRDs + if: ${{ inputs.HELM_CHARTS_PATH != '' }} run: make generate-crds # Publish helm chart - name: Publish Helm chart + if: ${{ inputs.HELM_CHARTS_PATH != '' }} run: | helm dependency build ${{ inputs.HELM_CHARTS_PATH }} helm package ${{ inputs.HELM_CHARTS_PATH }} --destination ./packaged-chart @@ -225,6 +246,7 @@ jobs: # Commit back changes - name: Commit files + if: ${{ inputs.HELM_CHARTS_PATH != '' }} run: | git config --local user.email "${{ inputs.BOT_EMAIL }}" git config --local user.name "${{ inputs.BOT_USERNAME }}" @@ -233,6 +255,7 @@ jobs: git commit -m "[skip-ci] Update artifacts" -a - name: Push changes + if: ${{ inputs.HELM_CHARTS_PATH != '' }} uses: ad-m/github-push-action@master with: github_token: ${{ secrets.ADMIN_TOKEN }} @@ -263,4 +286,4 @@ jobs: status: ${{ job.status }} fields: repo,author,action,eventName,ref,workflow env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file From 696c56c0ef294ef862667c2a37925e9b2a4e5a1d Mon Sep 17 00:00:00 2001 From: SheryarButt Date: Wed, 2 Oct 2024 00:09:15 +0500 Subject: [PATCH 07/10] Add BUILD_CUSTOM_CATALOG input and steps for custom catalog generation --- .github/workflows/operator_pull_request.yaml | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/operator_pull_request.yaml b/.github/workflows/operator_pull_request.yaml index 9689c99..ef53dbb 100644 --- a/.github/workflows/operator_pull_request.yaml +++ b/.github/workflows/operator_pull_request.yaml @@ -53,6 +53,12 @@ on: required: false type: string + BUILD_CUSTOM_CATALOG: + description: Build custom catalog + default: false + required: false + type: boolean + secrets: SLACK_WEBHOOK_URL: description: "Secret to send success/failure message to slack" @@ -159,6 +165,7 @@ jobs: - name: Build and push uses: docker/build-push-action@v6 + id: build_and_push with: context: . file: ${{ inputs.DOCKERFILE_PATH }} @@ -171,6 +178,29 @@ jobs: org.opencontainers.image.source=${{ github.event.repository.clone_url }} org.opencontainers.image.revision=${{ github.sha }} + # Build custom catalog + - name: Generate Tag + if: ${{ inputs.BUILD_CUSTOM_CATALOG }} + id: generate_tag_for_catalog + run: | + sha=${{ github.event.pull_request.head.sha }} + tag="${sha:0:8}" + echo "GIT_TAG=$(echo ${tag})" >> $GITHUB_OUTPUT + + - name: Install CLI tools from OpenShift Mirror + if: ${{ inputs.BUILD_CUSTOM_CATALOG }} + uses: redhat-actions/openshift-tools-installer@v1 + with: + source: "github" + operator-sdk: "v1.32.0" + + - name: Build and Push Bundle and Catalog + if: ${{ inputs.BUILD_CUSTOM_CATALOG }} + run: make custom-bundle bundle-build bundle-push catalog-build catalog-push + env: + IMAGE_DIGEST: ${{ steps.build_and_push.outputs.digest }} + PR_TAG: -${{ steps.generate_tag_for_catalog.outputs.GIT_TAG }} + - name: Comment on PR uses: mshick/add-pr-comment@v2 if: always() From 6a5c7cface6e3c29341cadb356eca392bdeef2ca Mon Sep 17 00:00:00 2001 From: SheryarButt Date: Wed, 2 Oct 2024 00:20:35 +0500 Subject: [PATCH 08/10] Add OPERATOR_SDK_VERSION input to operator_pull_request.yaml --- .github/workflows/operator_pull_request.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/operator_pull_request.yaml b/.github/workflows/operator_pull_request.yaml index ef53dbb..4fec747 100644 --- a/.github/workflows/operator_pull_request.yaml +++ b/.github/workflows/operator_pull_request.yaml @@ -59,6 +59,12 @@ on: required: false type: boolean + OPERATOR_SDK_VERSION: + description: Operator SDK version to use + default: "v1.32.0" + required: false + type: string + secrets: SLACK_WEBHOOK_URL: description: "Secret to send success/failure message to slack" @@ -192,7 +198,7 @@ jobs: uses: redhat-actions/openshift-tools-installer@v1 with: source: "github" - operator-sdk: "v1.32.0" + operator-sdk: ${{ inputs.OPERATOR_SDK_VERSION }} - name: Build and Push Bundle and Catalog if: ${{ inputs.BUILD_CUSTOM_CATALOG }} From 586f3187bcb84d7d7bbc2083b1d47860dc20994a Mon Sep 17 00:00:00 2001 From: SheryarButt Date: Wed, 2 Oct 2024 14:54:33 +0500 Subject: [PATCH 09/10] add custom catalog builds to operator_push.yaml --- .github/workflows/operator_push.yaml | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/operator_push.yaml b/.github/workflows/operator_push.yaml index 6d1afec..55ca9e9 100644 --- a/.github/workflows/operator_push.yaml +++ b/.github/workflows/operator_push.yaml @@ -48,7 +48,7 @@ on: default: "stakater-github-root" required: false type: string - + BOT_EMAIL: description: Bot email to create release default: "github-root@stakater.com" @@ -60,6 +60,18 @@ on: required: true type: string + BUILD_CUSTOM_CATALOG: + description: Build custom catalog + default: false + required: false + type: boolean + + OPERATOR_SDK_VERSION: + description: Operator SDK version to use + default: "v1.32.0" + required: false + type: string + secrets: ADMIN_TOKEN: description: "Secret to pull latest tag" @@ -212,6 +224,7 @@ jobs: - name: Build and push uses: docker/build-push-action@v6 + id: build_and_push with: context: . file: ${{ inputs.DOCKERFILE_PATH }} @@ -224,6 +237,21 @@ jobs: org.opencontainers.image.source=${{ github.event.repository.clone_url }} org.opencontainers.image.revision=${{ github.sha }} + # Build custom catalog + - name: Install CLI tools from OpenShift Mirror + if: ${{ inputs.BUILD_CUSTOM_CATALOG }} + uses: redhat-actions/openshift-tools-installer@v1 + with: + source: "github" + operator-sdk: "v1.32.0" + + - name: Build and Push Bundle and Catalog + if: ${{ inputs.BUILD_CUSTOM_CATALOG }} + run: make custom-bundle bundle-build bundle-push catalog-build catalog-push + env: + IMAGE_DIGEST: ${{ steps.build_and_push.outputs.digest }} + VERSION: ${{ needs.push-operator-setup.outputs.new_tag_without_v }} + # Update chart tag to the latest semver tag - name: Update Chart Version if: ${{ inputs.HELM_CHARTS_PATH != '' }} From 8b80c7528f3f6ca8e5b946afba2ab9546a18628b Mon Sep 17 00:00:00 2001 From: SheryarButt Date: Wed, 2 Oct 2024 14:55:54 +0500 Subject: [PATCH 10/10] Use OPERATOR_SDK_VERSION input in operator_push.yaml --- .github/workflows/operator_push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/operator_push.yaml b/.github/workflows/operator_push.yaml index 55ca9e9..50bf3b6 100644 --- a/.github/workflows/operator_push.yaml +++ b/.github/workflows/operator_push.yaml @@ -243,7 +243,7 @@ jobs: uses: redhat-actions/openshift-tools-installer@v1 with: source: "github" - operator-sdk: "v1.32.0" + operator-sdk: ${{ inputs.OPERATOR_SDK_VERSION }} - name: Build and Push Bundle and Catalog if: ${{ inputs.BUILD_CUSTOM_CATALOG }}