Skip to content

Commit b9037f6

Browse files
committed
filters and matrix in workflow
1 parent da45214 commit b9037f6

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

.github/workflows/deploy.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ jobs:
3434
name: Build and Push ${{ matrix.service }} to ECR
3535
runs-on: ubuntu-latest
3636

37-
if: |
38-
(${{ matrix.service }} == 'backend' && needs.detect-changes.outputs.backend == 'true') ||
39-
(${{ matrix.service }} == 'frontend' && needs.detect-changes.outputs.frontend == 'true') ||
40-
(${{ matrix.service }} == 'gateway' && needs.detect-changes.outputs.gateway == 'true')
41-
4237
strategy:
4338
fail-fast: false
4439
matrix:
@@ -48,31 +43,46 @@ jobs:
4843
context: ./backend
4944
dockerfile: ./backend/Dockerfile
5045
image: movie-api
46+
changed: ${{ needs.detect-changes.outputs.backend }}
5147
- service: frontend
5248
context: ./frontend
5349
dockerfile: ./frontend/Dockerfile
5450
image: frontend
51+
changed: ${{ needs.detect-changes.outputs.frontend }}
5552
- service: gateway
5653
context: ./gateway
5754
dockerfile: ./gateway/Dockerfile
5855
image: gateway
56+
changed: ${{ needs.detect-changes.outputs.gateway }}
57+
5958

6059
steps:
60+
61+
- name: Skip if no changes
62+
if: matrix.changed != 'true'
63+
run: |
64+
echo "No changes detected for ${{ matrix.service }}, skipping build"
65+
exit 0
66+
6167
- name: Checkout code
68+
if: matrix.changed == 'true'
6269
uses: actions/checkout@v4
6370

6471
- name: Configure AWS credentials
72+
if: matrix.changed == 'true'
6573
uses: aws-actions/configure-aws-credentials@v4
6674
with:
6775
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
6876
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
6977
aws-region: eu-west-1 # change to your AWS region
7078

7179
- name: Log in to Amazon ECR
80+
if: matrix.changed == 'true'
7281
id: login-ecr
7382
uses: aws-actions/amazon-ecr-login@v2
7483

7584
- name: Build, Tag, and Push Image to ECR
85+
if: matrix.changed == 'true'
7686
env:
7787
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
7888
REPO_NAME: movie_api

0 commit comments

Comments
 (0)