Skip to content

Commit e593d33

Browse files
committed
refactor: update workflow files
1 parent 34497aa commit e593d33

File tree

3 files changed

+47
-17
lines changed

3 files changed

+47
-17
lines changed

.github/workflows/deploy-backend.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,28 @@ jobs:
1919
- name: Checkout repository
2020
uses: actions/checkout@v3
2121

22-
- name: Check if backend directory changed
23-
id: changes
22+
- name: Download artifact
23+
uses: actions/download-artifact@v3
24+
with:
25+
name: changed-files
26+
path: .
27+
28+
- name: Check for backend changes
29+
id: backend-check
2430
run: |
25-
echo "CHANGED=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.workflow_run.head_sha }} | grep '^backend/' || true)" >> $GITHUB_ENV
31+
if grep '^backend/' changed_files.txt; then
32+
echo "Backend changed"
33+
echo "DEPLOY=true" >> $GITHUB_ENV
34+
else
35+
echo "No backend changes"
36+
echo "DEPLOY=false" >> $GITHUB_ENV
37+
fi
2638
2739
- name: Exit if no backend changes
28-
if: env.CHANGED == ''
29-
run: |
30-
echo "No changes in /backend. Skipping deployment."
31-
exit 0
40+
if: env.DEPLOY == 'false'
41+
run: exit 0
3242

3343
- name: Deploy on EC2
34-
if: env.CHANGED != ''
3544
uses: appleboy/ssh-action@master
3645
with:
3746
host: ${{ secrets.SSH_HOST }}

.github/workflows/deploy-frontend.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,26 @@ jobs:
2323
- name: Checkout repository
2424
uses: actions/checkout@v3
2525

26-
- name: Check if frontend directory changed
27-
id: changes
26+
- name: Download artifact
27+
uses: actions/download-artifact@v3
28+
with:
29+
name: changed-files
30+
path: .
31+
32+
- name: Check for frontend changes
33+
id: frontend-check
2834
run: |
29-
echo "CHANGED=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.workflow_run.head_sha }} | grep '^frontend/' || true)" >> $GITHUB_ENV
35+
if grep '^frontend/' changed_files.txt; then
36+
echo "Frontend changed"
37+
echo "DEPLOY=true" >> $GITHUB_ENV
38+
else
39+
echo "No frontend changes"
40+
echo "DEPLOY=false" >> $GITHUB_ENV
41+
fi
3042
3143
- name: Exit if no frontend changes
32-
if: env.CHANGED == ''
33-
run: |
34-
echo "No changes in /frontend. Skipping deployment."
35-
exit 0
44+
if: env.DEPLOY == 'false'
45+
run: exit 0
3646

3747
- name: Set up Node.js
3848
uses: actions/setup-node@v3
@@ -50,7 +60,6 @@ jobs:
5060
run: npm run build
5161

5262
- name: Deploy to S3
53-
if: env.CHANGED != ''
5463
uses: jakejarvis/s3-sync-action@v0.5.1
5564
with:
5665
args: --delete
@@ -62,7 +71,6 @@ jobs:
6271
SOURCE_DIR: frontend/dist
6372

6473
- name: Invalidate CloudFront cache
65-
if: env.CHANGED != ''
6674
run: |
6775
aws cloudfront create-invalidation \
6876
--distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \

.github/workflows/run-code.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,16 @@ jobs:
3333

3434
- name: Check running containers
3535
run: docker ps
36+
37+
- name: Get list of changed files
38+
id: changed
39+
run: |
40+
git fetch origin main
41+
git diff --name-only origin/main > changed_files.txt
42+
cat changed_files.txt
43+
44+
- name: Upload changed files list
45+
uses: actions/upload-artifact@v3
46+
with:
47+
name: changed-files
48+
path: changed_files.txt

0 commit comments

Comments
 (0)