-
Notifications
You must be signed in to change notification settings - Fork 10
135 lines (114 loc) · 3.6 KB
/
test.yml
File metadata and controls
135 lines (114 loc) · 3.6 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23"
- name: Test
run: go test ./...
- name: Vet
run: go vet ./...
unit_tests:
name: "Unit tests"
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23"
- name: Run tests with coverage
run: go test ./... -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: code-coverage
path: coverage.txt
if-no-files-found: error
- name: Generate coverage badge
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
TOTAL=$(go tool cover -func=coverage.txt | grep '^total:' | awk '{print $NF}' | tr -d '%')
echo "Total coverage: ${TOTAL}%"
# Determine badge color
if (( $(echo "$TOTAL >= 80" | bc -l) )); then
COLOR="brightgreen"
elif (( $(echo "$TOTAL >= 60" | bc -l) )); then
COLOR="green"
elif (( $(echo "$TOTAL >= 40" | bc -l) )); then
COLOR="yellowgreen"
elif (( $(echo "$TOTAL >= 20" | bc -l) )); then
COLOR="yellow"
else
COLOR="orange"
fi
# Write shields.io endpoint JSON
mkdir -p .github/badges
cat > .github/badges/coverage.json <<-EOF
{
"schemaVersion": 1,
"label": "coverage",
"message": "${TOTAL}%",
"color": "${COLOR}"
}
EOF
# Commit and push badge data to main
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .github/badges/coverage.json
git diff --cached --quiet || git commit -m "Update coverage badge [skip ci]"
git push
- name: Run shell tests
run: bash static/build/docker-entrypoint_test.sh
code_coverage:
name: "Code coverage report"
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: unit_tests
continue-on-error: true # Don't block PR if baseline is missing (first run)
permissions:
contents: read
actions: read
pull-requests: write
steps:
- uses: fgrosse/go-coverage-report@v1.1.1
with:
coverage-artifact-name: "code-coverage"
coverage-file-name: "coverage.txt"
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23"
- uses: golangci/golangci-lint-action@v6
with:
version: latest
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23"
- name: Build all targets
run: |
GOOS=linux GOARCH=amd64 go build -o /dev/null .
GOOS=linux GOARCH=arm64 go build -o /dev/null .
GOOS=darwin GOARCH=amd64 go build -o /dev/null .
GOOS=darwin GOARCH=arm64 go build -o /dev/null .
GOOS=windows GOARCH=amd64 go build -o /dev/null .
GOOS=windows GOARCH=arm64 go build -o /dev/null .