From ad7f275deb846bc97f3b26798a38bda57a08a392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Caiado?= Date: Thu, 7 Mar 2024 17:39:53 +0000 Subject: [PATCH] ci(task-nr): improve conditions expressions to be reusable (#24) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: AndreĢ Caiado da Silva --- .github/workflows/CI-CD.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI-CD.yml b/.github/workflows/CI-CD.yml index d1af289..f2af662 100644 --- a/.github/workflows/CI-CD.yml +++ b/.github/workflows/CI-CD.yml @@ -20,6 +20,9 @@ jobs: push_image: ${{ steps.set-push-image.outputs.PUSH_IMAGE }} deploy: ${{ steps.set-deploy.outputs.DEPLOY }} environment: ${{ steps.set-deploy.outputs.ENVIRONMENT }} + env: + pr_merged: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == 'true' }} + release_published: ${{ github.event_name == 'release' && github.event.action == 'published' }} steps: - name: Validate release target branch if: ${{ github.event_name == 'release' }} @@ -43,8 +46,7 @@ jobs: id: set-push-image shell: bash run: | - if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]] || - [[ "${{ github.event_name }}" == "release" && "${{ github.event.action }}" == "published" ]]; then + if [[ ${{env.pr_merged}} == true || ${{env.release_published}} == true ]]; then echo "Setting PUSH_IMAGE to true" echo "PUSH_IMAGE=true" >> "$GITHUB_OUTPUT" else @@ -55,12 +57,12 @@ jobs: id: set-deploy shell: bash run: | - if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then + if [[ ${{env.pr_merged}} == true ]]; then echo "Setting DEPLOY to true" echo "Setting ENVIRONMENT to staging" echo "DEPLOY=true" >> "$GITHUB_OUTPUT" echo "ENVIRONMENT=STAGING" >> "$GITHUB_OUTPUT" - elif [[ "${{ github.event_name }}" == "release" && "${{ github.event.action }}" == "published" ]]; then + elif [[ ${{env.release_published}} == true ]]; then echo "Setting DEPLOY to true" echo "Setting ENVIRONMENT to production" echo "DEPLOY=true" >> "$GITHUB_OUTPUT"