Skip to content

refactor: ์ƒ์‚ฐ๋ถˆ์ถœ ๋“ฑ๋ก ์‹œ ์ด๋ฏธ์ง€ #134

refactor: ์ƒ์‚ฐ๋ถˆ์ถœ ๋“ฑ๋ก ์‹œ ์ด๋ฏธ์ง€

refactor: ์ƒ์‚ฐ๋ถˆ์ถœ ๋“ฑ๋ก ์‹œ ์ด๋ฏธ์ง€ #134

Workflow file for this run

name: Frontend Workflows
on:
push:
branches:
- main # main์œผ๋กœ pushํ•˜๋ฉด workflow ์‹คํ–‰
paths:
- 'SCM/frontend/**'
pull_request:
types: [ opened, reopened, synchronize ] # Pull Request๊ฐ€ ์—ด๋ฆฌ๊ฑฐ๋‚˜, ๋‹ค์‹œ ์—ด๋ฆฌ๊ฑฐ๋‚˜, ๋™๊ธฐํ™”๋  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
branches:
- main # main์œผ๋กœ prํ•˜๋ฉด workflow ์‹คํ–‰
jobs:
CI:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest # ์ตœ์‹  Ubuntu ํ™˜๊ฒฝ
permissions:
contents: read # contents read ๊ถŒํ•œ์„ ๋ถ€์—ฌ
steps:
- uses: actions/checkout@v4 # ๋ ˆํฌ์ง€ํ† ๋ฆฌ ์ฝ”๋“œ๋ฅผ ์ฒดํฌ์•„์›ƒ [v4๋ผ๊ณ  ๋ฒ„์ „ ์ง€์ • ์‹œ v4๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ตœ์‹  ๋ฆด๋ฆฌ์ฆˆ ๋ฒ„์ „์„ ์‚ฌ์šฉ (์ •ํ™•ํ•œ ๋ฒ„์ „ ๊ธฐ์ž… ์‹œ ํ•ด๋‹น ๋ฆด๋ฆฌ์ฆˆ ๋ฒ„์ „๋งŒ ์‚ฌ์šฉ)]
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 20
- name: Create .env.template
run: |
mkdir -p SCM/frontend
cat > SCM/frontend/.env.template <<EOL
VITE_API_URL=\${BACKEND_URL}
EOF
- name: Set env
run: |
envsubst < SCM/frontend/.env.template > SCM/frontend/.env
echo "Generated .env:"
cat SCM/frontend/.env
env:
BACKEND_URL: ${{ secrets.BACKEND_URL }}
- name: Install dependencies
run: npm install
working-directory: ./SCM/frontend
- name: Build project
run: npm run build
working-directory: ./SCM/frontend
- name: Deploy to S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
run: |
aws s3 sync ./SCM/frontend/dist s3://${{ secrets.S3_BUCKET_NAME }} --delete
- name: Invalidate CloudFront Cache
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
run: |
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"
CD:
if: github.event_name == 'push'
runs-on: ubuntu-latest # ์ตœ์‹  Ubuntu ํ™˜๊ฒฝ
permissions:
contents: read # contents read ๊ถŒํ•œ์„ ๋ถ€์—ฌ
steps:
- uses: actions/checkout@v4 # ๋ ˆํฌ์ง€ํ† ๋ฆฌ ์ฝ”๋“œ๋ฅผ ์ฒดํฌ์•„์›ƒ [v4๋ผ๊ณ  ๋ฒ„์ „ ์ง€์ • ์‹œ v4๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ตœ์‹  ๋ฆด๋ฆฌ์ฆˆ ๋ฒ„์ „์„ ์‚ฌ์šฉ (์ •ํ™•ํ•œ ๋ฒ„์ „ ๊ธฐ์ž… ์‹œ ํ•ด๋‹น ๋ฆด๋ฆฌ์ฆˆ ๋ฒ„์ „๋งŒ ์‚ฌ์šฉ)]
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 20
- name: Create .env.template
run: |
mkdir -p SCM/frontend
cat > SCM/frontend/.env.template <<EOL
VITE_API_URL=\${BACKEND_URL}
EOF
- name: Set env
run: |
envsubst < SCM/frontend/.env.template > SCM/frontend/.env
echo "Generated .env:"
cat SCM/frontend/.env
env:
BACKEND_URL: ${{ secrets.BACKEND_URL }}
- name: Install dependencies
run: npm install
working-directory: ./SCM/frontend
- name: Build project
run: npm run build
working-directory: ./SCM/frontend
- name: Deploy to S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
run: |
aws s3 sync ./SCM/frontend/dist s3://${{ secrets.S3_BUCKET_NAME }} --delete
- name: Invalidate CloudFront Cache
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
run: |
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"