-
Notifications
You must be signed in to change notification settings - Fork 18
131 lines (127 loc) · 4.04 KB
/
ci.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
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
name: ci
on:
push:
tags:
- "v*"
branches:
- main
pull_request:
schedule:
- cron: "30 10 * * 0"
jobs:
test-windows:
strategy:
matrix:
go-version:
- "1.21"
- "1.22"
- "^1"
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: mkdir gocoverdir
run: |
# mktemp -pd gocoverdir.XXXXXXXX
function New-TemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
do {
[string] $name = [System.Guid]::NewGuid()
$item = New-Item -Path $parent -Name $name -ItemType "directory" -ErrorAction SilentlyContinue
} while (-not $item)
return $item.FullName
}
$GOCOVERDIR = (New-TemporaryDirectory)
echo "GOCOVERDIR=$GOCOVERDIR" >>"$GITHUB_ENV"
- name: unit tests
run: |
$item = New-Item -Path $GOCOVERDIR -Name windows -ItemType "directory"
$GOCOVERDIR = $item.FullName
go test -v -cover -test.gocoverdir="$GOCOVERDIR" ./...
- name: upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
path: ${{ env.GOCOVERDIR }}
test-unix:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
go-version:
- "1.21"
- "1.22"
- "^1"
exclude:
# It seems MacOS 1.14 is no longer cached by actions/setup-go.
- os: macos-latest
go-version: "1.14"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: mkdir gocoverdir
run: |
GOCOVERDIR="$(mktemp -pd gocoverdir.XXXXXXXX)"
echo "GOCOVERDIR=$GOCOVERDIR" >>"$GITHUB_ENV"
- name: unit tests
run: |
GOCOVERDIR="$GOCOVERDIR/nonroot"
mkdir -p "$GOCOVERDIR"
go test -v -cover -test.gocoverdir="$GOCOVERDIR" ./...
- name: unit tests (root)
if: ${{ ! startsWith(matrix.os, 'windows-') }}
run: |
GOCOVERDIR="$GOCOVERDIR/root"
mkdir -p "$GOCOVERDIR"
sudo go test -v -cover -test.gocoverdir="$GOCOVERDIR" ./...
- name: upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
path: ${{ env.GOCOVERDIR }}
coverage:
runs-on: ubuntu-latest
needs:
- test-windows
- test-unix
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "^1"
- name: download all coverage
uses: actions/download-artifact@v4
with:
path: coverage
- name: generate coverage list
run: |
find coverage/
GOCOVERDIRS="$(printf '%s,' coverage/*/* | sed 's|,$||')"
echo "GOCOVERDIRS=$GOCOVERDIRS" >>"$GITHUB_ENV"
FULLCOVERAGE_FILE="$(mktemp fullcoverage.XXXXXXXX)"
echo "FULLCOVERAGE_FILE=$FULLCOVERAGE_FILE" >>"$GITHUB_ENV"
- name: compute coverage
run: go tool covdata percent -i "$GOCOVERDIRS"
- name: compute func coverage
run: go tool covdata func -i "$GOCOVERDIRS"
- name: merge coverage
run: |
go tool covdata textfmt -i "$GOCOVERDIRS" -o "$FULLCOVERAGE_FILE"
go tool cover -html="$FULLCOVERAGE_FILE" -o "$FULLCOVERAGE_FILE.html"
- name: upload merged coverage
uses: actions/upload-artifact@v4
with:
name: fullcoverage-${{ github.job }}
path: ${{ env.FULLCOVERAGE_FILE }}
- name: upload coverage html
uses: actions/upload-artifact@v4
with:
name: fullcoverage-${{ github.job }}.html
path: ${{ env.FULLCOVERAGE_FILE }}.html