Repository navigation
72 lines (68 loc) · 2.35 KB
/
Copy pathci.yml
File metadata and controls
72 lines (68 loc) · 2.35 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
name: ci
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: git version
run: git --version
- name: gofmt
run: test -z "$(gofmt -l .)" || (gofmt -l . && exit 1)
- name: vet
run: go vet ./...
- name: staticcheck
uses: dominikh/staticcheck-action@v1
with:
install-go: false
- name: test
run: go test -race ./...
- name: build
run: go build -o /dev/null ./cmd/gitident
# Publishes the coverage badge data (shields.io endpoint JSON) to the
# `badges` branch; README.md renders it. No third-party service involved.
coverage:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: measure
run: |
go test -coverpkg=./... -coverprofile=coverage.out ./...
pct=$(go tool cover -func=coverage.out | awk '/^total:/ { sub("%", "", $3); print $3 }')
color=$(awk -v p="$pct" 'BEGIN { print (p >= 90 ? "brightgreen" : p >= 80 ? "green" : p >= 70 ? "yellowgreen" : p >= 50 ? "yellow" : "red") }')
printf '{"schemaVersion":1,"label":"coverage","message":"%s%%","color":"%s"}\n' "$pct" "$color" > "$RUNNER_TEMP/coverage.json"
echo "Coverage: ${pct}%" >> "$GITHUB_STEP_SUMMARY"
- name: publish
run: |
dir="$RUNNER_TEMP/badges"
if git fetch --depth=1 origin badges; then
git worktree add -B badges "$dir" FETCH_HEAD
else
git worktree add --orphan -b badges "$dir"
fi
cp "$RUNNER_TEMP/coverage.json" "$dir/coverage.json"
cd "$dir"
git add coverage.json
if git diff --cached --quiet; then exit 0; fi
git -c user.name="github-actions[bot]" -c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
commit -q -m "Update coverage badge"
git push -q origin badges