Skip to content

Fix code coverage badge & generate docs coverage badge #13

Fix code coverage badge & generate docs coverage badge

Fix code coverage badge & generate docs coverage badge #13

Workflow file for this run

name: CI
# test, build documentation and publish
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
publish:
permissions:
contents: read
packages: read
runs-on: ubuntu-latest
steps:
# Checkout
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: latest
registry-url: https://npm.pkg.github.com
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
# Install dependencies
- run: npm ci --verbose
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install test reporters
run: npm install --no-save --verbose node-test-github-reporter
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Tests
- name: Run tests
run: |
NODE_OPTIONS='--test-reporter=spec --test-reporter-destination=stdout --test-reporter=node-test-github-reporter --test-reporter-destination=stderr --test-reporter=@mafalda-sfu/test-reporter-json --test-reporter-destination=coverage.json' npm test
test -f coverage.json # Ensure coverage.json has been created
# Docs
- name: Generate docs
run: npm run docs
- name: Publish docs
uses: cpina/[email protected]
env:
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
with:
destination-github-username: Mafalda-SFU
destination-repository-name: Mafalda-SFU.github.io
source-directory: docs
target-directory: docs/${{ github.event.repository.name }}
user-email: [email protected]
user-name: Mafalda bot
# Code coverage
- name: Code coverage
run: |
export CODE_COVERAGE=$( \
cat coverage.json | \
jq .summary.totals.coveredLinePercent | \
jq '.*100|round/100' \
)
echo "codeCoverage=$CODE_COVERAGE" >> $GITHUB_ENV
echo "### Code coverage: ${CODE_COVERAGE}%" >> $GITHUB_STEP_SUMMARY
- name: Code coverage badge
uses: Schneegans/[email protected]
with:
auth: ${{ secrets.GIST_SECRET }}
filename: ${{ github.event.repository.name }}.json
gistID: 27d772a9a3a8a945b34fd9676de40486
label: Code coverage
minColorRange: 50
message: ${{ env.codeCoverage }}%
maxColorRange: 90
namedLogo: Jest
valColorRange: ${{ env.codeCoverage }}
# Docs coverage
- run: npm run docs:coverage
- name: Docs coverage
run: |
export DOCS_COVERAGE=$(cat doc-coverage/docCoverageReport.json | jq .jsdocCoverage.coveragePercent)
echo "docsCoverage=$DOCS_COVERAGE" >> $GITHUB_ENV
echo "### Docs coverage: ${DOCS_COVERAGE}%" >> $GITHUB_STEP_SUMMARY
- name: Docs coverage badge
uses: Schneegans/[email protected]
with:
auth: ${{ secrets.GIST_SECRET }}
filename: ${{ github.event.repository.name }}.json
gistID: 7238ab5f664c36d1edfa48d218eea9b3
label: Docs coverage
minColorRange: 50
message: ${{ env.docsCoverage }}%
maxColorRange: 90
namedLogo: readdotcv
valColorRange: ${{ env.docsCoverage }}