From 24ca641067266fd1d95f52ebc4ad412ba2b73b74 Mon Sep 17 00:00:00 2001 From: Alejandro Peralta Date: Wed, 11 Dec 2024 01:06:29 +0100 Subject: [PATCH] chore(cd): Adjust deployment rules for target environments --- .github/workflows/deploy.yml | 63 ++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 800419c1..63f9b8ad 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,7 +16,6 @@ on: - 'package.json' jobs: - set_environment_name: name: Set Environment runs-on: ubuntu-latest @@ -26,28 +25,46 @@ jobs: - id: set_env run: echo "env_name=${{ github.ref_name == 'main' && 'production' || github.ref_name }}" >> $GITHUB_OUTPUT - - build_client: - needs: [ set_environment_name ] - environment: - name: ${{ needs.set_environment_name.outputs.env_name }} + trigger_build: runs-on: ubuntu-latest - name: Build Client image and push to Amazon ECR + outputs: + build_client: ${{ steps.changes.outputs.client == 'true' || github.ref_name == 'staging' || github.ref_name == 'main' }} + build_api: ${{ steps.changes.outputs.api == 'true' || github.ref_name == 'staging' || github.ref_name == 'main' }} + build_backoffice: ${{ steps.changes.outputs.backoffice == 'true' || github.ref_name == 'staging' || github.ref_name == 'main' }} steps: - name: Checkout code uses: actions/checkout@v4 - - uses: dorny/paths-filter@v3 - id: client-changes + - name: Detect changes in client and API paths + uses: dorny/paths-filter@v3 + id: changes with: filters: | client: + - '.github/workflows/**' + - 'shared/**' - 'client/**' + api: - '.github/workflows/**' - shared: - 'shared/**' + - 'api/**' + backoffice: + - '.github/workflows/**' + - 'shared/**' + - 'backoffice/**' + build_client: + needs: [ set_environment, trigger_build ] + if: ${{ github.event_name == 'workflow_dispatch' || needs.trigger_build.outputs.build_client == 'true' }} + environment: + name: ${{ needs.set_environment_name.outputs.env_name }} + runs-on: ubuntu-latest + name: Build Client image and push to Amazon ECR + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Configure AWS credentials if: ${{ github.event_name == 'workflow_dispatch' || steps.client-changes.outputs.client == 'true' }} uses: aws-actions/configure-aws-credentials@v4 @@ -86,7 +103,8 @@ jobs: ${{ steps.login-ecr.outputs.registry }}/${{ secrets.CLIENT_REPOSITORY_NAME }}:${{ needs.set_environment_name.outputs.env_name }} build_api: - needs: [ set_environment_name ] + needs: [ set_environment, trigger_build ] + if: ${{ github.event_name == 'workflow_dispatch' || needs.trigger_build.outputs.build_api == 'true' }} environment: name: ${{ needs.set_environment_name.outputs.env_name }} runs-on: ubuntu-latest @@ -95,16 +113,6 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - uses: dorny/paths-filter@v3 - id: api-changes - with: - filters: | - api: - - 'api/**' - - '.github/workflows/**' - shared: - - 'shared/**' - - name: Configure AWS credentials if: ${{ github.event_name == 'workflow_dispatch' || steps.api-changes.outputs.api == 'true' }} uses: aws-actions/configure-aws-credentials@v4 @@ -158,7 +166,8 @@ jobs: ${{ steps.login-ecr.outputs.registry }}/${{ secrets.API_REPOSITORY_NAME }}:${{ needs.set_environment_name.outputs.env_name }} build_backoffice: - needs: [ set_environment_name ] + needs: [ set_environment, trigger_build ] + if: ${{ github.event_name == 'workflow_dispatch' || needs.trigger_build.outputs.build_backoffice == 'true' }} environment: name: ${{ needs.set_environment_name.outputs.env_name }} runs-on: ubuntu-latest @@ -167,16 +176,6 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - uses: dorny/paths-filter@v3 - id: backoffice-changes - with: - filters: | - backoffice: - - 'backoffice/**' - - '.github/workflows/**' - shared: - - 'shared/**' - - name: Configure AWS credentials if: ${{ github.event_name == 'workflow_dispatch' || steps.backoffice-changes.outputs.backoffice == 'true' }} uses: aws-actions/configure-aws-credentials@v4