CI/CD를 구현하여 프로젝트를 관리 할 것이다. github action
을 통해 아래 두가지 기능을 자동화 시킬 것이다.
yarn lint
와 yarn test
작동루트 폴더에서 .github
와 그 밑에 workflows
폴더를 만들어 준다.
# .github/workflows/ci-functions.yml
name: CI Functions
on: # 실행 조건
push: # 커밋이 푸시되었을때
branches:
- main # 메인 브랜치에
paths:
- "functions/**" # functions폴더 밑에 파일이 수정되었을때
pull_request: # PR이
types: [opened, synchronize, reopened] # 오픈, 동기화, 다시오픈 되었을때ㅔ
paths:
- "functions/**" # functions폴더 밑에 파일이 수정되었을때
jobs:
build:
strategy:
matrix:
platform: [ubuntu-latest]
node: ["16"]
name: Node ${{ matrix.node }} (${{ matrix.platform }})
runs-on: ${{ matrix.platform }}
defaults:
run:
working-directory: functions
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: 패키지 설치
run: yarn
- name: 린트 실행
run: yarn lint
- name: 테스트 실행
run: yarn test
이런 식으로 PR을 남기면 CI action이 작동하는 것을 볼 수 있다.
파이어베이스에 배포하기 위해서는 권한이 필요하다. 터미널에 firebase login:ci
를 실행하여 토큰을 받아와야한다.
받아온 토큰을 github secret으로 한다.
name: CD Functions
on:
push: # 커밋이 푸시됬을때
branches:
- main # 메인브랜치에
paths:
- "functions/**" # functions폴더 밑의 파일이 수정되었을때
jobs:
build-and-deploy:
strategy:
matrix:
platform: [ubuntu-latest]
node: ["16"]
name: Node ${{ matrix.node }} (${{ matrix.platform }})
runs-on: ${{ matrix.platform }}
defaults:
run:
working-directory: functions
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: 패키지 설치
run: |
yarn
yarn build
- name: 파이어베이스 툴 설치
run: npm i firebase-tools -g
- name: 파이어베이스 functions 배포
run: firebase deploy --only functions --token ${{ secrets.FIREBASE_DEPLOY_TOKEN }}
메인 브랜치에 푸시시 이런식으로 CI와 CD action이 실행된다.
CD 액션이 완료되면
파이어베이스에 배포가 된것을 확인 할 수 있다.