From fc28eb821cdc1cb48f0c3cc19b84003b552db4fa Mon Sep 17 00:00:00 2001 From: Xin Ruan Date: Thu, 5 Sep 2024 11:04:43 +0200 Subject: [PATCH] fix: Use workflow call to trigger image build during release (#254) **Description** Due to the [restriction](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/triggering-a-workflow#triggering-a-workflow-from-a-workflow) that use default `GITHUB_TOKEN` to push tags will not trigger related workflow (`build-image.yml`), this PR refactored the create-release workflow to use build-image specifically. Tested in my fork: https://github.com/ruanxin/template-operator/actions/runs/10705244987 **Related issue(s)** --- ...-template-operator.yml => build-image.yml} | 14 ++++++++----- .github/workflows/create-release.yml | 20 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) rename .github/workflows/{build-template-operator.yml => build-image.yml} (79%) diff --git a/.github/workflows/build-template-operator.yml b/.github/workflows/build-image.yml similarity index 79% rename from .github/workflows/build-template-operator.yml rename to .github/workflows/build-image.yml index 8215b59..6147316 100644 --- a/.github/workflows/build-template-operator.yml +++ b/.github/workflows/build-image.yml @@ -4,9 +4,13 @@ on: push: branches: - main # This will get tagged with `latest` and `v{{DATE}}-{{COMMIT_HASH_SHORT}}` - tags: - - '[0-9]+.[0-9]+.[0-9]+' - - '[0-9]+.[0-9]+.[0-9]+-*' + workflow_call: + inputs: + tag: + description: 'Additional tag for built images' + required: false + type: string + default: "" pull_request_target: types: [ opened, edited, synchronize, reopened, ready_for_review ] @@ -25,8 +29,8 @@ jobs: - name: Get the latest tag id: get_tag run: | - if [[ "${{ github.event_name }}" == "push" && "${{ github.ref_type }}" == "tag" ]]; then - echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT + if [[ "${{ inputs.tag }}" != "" ]]; then + echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT elif [[ "${{ github.event_name }}" == "push" ]]; then echo "tag=latest" >> $GITHUB_OUTPUT fi diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 274292e..ea43577 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -50,16 +50,10 @@ jobs: run: | RELEASE_ID=$(./scripts/release/draft_release.sh ${{ github.event.inputs.name }}) echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT - - name: Create lightweight tag + - name: Create tag run: | git tag ${{ github.event.inputs.name }} git push origin ${{ github.event.inputs.name }} --tags - - name: Wait for the Docker image - timeout-minutes: 20 - env: - ITERATIONS: 40 - SLEEP_SECONDS: 30 - run: ./scripts/release/wait_for_image.sh ${{ env.IMAGE_REPO }}:${{ github.event.inputs.name }} $ITERATIONS $SLEEP_SECONDS - name: Create release assets id: create-assets env: @@ -68,7 +62,11 @@ jobs: run: ./scripts/release/upload_assets.sh outputs: release_id: ${{ steps.draft-release.outputs.release_id }} - + builds: + needs: draft-release + uses: ./.github/workflows/build-image.yml + with: + tag: "${{ github.event.inputs.name }}" publish-release: name: Publish release needs: [validate-head-status, draft-release] @@ -78,6 +76,12 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Wait for the Docker image + timeout-minutes: 20 + env: + ITERATIONS: 40 + SLEEP_SECONDS: 30 + run: ./scripts/release/wait_for_image.sh ${{ env.IMAGE_REPO }}:${{ github.event.inputs.name }} $ITERATIONS $SLEEP_SECONDS - name: Publish release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}