7
7
branches : [main]
8
8
9
9
jobs :
10
- test-and-build :
10
+ lint :
11
+ name : Lint and Format Check
11
12
runs-on : ubuntu-latest
13
+ steps :
14
+ - uses : actions/checkout@v4
15
+
16
+ - name : Install mise
17
+ uses : jdx/mise-action@v2
18
+
19
+ - name : Get Go cache paths
20
+ id : go-cache-paths
21
+ shell : bash
22
+ run : |
23
+ echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
24
+ echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
25
+
26
+ - name : Cache Go Build Cache
27
+ uses : actions/cache@v4
28
+ with :
29
+ path : ${{ steps.go-cache-paths.outputs.go-build }}
30
+ key : ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
31
+
32
+ - name : Cache Go Mod Cache
33
+ uses : actions/cache@v4
34
+ with :
35
+ path : ${{ steps.go-cache-paths.outputs.go-mod }}
36
+ key : ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
37
+
38
+ - name : Check code formatting
39
+ run : mise run fmt-check
40
+
41
+ - name : Check module dependencies
42
+ run : mise run mod-check
43
+
44
+ - name : Run lint task
45
+ run : mise run lint
46
+
47
+ - name : Check examples are up to date
48
+ run : mise run examples-check
49
+
50
+ test-and-build :
51
+ name : Test and Build
52
+ needs : lint
53
+ strategy :
54
+ matrix :
55
+ os : [ubuntu-latest, windows-latest]
56
+ runs-on : ${{ matrix.os }}
12
57
permissions :
13
58
contents : read
14
59
pull-requests : write
15
60
16
61
steps :
17
62
- uses : actions/checkout@v4
18
63
19
- - name : Set up Go
20
- uses : actions/setup-go@v5
64
+ - name : Install mise
65
+ uses : jdx/mise-action@v2
66
+
67
+ - name : Get Go cache paths
68
+ id : go-cache-paths
69
+ shell : bash
70
+ run : |
71
+ echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
72
+ echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
73
+
74
+ - name : Cache Go Build Cache
75
+ uses : actions/cache@v4
21
76
with :
22
- go-version : " 1.23"
77
+ path : ${{ steps.go-cache-paths.outputs.go-build }}
78
+ key : ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
23
79
24
- - name : Install dependencies
25
- run : go mod download
80
+ - name : Cache Go Mod Cache
81
+ uses : actions/cache@v4
82
+ with :
83
+ path : ${{ steps.go-cache-paths.outputs.go-mod }}
84
+ key : ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
26
85
27
- - name : Run golangci-lint
28
- uses : golangci/golangci-lint-action@v6
86
+ - name : Cache downloaded test files
87
+ uses : actions/cache@v4
29
88
with :
30
- version : latest
89
+ path : |
90
+ ~/tmp/speakeasy-api_arazzo
91
+ ${{ runner.temp }}/speakeasy-api_arazzo
92
+ key : arazzo-test-files-${{ hashFiles('arazzo/arazzo_test.go') }}
93
+ restore-keys : |
94
+ arazzo-test-files-
31
95
32
96
- name : Run tests with coverage
33
- run : |
34
- go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
35
- go tool cover -html=coverage.out -o coverage.html
97
+ if : matrix.os == 'ubuntu-latest'
98
+ run : mise run test-coverage
99
+
100
+ - name : Run tests (Windows)
101
+ if : matrix.os == 'windows-latest'
102
+ run : gotestsum --format testname -- -race ./...
36
103
37
104
- name : Calculate coverage
105
+ if : matrix.os == 'ubuntu-latest'
38
106
id : coverage
39
107
run : |
40
108
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}')
41
109
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
42
110
echo "Coverage: $COVERAGE"
43
111
44
112
- name : Get main branch coverage
45
- if : github.event_name == 'pull_request'
113
+ if : github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest'
46
114
id : main-coverage
47
115
run : |
48
116
# Store current working directory
49
117
CURRENT_DIR=$(pwd)
50
-
118
+
51
119
# Fetch main branch
52
120
git fetch origin main:main
53
-
121
+
54
122
# Checkout main branch in a temporary directory
55
123
git worktree add /tmp/main-branch main
56
-
124
+
57
125
# Run tests on main branch to get coverage
58
126
cd /tmp/main-branch
59
127
go test -coverprofile=main-coverage.out -covermode=atomic ./... > /dev/null 2>&1 || echo "Main branch tests failed"
60
-
128
+
61
129
if [ -f main-coverage.out ]; then
62
130
MAIN_COVERAGE=$(go tool cover -func=main-coverage.out | grep total | awk '{print $3}' || echo "0.0%")
63
131
echo "main-coverage=$MAIN_COVERAGE" >> $GITHUB_OUTPUT
@@ -69,23 +137,24 @@ jobs:
69
137
echo "main-coverage=0.0%" >> $GITHUB_OUTPUT
70
138
echo "Could not get main branch coverage"
71
139
fi
72
-
140
+
73
141
# Return to original directory
74
142
cd "$CURRENT_DIR"
75
-
143
+
76
144
# Clean up worktree (force removal to handle modified files)
77
145
git worktree remove --force /tmp/main-branch || rm -rf /tmp/main-branch
78
146
79
147
- name : Generate coverage summary
148
+ if : matrix.os == 'ubuntu-latest'
80
149
id : coverage-summary
81
150
run : |
82
151
echo "## 📊 Test Coverage Report" > coverage-summary.md
83
152
echo "" >> coverage-summary.md
84
-
153
+
85
154
# Current coverage
86
155
CURRENT_COV="${{ steps.coverage.outputs.coverage }}"
87
156
echo "**Current Coverage:** \`$CURRENT_COV\`" >> coverage-summary.md
88
-
157
+
89
158
# Compare with main if this is a PR
90
159
if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ steps.main-coverage.outputs.main-coverage }}" != "" ]; then
91
160
MAIN_COV="${{ steps.main-coverage.outputs.main-coverage }}"
@@ -109,7 +178,7 @@ jobs:
109
178
fi
110
179
fi
111
180
fi
112
-
181
+
113
182
echo "" >> coverage-summary.md
114
183
echo "### Coverage by Package" >> coverage-summary.md
115
184
echo "\`\`\`" >> coverage-summary.md
@@ -122,25 +191,25 @@ jobs:
122
191
echo "_Generated by GitHub Actions_" >> coverage-summary.md
123
192
124
193
- name : Comment PR with coverage
125
- if : github.event_name == 'pull_request'
194
+ if : github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest'
126
195
uses : actions/github-script@v7
127
196
with :
128
197
script : |
129
198
const fs = require('fs');
130
199
const coverageSummary = fs.readFileSync('coverage-summary.md', 'utf8');
131
-
200
+
132
201
// Look for existing coverage comment
133
202
const comments = await github.rest.issues.listComments({
134
203
issue_number: context.issue.number,
135
204
owner: context.repo.owner,
136
205
repo: context.repo.repo,
137
206
});
138
-
207
+
139
208
const botComment = comments.data.find(comment =>
140
209
comment.user.type === 'Bot' &&
141
210
comment.body.includes('📊 Test Coverage Report')
142
211
);
143
-
212
+
144
213
if (botComment) {
145
214
// Update existing comment
146
215
await github.rest.issues.updateComment({
@@ -160,12 +229,34 @@ jobs:
160
229
}
161
230
162
231
- name : Upload coverage artifact
232
+ if : matrix.os == 'ubuntu-latest'
163
233
uses : actions/upload-artifact@v4
164
234
with :
165
235
name : coverage-report
166
236
path : |
167
237
coverage.out
168
238
coverage.html
169
239
170
- - name : Build
240
+ - name : Build (Ubuntu)
241
+ if : matrix.os == 'ubuntu-latest'
242
+ run : mise run build
243
+
244
+ - name : Build (Windows)
245
+ if : matrix.os == 'windows-latest'
171
246
run : go build -v ./...
247
+
248
+ # Summary job that depends on all matrix jobs
249
+ # This provides a single status check for branch protection
250
+ test-summary :
251
+ name : Test Summary
252
+ needs : [lint, test-and-build]
253
+ runs-on : ubuntu-latest
254
+ if : always()
255
+ steps :
256
+ - name : Check test results
257
+ run : |
258
+ if [ "${{ needs.test-and-build.result }}" != "success" ]; then
259
+ echo "Tests failed or were cancelled"
260
+ exit 1
261
+ fi
262
+ echo "All tests passed successfully"
0 commit comments