refactor: ์์ฐ๋ถ์ถ ๋ฑ๋ก ์ ์ด๋ฏธ์ง #134
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "/*" |