feat: add ci workflow #5
Workflow file for this run
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
name: CI Pipeline | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [20.x] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Install dependencies | |
working-directory: app | |
run: npm install | |
- name: Lint code | |
working-directory: app | |
run: npm run lint | |
- name: Run tests | |
working-directory: app | |
run: npm run test | |
- name: Run coverage | |
working-directory: app | |
run: npm run test:cov | |
- name: Upload coverage report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage-report | |
path: app/coverage/lcov-report/ | |
- name: Extract coverage percentage | |
id: coverage | |
run: | | |
COVERAGE=$(grep -m 1 -o '[0-9]*\.[0-9]*%' coverage/lcov-report/index.html) | |
echo "coverage=$COVERAGE" >> $GITHUB_ENV | |
- name: Post coverage to PR | |
uses: actions/github-script@v6 | |
if: github.event_name == 'pull_request' | |
with: | |
script: | | |
const coverage = process.env.coverage; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `## Test Coverage\n\nThe current test coverage is **${coverage}**.` | |
}); |