forked from we-cli/coverage-badge-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
61 lines (53 loc) · 1.92 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
inputs:
version:
description: Version string will be appended to the badge filename
required: false
type: string
runs:
using: composite
steps:
- name: Get coverage
id: coverage
shell: bash
run: |
COVERAGE=$(node -p 't=require(`./coverage/coverage-summary.json`).total,Math.min(...`lines|statements|functions|branches`.split(`|`).map(k=>t[k].pct))')
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
- name: Get color
id: color
shell: bash
run: |
COLOR=$(node -p '+${{ steps.coverage.outputs.coverage }} >= 95 ? `green` : +${{ steps.coverage.outputs.coverage }} >= 50 ? `orange` : `red`')
echo "color=$COLOR" >> $GITHUB_OUTPUT
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Generate badge
id: badge
uses: emibcn/[email protected]
with:
label: 'coverage'
color: ${{ steps.color.outputs.color }}
status: "${{ format('{0}%', steps.coverage.outputs.coverage) }}"
path: "badges/coverage${{ inputs.version && format('-{0}', inputs.version) }}.svg"
- name: Deploy Badge to gh-pages
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'Update badge [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@v4
with:
ref: ${{ github.ref }}