Skip to content

Commit

Permalink
feat: test badge
Browse files Browse the repository at this point in the history
  • Loading branch information
aelf-lxy committed Jul 29, 2024
1 parent 24a17b1 commit 37af607
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
48 changes: 48 additions & 0 deletions .github/actions/badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Coverage Badge
description: Badges for test results and code coverage

# Required for publishing to the marketplace:
# Improve your Action by adding labels for icon and color.
branding:
icon: check-circle
color: green

runs:
using: composite
steps:
- name: Get Values
id: get-values
shell: bash
run: |
COV=$(node -p 't=require(`./packages/utils/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
uses: actions/checkout@v3
with:
ref: gh-pages

- name: Create Badges
shell: bash
run: |
npm i -g badgen-cli
export COV=${{ steps.get-values.outputs.coverage }}
COLOR=$(node -p '+process.env.COV >= 95 ? `green` : `orange`')
mkdir -p badges
badgen -j coverage -s $COV% -c $COLOR > badges/coverage.svg
- name: Deploy Badges
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Update badges [skip ci]"
branch: gh-pages
skip_fetch: true
skip_checkout: true

# Without this, will get Error:
# Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/coverage-badge-action/coverage-badge-action/action.yml'.
# Did you forget to run actions/checkout before running your local action?
- name: Checkout Back
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
4 changes: 1 addition & 3 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,4 @@ jobs:
name: codecov-umbrella

- name: Update Coverage Badge
uses: we-cli/coverage-badge-action@main
with:
coverage-summary: packages/${{ matrix.package }}/coverage/coverage-summary.json
uses: './.github/actions/badge'

0 comments on commit 37af607

Please sign in to comment.