-
Notifications
You must be signed in to change notification settings - Fork 1
63 lines (51 loc) · 1.84 KB
/
update-tests-coverage.yml
File metadata and controls
63 lines (51 loc) · 1.84 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
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Update Tests Coverage
on:
push:
branches: [ "main" ]
jobs:
build:
name: Go test coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Install dependencies
run: go get .
- name: Build
run: go build -v ./...
- name: Run tests and generate coverage badge
id: badge
run: |
go test -coverprofile=coverage.out ./...
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
echo "Coverage: $COVERAGE"
COLOR="gray"
if (( $(echo "$COVERAGE < 50" | bc -l) )); then
COLOR="red"
elif (( $(echo "$COVERAGE >= 50 && $COVERAGE < 80" | bc -l) )); then
COLOR="yellow"
elif (( $(echo "$COVERAGE >= 80 && $COVERAGE < 90" | bc -l) )); then
COLOR="green"
elif (( $(echo "$COVERAGE >= 90" | bc -l) )); then
COLOR="brightgreen"
fi
BADGE_MARKDOWN=""
sed -i "s|!\[Coverage Badge\](.*)|$BADGE_MARKDOWN|g" README.md
- name: Commit coverage badge
continue-on-error: true
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add README.md
if ! git diff-index --quiet HEAD --; then
git commit -m "Update coverage badge to $COVERAGE%"
git push
else
echo "No changes to commit."
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}