필요한 작업 목록
작업 종류 | 작업명 | Marketplace |
---|---|---|
Repo에서 코드 가져오기 | code checkout | O |
머신에 nodejs 세팅하기 | setup node | O |
반복적인 모듈 인스톨을 위한 캐싱 | cache node modules | O |
의존성 설치 | npm install | X |
린트 | npm run lint | X |
유닛 테스트 | npm run test | X |
e2e 테스트 | npm run test:e2e | X |
슬랙으로 알림 보내주기(선택) | Notify Slack | O |
test_on_push.yml
name: test_on_push
on:
push:
branches:
- develop
jobs:
test:
name: test nestjs
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Setup node
uses: actions/setup-node@v4.0.0
with:
node-version: '20'
cache: 'npm'
- name: Cache node modules
uses: actions/cache@v3.3.2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install
- name: Run lint
run: npm run lint
- name: Run tests
run: npm run test
- name: Run e2e tests
run: npm run test:e2e
- name: Notify Slack on Failure
if: failure()
uses: 8398a7/action-slack@v3.15.1
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow
author_name: ${{ github.actor }}
channel: ${{ vars.SLACK_CHANNEL }}
username: ${{ vars.SLACK_USERNAME }}
text: 'Tests failed! :x:'
env:
SLACK_WEBHOOK_URL: ${{ vars.SLACK_WEBHOOK_URL }}
- name: Notify Slack on Success
if: success()
uses: 8398a7/action-slack@v3.15.1
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow
author_name: ${{ github.actor }}
channel: ${{ vars.SLACK_CHANNEL }}
username: ${{ vars.SLACK_USERNAME }}
text: 'Tests passed! :white_check_mark:'
env:
SLACK_WEBHOOK_URL: ${{ vars.SLACK_WEBHOOK_URL }}
크게 신경 쓸 부분은 없고, 슬랙을 사용하시는 경우 몇가지 변수를 Repo에 등록해주셔야 합니다.
vscode를 사용하는 경우: github actions 익스텐션에서 직접 등록
github에서 직접 등록하는 경우
❗참고
Secrets: 등록 후 변수 확인 불가
Variables: 등록 후 변수 확인 가능