From 8498806e85ff51f6a23937ac55c40e1a16358347 Mon Sep 17 00:00:00 2001 From: Muhammad Faizan Date: Wed, 18 Sep 2024 16:25:17 +0200 Subject: [PATCH] chore: replace prow build job waiting with github action (#639) * replace prow build job waiting with github action * updated * updated * updated * updated * updated * updated * updated --- .github/workflows/create-release.yml | 19 ++-- .../workflows/e2e-upgrade-test-reusable.yaml | 17 ---- .github/workflows/e2e.yml | 86 +++++++++---------- .github/workflows/pull-e2e-upgrade-test.yaml | 9 +- .github/workflows/pull-target-e2e.yml | 20 ++--- .github/workflows/push-e2e-upgrade-test.yaml | 10 ++- 6 files changed, 74 insertions(+), 87 deletions(-) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 75b8e136..d29bb816 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -185,6 +185,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + token: ${{ secrets.BOT_PAT }} # creating git tag using bot token because GITHUB_TOKEN would not trigger build workflow (https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow). - name: Create changelog env: @@ -199,15 +200,14 @@ jobs: RELEASE_ID=$(./hack/ci/create_draft_release.sh $VERSION) echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT - - name: Trigger prow job 'release-eventing-manager-build' + - name: Add lightweight tag to trigger release build job + env: + GITHUB_TOKEN: ${{ secrets.BOT_PAT }} # creating git tag using bot token because GITHUB_TOKEN would not trigger build workflow (https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow). run: | - # The job release-eventing-manager-build will be triggered by pushing a new tag (format: x.y.z) to the repo. + # The build job will be triggered by pushing a new tag (format: x.y.z) to the repo. git tag $VERSION git push origin $VERSION - - name: Wait for job 'release-eventing-manager-build' to succeed - run: ./hack/ci/wait-for-release-build-job.sh ${{ github.ref_name }} 600 10 30 # Inputs: repo (format: "owner/repo"), timeout, interval and initial wait time. - - name: Create and upload eventing-manager.yaml and eventing-default-cr.yaml env: PULL_BASE_REF: ${{ needs.generate-version.outputs.VERSION }} @@ -218,11 +218,20 @@ jobs: run: | ./hack/ci/render_and_upload_manifests.sh + wait-until-build-succeeds: + needs: [generate-version, create-draft] + uses: "kyma-project/eventing-tools/.github/workflows/wait-build-reusable.yml@main" + with: + repository: ${{ github.repository_owner }}/eventing-manager + git_ref: ${{ needs.generate-version.outputs.VERSION }} + git_check_run_name: "build-${{ needs.generate-version.outputs.VERSION }} / Build image" + bump-sec-scanners-config-main: name: Bump sec-scanners-config.yaml on main branch needs: - create-draft - generate-version + - wait-until-build-succeeds runs-on: ubuntu-latest env: VERSION: ${{ needs.generate-version.outputs.VERSION }} diff --git a/.github/workflows/e2e-upgrade-test-reusable.yaml b/.github/workflows/e2e-upgrade-test-reusable.yaml index 2bdf4bbe..f380ef99 100644 --- a/.github/workflows/e2e-upgrade-test-reusable.yaml +++ b/.github/workflows/e2e-upgrade-test-reusable.yaml @@ -18,9 +18,6 @@ on: required: true type: string description: "The image tag of the Eventing Manager after the upgrade" - build-job-name: - type: string - description: "The name of the build job to wait for" commit-sha: type: string description: "The commit sha of the new version" @@ -88,20 +85,6 @@ jobs: make e2e-setup make e2e-eventing-setup - - name: Wait for the ${{ inputs.build-job-name }} job to succeed - if: ${{ inputs.build-job-name != '' }} - uses: kyma-project/wait-for-commit-status-action@2b3ffe09af8b6f40e1213d5fb7f91a7bd41ffb20 - with: - context: ${{ inputs.build-job-name }} - commit_ref: "${{ inputs.commit-sha }}" - timeout: 600000 # 10 minutes in milliseconds - # The check interval is kept long otherwise it will exhaust the GitHub rate limit (More info: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting) - check_interval: 60000 # 1 minute in milliseconds - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - GITHUB_OWNER: "${{ github.repository_owner }}" - GITHUB_REPO: "eventing-manager" - - name: Upgrade Eventing manager id: upgrade-eventing-manager run: | diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 695bd4c4..13f0cc96 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -35,60 +35,52 @@ on: - PROJECT jobs: - wait-until-build-succeeds: + export-info: runs-on: ubuntu-latest outputs: image-name: ${{ steps.extract-image.outputs.image_name }} + git-ref: ${{ steps.extract-image.outputs.git_ref }} steps: - - uses: actions/checkout@v4 - - - name: Wait for the 'pull-eventing-manager-build' job to succeed - id: pull-wait-build - if: github.event_name == 'pull_request' - uses: kyma-project/wait-for-commit-status-action@2b3ffe09af8b6f40e1213d5fb7f91a7bd41ffb20 - with: - context: "pull-eventing-manager-build" - commit_ref: "${{ github.event.pull_request.head.sha }}" # Note: 'github.event.pull_request.head.sha' is not same as 'github.sha' on pull requests. - timeout: 600000 # 10 minutes in milliseconds - # The check interval is kept long otherwise it will exhaust the GitHub rate limit (More info: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting) - check_interval: 60000 # 1 minute in milliseconds - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - GITHUB_OWNER: "${{ github.repository_owner }}" - GITHUB_REPO: "eventing-manager" - - - name: Wait for the 'post-eventing-manager-build' job to succeed - id: push-wait-build - if: github.event_name == 'push' - uses: kyma-project/wait-for-commit-status-action@2b3ffe09af8b6f40e1213d5fb7f91a7bd41ffb20 - with: - context: "post-eventing-manager-build" - commit_ref: "${{ github.sha }}" - timeout: 600000 # 10 minutes in milliseconds - # The check interval is kept long otherwise it will exhaust the GitHub rate limit (More info: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting) - check_interval: 60000 # 1 minute in milliseconds - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - GITHUB_OWNER: "${{ github.repository_owner }}" - GITHUB_REPO: "eventing-manager" - - - name: Extract container image name from build logs (pull) + - name: export correct info based on event (PR or Push) id: extract-image env: - # Refernce: https://docs.github.com/en/actions/learn-github-actions/expressions#example - COMMIT_STATUS_JSON: "${{ github.event_name == 'push' && steps.push-wait-build.outputs.json || steps.pull-wait-build.outputs.json }}" + GIT_EVENT_NAME: "${{ github.event_name }}" + PR_NUMBER: "${{ github.event.number }}" + PR_HEAD_SHA: "${{ github.event.pull_request.head.sha }}" + HEAD_SHA: "${{ github.sha }}" + run: | + if [[ $GIT_EVENT_NAME == "pull_request" ]] + then + echo "exporting info for pull request..." + echo "image_name=europe-docker.pkg.dev/kyma-project/dev/eventing-manager:PR-${PR_NUMBER}" >> "$GITHUB_OUTPUT" + echo "git_ref=${PR_HEAD_SHA}" >> "$GITHUB_OUTPUT" + else + echo "exporting info for push..." + echo "image_name=europe-docker.pkg.dev/kyma-project/prod/eventing-manager:${HEAD_SHA}" >> "$GITHUB_OUTPUT" + echo "git_ref=${HEAD_SHA}" >> "$GITHUB_OUTPUT" + fi + - name: Print info + env: + IMAGE_NAME: ${{ steps.extract-image.outputs.image_name }} + GIT_REF: ${{ steps.extract-image.outputs.git_ref }} run: | - ./scripts/extract_image_from_build_logs.sh - # export value to job output - export IMAGE_NAME="$(cat image.name)" - echo "IMAGE_NAME: ${IMAGE_NAME}" - echo "image_name=${IMAGE_NAME}" >> "$GITHUB_OUTPUT" + echo "IMAGE: $IMAGE_NAME" + echo "Git ref: $GIT_REF" + + + wait-until-build-succeeds: + needs: export-info + uses: "kyma-project/eventing-tools/.github/workflows/wait-build-reusable.yml@main" + with: + repository: ${{ github.repository_owner }}/eventing-manager + git_ref: ${{ needs.export-info.outputs.git-ref }} + git_check_run_name: "build / Build image" nats: runs-on: ubuntu-latest - needs: wait-until-build-succeeds + needs: [export-info, wait-until-build-succeeds] env: - MANAGER_IMAGE: ${{ needs.wait-until-build-succeeds.outputs.image-name }} + MANAGER_IMAGE: ${{ needs.export-info.outputs.image-name }} steps: - uses: actions/checkout@v4 @@ -152,9 +144,9 @@ jobs: PeerAuthentication: runs-on: ubuntu-latest - needs: wait-until-build-succeeds + needs: [export-info, wait-until-build-succeeds] env: - MANAGER_IMAGE: ${{ needs.wait-until-build-succeeds.outputs.image-name }} + MANAGER_IMAGE: ${{ needs.export-info.outputs.image-name }} steps: - uses: actions/checkout@v4 @@ -200,10 +192,10 @@ jobs: kubectl get peerauthentications.security.istio.io -A -o yaml backend-switching: - needs: wait-until-build-succeeds + needs: [export-info, wait-until-build-succeeds] if: github.event_name == 'push' uses: "./.github/workflows/e2e-backend-switching-reuseable.yml" with: - eventing-manager-image: ${{ needs.wait-until-build-succeeds.outputs.image-name }} + eventing-manager-image: ${{ needs.export-info.outputs.image-name }} cluster-name-prefix: "ghem-" secrets: inherit diff --git a/.github/workflows/pull-e2e-upgrade-test.yaml b/.github/workflows/pull-e2e-upgrade-test.yaml index 686f73bf..59ab746f 100644 --- a/.github/workflows/pull-e2e-upgrade-test.yaml +++ b/.github/workflows/pull-e2e-upgrade-test.yaml @@ -15,11 +15,18 @@ on: - PROJECT jobs: + wait-until-build-succeeds: + uses: "kyma-project/eventing-tools/.github/workflows/wait-build-reusable.yml@main" + with: + repository: ${{ github.repository_owner }}/eventing-manager + git_ref: ${{ github.event.pull_request.head.sha }} + git_check_run_name: "build / Build image" + upgrade-test: + needs: wait-until-build-succeeds uses: ./.github/workflows/e2e-upgrade-test-reusable.yaml with: pre-upgrade-image-tag: main post-upgrade-image-tag: PR-${{ github.event.number }} - build-job-name: pull-eventing-manager-build commit-sha: ${{ github.event.pull_request.head.sha }} secrets: inherit diff --git a/.github/workflows/pull-target-e2e.yml b/.github/workflows/pull-target-e2e.yml index 90d4a375..8759600c 100644 --- a/.github/workflows/pull-target-e2e.yml +++ b/.github/workflows/pull-target-e2e.yml @@ -34,22 +34,12 @@ jobs: ./scripts/is_pr_approved.sh wait-until-build-succeeds: - runs-on: ubuntu-latest needs: is-pr-approved - steps: - - name: Wait for the 'pull-eventing-manager-build' job to succeed - id: pull-wait-build - uses: kyma-project/wait-for-commit-status-action@2b3ffe09af8b6f40e1213d5fb7f91a7bd41ffb20 - with: - context: "pull-eventing-manager-build" - commit_ref: "${{ github.event.pull_request.head.sha }}" # Note: 'github.event.pull_request.head.sha' is not same as 'github.sha' on pull requests. - timeout: 600000 # 10 minutes in milliseconds - # The check interval is kept long otherwise it will exhaust the GitHub rate limit (More info: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting) - check_interval: 60000 # 1 minute in milliseconds - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - GITHUB_OWNER: "${{ github.repository_owner }}" - GITHUB_REPO: "eventing-manager" + uses: "kyma-project/eventing-tools/.github/workflows/wait-build-reusable.yml@main" + with: + repository: ${{ github.repository_owner }}/eventing-manager + git_ref: ${{ github.event.pull_request.head.sha }} + git_check_run_name: "build / Build image" backend-switching: needs: wait-until-build-succeeds diff --git a/.github/workflows/push-e2e-upgrade-test.yaml b/.github/workflows/push-e2e-upgrade-test.yaml index 58fa7b65..70ca501b 100644 --- a/.github/workflows/push-e2e-upgrade-test.yaml +++ b/.github/workflows/push-e2e-upgrade-test.yaml @@ -28,12 +28,18 @@ jobs: run: | echo "latest_release_tag=$(curl -s https://api.github.com/repos/kyma-project/eventing-manager/releases/latest | jq -r '.tag_name')" >> "$GITHUB_OUTPUT" + wait-until-build-succeeds: + uses: "kyma-project/eventing-tools/.github/workflows/wait-build-reusable.yml@main" + with: + repository: ${{ github.repository_owner }}/eventing-manager + git_ref: ${{ github.sha }} + git_check_run_name: "build / Build image" + upgrade-test: uses: ./.github/workflows/e2e-upgrade-test-reusable.yaml - needs: get-latest-release + needs: [get-latest-release, wait-until-build-succeeds] with: pre-upgrade-image-tag: ${{ needs.get-latest-release.outputs.latest_release_tag }} post-upgrade-image-tag: main - build-job-name: post-eventing-manager-build commit-sha: ${{ github.sha }} secrets: inherit