-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (86 loc) · 3.09 KB
/
frontend-prod-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Siso - 밸런스 게임 프론트엔드 배포 자동화 워크 플로우(frontend-prod)
on:
push:
branches: ["main"]
permissions:
checks: write
jobs:
detect-changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
backend: ${{ steps.filter.outputs.backend }} # backend 변경 여부를 출력으로 설정
frontend: ${{ steps.filter.outputs.frontend }} # frontend 변경 여부를 출력으로 설정
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # 모든 Git 히스토리를 가져옴
- name: Get previous tag
id: previoustag
run: echo "PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ --always)" >> $GITHUB_OUTPUT
# 이전 태그를 찾아서 환경 변수로 저장
- uses: dorny/paths-filter@v3
id: filter
with:
base: ${{ steps.previoustag.outputs.PREVIOUS_TAG }} # 이전 태그 기준
ref: ${{ github.ref }} # 현재 GitHub 참조(커밋, 태그 등)
filters: |
backend:
- 'backend/**'
frontend:
- 'frontend/**'
frontend-build:
needs: detect-changes
if: ${{ needs.detect-changes.outputs.frontend == 'true' }}
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./frontend
steps:
- name: Siso - 밸런스게임의 코드 가져오기
uses: actions/checkout@v4
- name: 노드 버전 설정
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: 의존성 캐시 확인
uses: actions/cache@v4
with:
path: "frontend/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} # package-lock.json을 기준으로 캐시 키 생성
restore-keys: |
${{ runner.os }}-node-
- name: 의존성 설치
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci
- name: 프론트엔드 빌드
run: npm run build
- name: 빌드 파일 아티팩트로 저장
uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: frontend/dist
frontend-deploy:
needs: frontend-build
if: ${{ needs.detect-changes.outputs.frontend == 'true' }}
runs-on: ubuntu-latest
steps:
- name: 빌드 파일 다운로드
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: ./frontend/dist
- name: Set up AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }} # Replace with your AWS region
- name: Deploy to S3
run: |
aws s3 sync ./frontend/dist s3://siso-balance-game --delete
- name: Invalidate CloudFront
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID_PROD }} --paths "/*"