Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Github Actions 워크플로 리팩토링 #230

Merged
merged 9 commits into from
Jan 2, 2024
13 changes: 13 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Setup
description: 'Node.js와 Yarn 패키지를 설치합니다.'
runs:
using: 'composite'
steps:
- name: Node.js 설정
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Yarn 패키지 설치
run: yarn
shell: bash
43 changes: 0 additions & 43 deletions .github/workflows/build-test.yml

This file was deleted.

90 changes: 90 additions & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Production CD

on:
push:
branches: ['main']

jobs:
react:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Node.js 및 Yarn 설치
uses: ./.github/actions/setup

- name: .env 파일 생성
run: |
echo "NODE_ENV=${{ secrets.NODE_ENV }}" >> .env
echo "VITE_API_ENDPOINT=${{ secrets.VITE_API_ENDPOINT }}" >> .env
echo "VITE_SLACK_API_ENDPOINT=${{ secrets.VITE_SLACK_API_ENDPOINT }}" >> .env
echo "VITE_CHANNEL_ID=${{ secrets.VITE_CHANNEL_ID }}" >> .env
echo "VITE_SLACK_ID_DESCRIPTION=${{ secrets.VITE_SLACK_ID_DESCRIPTION }}" >> .env

mv .env packages/web/.env
cat packages/web/.env

- name: React 앱 빌드
run: yarn web build

- name: 빌드된 파일 S3에 배포
uses: awact/s3-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
SOURCE_DIR: './packages/web/dist'
AWS_REGION: 'ap-northeast-2'
AWS_S3_BUCKET: ${{ secrets.AWS_CLIENT_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_CLIENT_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_CLIENT_SECRET_KEY }}

- name: CloudFront 캐시 무효화
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: ${{ secrets.AWS_CLIENT_CLOUDFRONT_ID }}
PATHS: '/*'
AWS_REGION: 'ap-northeast-2'
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_CLIENT_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_CLIENT_SECRET_KEY }}

express:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Node.js 및 Yarn 설치
uses: ./.github/actions/setup

- name: .env 파일 생성
run: |
echo "${{ secrets.EXPRESS_ENV_FILE }}" >> .env
mv .env packages/slack/.env
cat packages/slack/.env

- name: Express 앱 빌드
run: yarn slack build

- name: appspec.yml 파일을 루트 디렉토리로 이동
run: |
mv packages/slack/appspec.yml appspec.yml
mv packages/slack/scripts scripts

- name: AWS Credentials 설정
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_BACKEND_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_BACKEND_SECRET_KEY }}
aws-region: ap-northeast-2

- name: 빌드 내용 및 배포 파일 압축
run: tar cvfz ./$GITHUB_SHA.gz packages/common packages/slack scripts appspec.yml package.json tsconfig.base.json yarn.lock .yarnrc.yml .yarn

- name: 압축 파일 S3 업로드
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.gz s3://${{secrets.AWS_BACKEND_S3_BUCKET}}/deployment/$GITHUB_SHA.gz

- name: CodeDeploy 배포
run: aws deploy create-deployment
--application-name ${{secrets.AWS_BACKEND_CODEDEPLOY_APPLICATION_NAME}}
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name ${{secrets.AWS_BACKEND_CODEDEPLOY_GROUP_NAME}}
--s3-location bucket=${{secrets.AWS_BACKEND_S3_BUCKET}},bundleType=tgz,key=deployment/$GITHUB_SHA.gz
77 changes: 0 additions & 77 deletions .github/workflows/express-deploy.yml

This file was deleted.

43 changes: 43 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build & Test

on:
pull_request:
branches: ['main']

jobs:
api-docs-and-react:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Node.js 및 Yarn 설치
uses: ./.github/actions/setup

- name: API 문서 빌드
run: yarn api-docs build

- name: API 문서로부터 타입 및 함수 자동 생성
run: yarn web orval

- name: React 앱 빌드
run: yarn web build

express:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Node.js 및 Yarn 설치
uses: ./.github/actions/setup

- name: .env 파일 생성
run: |
echo "${{ secrets.EXPRESS_ENV_FILE }}" >> .env
mv .env packages/slack/.env
cat packages/slack/.env

- name: Express 앱 빌드
run: yarn slack build

- name: Express 앱 테스트 코드 실행
run: yarn slack test
49 changes: 0 additions & 49 deletions .github/workflows/react-deploy.yml

This file was deleted.

2 changes: 1 addition & 1 deletion packages/api-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "api-docs",
"packageManager": "yarn@3.6.3",
"scripts": {
"build": "tsc && swagger-cli bundle ./src/swagger/index.yaml --outfile dist/swagger.yaml --type yaml",
"build": "tsc && swagger-cli bundle ./src/swagger/index.yaml --outfile dist/swagger.yaml --type yaml && swagger-cli validate ./dist/swagger.yaml",
"start": "swagger-cli bundle ./src/swagger/index.yaml --outfile dist/swagger.yaml --type yaml && ts-node src/app.ts"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/slack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
"noFallthroughCasesInSwitch": true
},
"include": ["src", "./src/**/*.ts"],
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules", "dist", "src/**/*.test.ts"]
}