-
Notifications
You must be signed in to change notification settings - Fork 1
225 lines (191 loc) · 5.6 KB
/
Copy pathci.yml
File metadata and controls
225 lines (191 loc) · 5.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# Continuous Integration Workflow
# Runs tests, linting, and build checks on code changes
# Optimized to skip jobs when only irrelevant files change
name: CI
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
workflow_dispatch:
inputs:
debug:
description: 'Enable debug logging'
required: false
default: 'false'
type: boolean
# Cancel in-progress runs for the same branch
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
GO_VERSION_FILE: go.mod
GOWORK: off
jobs:
detect-changes:
name: Detect Changes
runs-on: ubuntu-latest
timeout-minutes: 2
outputs:
go-changed: ${{ steps.changes.outputs.go }}
proto-changed: ${{ steps.changes.outputs.proto }}
ci-changed: ${{ steps.changes.outputs.ci }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect file changes
id: changes
uses: dorny/paths-filter@v3
with:
filters: |
go:
- '**/*.go'
- 'go.mod'
- 'go.sum'
- 'Makefile'
proto:
- 'api/proto/**'
- 'buf.yaml'
- 'buf.gen.yaml'
ci:
- '.github/workflows/ci.yml'
- '.golangci.yml'
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 10
needs: detect-changes
if: |
needs.detect-changes.outputs.go-changed == 'true' ||
needs.detect-changes.outputs.ci-changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: ${{ env.GO_VERSION_FILE }}
cache: true
- name: Download dependencies
run: go mod download
- name: Build
run: go build -o /dev/null ./...
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 15
needs: detect-changes
if: |
needs.detect-changes.outputs.go-changed == 'true' ||
needs.detect-changes.outputs.ci-changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: ${{ env.GO_VERSION_FILE }}
cache: true
- name: Download dependencies
run: go mod download
- name: Run tests with race detection
run: go test -p 1 -race -v ./...
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 10
needs: detect-changes
if: |
needs.detect-changes.outputs.go-changed == 'true' ||
needs.detect-changes.outputs.ci-changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: ${{ env.GO_VERSION_FILE }}
cache: true
- name: Download dependencies
run: go mod download
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: latest
skip-cache: true
args: --timeout=5m
proto:
name: Proto
runs-on: ubuntu-latest
timeout-minutes: 10
needs: detect-changes
if: |
needs.detect-changes.outputs.proto-changed == 'true' ||
needs.detect-changes.outputs.ci-changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: ${{ env.GO_VERSION_FILE }}
cache: true
- name: Setup Buf
uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Lint protos
run: buf lint
- name: Check for breaking changes
if: github.event_name == 'pull_request'
env:
BASE_REF: ${{ github.base_ref }}
run: |
git fetch origin $BASE_REF:$BASE_REF
buf breaking --against ".git#branch=${BASE_REF}"
- name: Verify generated code is up-to-date
run: |
buf generate
if [ -n "$(git status --porcelain api/proto/gen)" ]; then
echo "::error::Generated proto code is out of date. Run 'make proto' and commit."
git diff api/proto/gen
exit 1
fi
ci-complete:
name: CI Complete
runs-on: ubuntu-latest
needs: [detect-changes, build, test, lint, proto]
if: always()
steps:
- name: Check results
env:
CHANGES_RESULT: ${{ needs.detect-changes.result }}
BUILD_RESULT: ${{ needs.build.result }}
TEST_RESULT: ${{ needs.test.result }}
LINT_RESULT: ${{ needs.lint.result }}
PROTO_RESULT: ${{ needs.proto.result }}
run: |
echo "Detection: $CHANGES_RESULT"
echo "Build: $BUILD_RESULT"
echo "Test: $TEST_RESULT"
echo "Lint: $LINT_RESULT"
echo "Proto: $PROTO_RESULT"
# Fail if detection failed
if [ "$CHANGES_RESULT" == "failure" ]; then
echo "::error::Change detection failed"
exit 1
fi
# Check each job - 'skipped' is acceptable, 'failure' is not
for result in "$BUILD_RESULT" "$TEST_RESULT" "$LINT_RESULT" "$PROTO_RESULT"; do
if [ "$result" == "failure" ]; then
echo "::error::CI failed"
exit 1
fi
done
echo "✅ CI passed (some jobs may have been skipped based on changes)"