-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (40 loc) · 1.29 KB
/
test.yaml
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
name: Testing
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.22
- name: Install dependencies
run: go mod download
- name: Run tests
run: go test -v -coverprofile=coverage.out ./...
- name: Extract coverage percentage
id: extract_coverage
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}')
echo "COVERAGE=${COVERAGE%%.*}" >> $GITHUB_ENV
- name: Update README with coverage badge
if: ${{ github.event_name == 'pull_request' }}
run: |
sed -i "1 s|Coverage-[0-9]\{1,3\}-brightgreen|Coverage-${COVERAGE}-brightgreen|" README.md
- name: Push README changes (PR Only)
if: ${{ github.event_name == 'pull_request' }}
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: Update coverage badge in README
add: README.md
push: origin HEAD:${{ github.head_ref || github.ref_name }}