77 branches : [main]
88
99jobs :
10- test-and-build :
10+ lint :
11+ name : Lint and Format Check
1112 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 }}
1257 permissions :
1358 contents : read
1459 pull-requests : write
1560
1661 steps :
1762 - uses : actions/checkout@v4
1863
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
2176 with :
22- go-version : " 1.23"
77+ path : ${{ steps.go-cache-paths.outputs.go-build }}
78+ key : ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
2379
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') }}
2685
27- - name : Run golangci-lint
28- uses : golangci/golangci-lint-action@v6
86+ - name : Cache downloaded test files
87+ uses : actions/cache@v4
2988 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-
3195
3296 - 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 ./...
36103
37104 - name : Calculate coverage
105+ if : matrix.os == 'ubuntu-latest'
38106 id : coverage
39107 run : |
40108 COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}')
41109 echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
42110 echo "Coverage: $COVERAGE"
43111
44112 - name : Get main branch coverage
45- if : github.event_name == 'pull_request'
113+ if : github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest'
46114 id : main-coverage
47115 run : |
48116 # Store current working directory
49117 CURRENT_DIR=$(pwd)
50-
118+
51119 # Fetch main branch
52120 git fetch origin main:main
53-
121+
54122 # Checkout main branch in a temporary directory
55123 git worktree add /tmp/main-branch main
56-
124+
57125 # Run tests on main branch to get coverage
58126 cd /tmp/main-branch
59127 go test -coverprofile=main-coverage.out -covermode=atomic ./... > /dev/null 2>&1 || echo "Main branch tests failed"
60-
128+
61129 if [ -f main-coverage.out ]; then
62130 MAIN_COVERAGE=$(go tool cover -func=main-coverage.out | grep total | awk '{print $3}' || echo "0.0%")
63131 echo "main-coverage=$MAIN_COVERAGE" >> $GITHUB_OUTPUT
@@ -69,23 +137,24 @@ jobs:
69137 echo "main-coverage=0.0%" >> $GITHUB_OUTPUT
70138 echo "Could not get main branch coverage"
71139 fi
72-
140+
73141 # Return to original directory
74142 cd "$CURRENT_DIR"
75-
143+
76144 # Clean up worktree (force removal to handle modified files)
77145 git worktree remove --force /tmp/main-branch || rm -rf /tmp/main-branch
78146
79147 - name : Generate coverage summary
148+ if : matrix.os == 'ubuntu-latest'
80149 id : coverage-summary
81150 run : |
82151 echo "## 📊 Test Coverage Report" > coverage-summary.md
83152 echo "" >> coverage-summary.md
84-
153+
85154 # Current coverage
86155 CURRENT_COV="${{ steps.coverage.outputs.coverage }}"
87156 echo "**Current Coverage:** \`$CURRENT_COV\`" >> coverage-summary.md
88-
157+
89158 # Compare with main if this is a PR
90159 if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ steps.main-coverage.outputs.main-coverage }}" != "" ]; then
91160 MAIN_COV="${{ steps.main-coverage.outputs.main-coverage }}"
@@ -109,7 +178,7 @@ jobs:
109178 fi
110179 fi
111180 fi
112-
181+
113182 echo "" >> coverage-summary.md
114183 echo "### Coverage by Package" >> coverage-summary.md
115184 echo "\`\`\`" >> coverage-summary.md
@@ -122,25 +191,25 @@ jobs:
122191 echo "_Generated by GitHub Actions_" >> coverage-summary.md
123192
124193 - name : Comment PR with coverage
125- if : github.event_name == 'pull_request'
194+ if : github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest'
126195 uses : actions/github-script@v7
127196 with :
128197 script : |
129198 const fs = require('fs');
130199 const coverageSummary = fs.readFileSync('coverage-summary.md', 'utf8');
131-
200+
132201 // Look for existing coverage comment
133202 const comments = await github.rest.issues.listComments({
134203 issue_number: context.issue.number,
135204 owner: context.repo.owner,
136205 repo: context.repo.repo,
137206 });
138-
207+
139208 const botComment = comments.data.find(comment =>
140209 comment.user.type === 'Bot' &&
141210 comment.body.includes('📊 Test Coverage Report')
142211 );
143-
212+
144213 if (botComment) {
145214 // Update existing comment
146215 await github.rest.issues.updateComment({
@@ -160,12 +229,34 @@ jobs:
160229 }
161230
162231 - name : Upload coverage artifact
232+ if : matrix.os == 'ubuntu-latest'
163233 uses : actions/upload-artifact@v4
164234 with :
165235 name : coverage-report
166236 path : |
167237 coverage.out
168238 coverage.html
169239
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'
171246 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