-
Notifications
You must be signed in to change notification settings - Fork 1
61 lines (50 loc) · 1.73 KB
/
update-tests-coverage.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
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Update Tests Coverage
on:
push:
# push:
# branches: [ "main" ]
# pull_request:
# 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: Test with coverage
run: go test -coverprofile=coverage.out -v ./...
- name: Generate coverage percentage
id: coverage
run: |
go tool cover -func=coverage.out | grep total | awk '{print $3}' > coverage.txt
COVERAGE=$(cat coverage.txt | sed 's/%//')
echo "coverage=$COVERAGE" >> $GITHUB_ENV
- name: Generate Coverage Badge
id: badge
run: |
COVERAGE=$(echo ${{ env.coverage }})
echo $COVERAGE
COLOR="red"
if [ $(echo "$COVERAGE > 80" | bc) -eq 1 ]; then COLOR="green"; fi
if [ $(echo "$COVERAGE > 50" | bc) -eq 1 ]; then COLOR="yellow"; fi
echo "https://img.shields.io/badge/Coverage-${COVERAGE}%25-${COLOR}.svg" > badge-url.txt
- name: Commit coverage badge
run: |
BADGE_URL=$(cat badge-url.txt)
echo "![Coverage Badge](${BADGE_URL})" > coverage-badge.md
git config --global user.name 'GitHub Actions'
git config --global user.email 'actions@github.com'
git add coverage-badge.md
git commit -m "Update coverage badge"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}