From e4dd5f24a274fbc385199c2864f2c1efcb6b1887 Mon Sep 17 00:00:00 2001 From: AjitPadhi-Microsoft Date: Wed, 27 Nov 2024 17:09:40 +0530 Subject: [PATCH] fix: Container issue fix for multiple branch (#1539) --- .github/workflows/build-docker-images.yml | 13 ++++--------- .github/workflows/build-docker.yml | 11 +++++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build-docker-images.yml b/.github/workflows/build-docker-images.yml index 3b57b5c1d..76b66f627 100644 --- a/.github/workflows/build-docker-images.yml +++ b/.github/workflows/build-docker-images.yml @@ -4,15 +4,9 @@ on: workflow_run: workflows: [Tests] types: [completed] - branches: - - main - - dev - - demo + branches: [main, dev, demo] pull_request: - branches: - - main - - dev - - demo + branches: [main, dev, demo] types: - opened - ready_for_review @@ -38,5 +32,6 @@ jobs: username: ${{ github.event.workflow_run.head_branch == 'main' && 'fruoccopublic' || 'cwydcontainerreg'}} app_name: ${{ matrix.app_name }} dockerfile: ${{ matrix.dockerfile }} - push: ${{ github.event.workflow_run.head_branch == 'main' || github.event.workflow_run.head_branch == 'dev' || github.event.workflow_run.head_branch == 'demo' }} + branch: ${{ github.event.workflow_run.head_branch }} + push: ${{ github.event_name == 'workflow_run' && (github.event.workflow_run.head_branch == 'main' || github.event.workflow_run.head_branch == 'dev' || github.event.workflow_run.head_branch == 'demo') }} secrets: inherit diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 0d14652e9..843f2e898 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -15,6 +15,9 @@ on: dockerfile: required: true type: string + branch: + required: false + type: string push: required: true type: boolean @@ -33,7 +36,7 @@ jobs: uses: actions/checkout@v4 - name: Docker Login - if: ${{ inputs.push == true && github.ref_name == 'main' }} + if: ${{ inputs.push == true && inputs.branch == 'main' }} uses: docker/login-action@v3 with: registry: ${{ inputs.registry }} @@ -41,7 +44,7 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: Dev Docker Login - if: ${{ inputs.push == true && (github.ref_name == 'dev' || github.ref_name == 'demo') }} + if: ${{ inputs.push == true && (inputs.branch == 'dev' || inputs.branch == 'demo') }} uses: docker/login-action@v3 with: registry: ${{ inputs.registry }} @@ -61,7 +64,7 @@ jobs: context: . file: ${{ inputs.dockerfile }} push: ${{ inputs.push }} - cache-from: type=registry,ref=${{ inputs.registry }}/${{ inputs.app_name}}:${{ github.ref_name == 'main' && 'latest' || github.ref_name == 'dev' && 'dev' || github.ref_name == 'demo' && 'demo' || 'latest' }} + cache-from: type=registry,ref=${{ inputs.registry }}/${{ inputs.app_name}}:${{ inputs.branch == 'main' && 'latest' || inputs.branch == 'dev' && 'dev' || inputs.branch == 'demo' && 'demo' || 'latest' }} tags: | - ${{ inputs.registry }}/${{ inputs.app_name}}:${{ github.ref_name == 'main' && 'latest' || github.ref_name == 'dev' && 'dev' || github.ref_name == 'demo' && 'demo' || 'latest' }} + ${{ inputs.registry }}/${{ inputs.app_name}}:${{ inputs.branch == 'main' && 'latest' || inputs.branch == 'dev' && 'dev' || inputs.branch == 'demo' && 'demo' || 'latest' }} ${{ inputs.registry }}/${{ inputs.app_name}}:${{ steps.date.outputs.date }}_${{ github.run_number }}