-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: unit-tests github-action yml파일 추가 및 package.json에 관련 스크립트 추가
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Unit Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
|
||
jobs: | ||
unit-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Create ./env/.env.test file | ||
run: | | ||
mkdir -p ./env | ||
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> ./env/.env.test | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build the project | ||
run: npm run build | ||
|
||
- name: Run unit tests | ||
run: npm run test:unit-coverage | ||
|
||
# The following Steps has been modified based on the following Github-Action. | ||
# https://github.com/marketplace/actions/coverage-badge | ||
- name: Get Values | ||
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
id: get-values | ||
shell: bash | ||
run: | | ||
COV=$(node -p 't=require(`./coverage/coverage-summary.json`).total,Math.min(...`lines|statements|functions|branches`.split(`|`).map(k=>t[k].pct))') | ||
echo "coverage=$COV" >> $GITHUB_OUTPUT | ||
- name: Checkout gh-pages | ||
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: gh-pages | ||
|
||
- name: Create Badges | ||
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
shell: bash | ||
run: | | ||
npm i -g badgen-cli | ||
export COV=${{ steps.get-values.outputs.coverage }} | ||
COLOR=$(node -p '+process.env.COV >= 90 ? `green` : +process.env.COV >= 60 ? `orange` : `red`') | ||
mkdir -p badges | ||
badgen -j "Unit Coverage" -s $COV% -c $COLOR > badges/unitcoverage.svg | ||
- name: Deploy Badges | ||
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
commit_message: "Update badges [skip ci]" | ||
branch: gh-pages | ||
skip_fetch: true | ||
skip_checkout: true | ||
|
||
- name: Checkout Back | ||
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.ref }} |
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