프로젝트를 진행하면서 코드 스타일, 빌드, 테스트등 수정사항이 일어날 때 마다 수기로 테스트 했었다.
하지만 어려명의 개발자와 작업하면서 개개인의 서로 다른 설정 문제로(IDE 코드 스타일등…) 잦은 코드 컨플릭트가 발생했다.
코드 변경사항이 나올때 마다 일일히 테스트를 진행 하는건 시간적으로 낭비가 심하다 생각해 자동화된 테스팅을 진행할 수 있는 Github-Actions를 도입하게 되었다.
해당 게시글에서는 Github-Actions를 통해 코드 자동 검사 및 정렬, 빌드 성공 확인, 테스트 코드 자동 검증을 도입 하려고 한다.
.github/workflows
디렉토리에 CI.YAML
파일을 생성한다.
.env
파일을 생성하고 테스트코드 검증name: CI
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 21.x ]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Install the project dependencies
run: npm install
- name: Fix code style issues with prettier & eslint
run: npm run lint:fix && npm run prettier:fix
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
test:
environment: development
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 21.x ]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: .env setting
run: |
touch .env
echo "APP_API_URL=${{ secrets.APP_API_URL }}" >> .env
echo "NEXTAUTH_URL=${{ secrets.NEXTAUTH_URL }}" >> .env
echo "NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}" >> .env
env:
APP_API_URL: ${{ secrets.APP_API_URL }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
- name: Install the project dependencies
run: npm install
- name: Run tests
run: npm run jest
build:
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 21.x ]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install the project dependencies
run: npm install
- name: Build the project
run: npm run build
Github에 들어가 설정을 통해 해당 액션이 성공했을때만 PR
이 Merge 되도록 설정할 수 있다.