-
Notifications
You must be signed in to change notification settings - Fork 10
78 lines (66 loc) · 2.34 KB
/
Copy pathcoverage.yml
File metadata and controls
78 lines (66 loc) · 2.34 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Update Coverage Badge
on:
workflow_run:
workflows: ["CI"]
types:
- completed
branches: [main]
permissions:
contents: write
jobs:
update-badge:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v4
- name: Download coverage artifact
uses: actions/download-artifact@v4
continue-on-error: true
id: download
with:
name: coverage-percentage
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Update README badge
if: steps.download.outcome == 'success'
run: |
# Check if coverage file exists
if [ ! -f "coverage-percentage.json" ]; then
echo "Coverage percentage file not found, skipping"
exit 0
fi
# Read coverage percentage
COVERAGE=$(jq -r '.coverage' coverage-percentage.json)
# Determine color based on coverage
if (( $(echo "$COVERAGE >= 90" | bc -l) )); then
COLOR="brightgreen"
elif (( $(echo "$COVERAGE >= 80" | bc -l) )); then
COLOR="green"
elif (( $(echo "$COVERAGE >= 70" | bc -l) )); then
COLOR="yellow"
elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then
COLOR="orange"
else
COLOR="red"
fi
echo "Updating coverage badge to ${COVERAGE}% with color ${COLOR}"
# Update README.md with new badge
sed -i "s|Coverage-[0-9.]*%25-[a-z]*|Coverage-${COVERAGE}%25-${COLOR}|g" README.md
- name: Check if README changed
id: check-changes
run: |
if git diff --exit-code README.md; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "Coverage badge is already up to date"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "Coverage badge needs updating"
fi
- name: Commit updated README
if: steps.check-changes.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "chore: update coverage badge to $(jq -r '.coverage' coverage-percentage.json)% [skip ci]"
git push