-
Notifications
You must be signed in to change notification settings - Fork 2
298 lines (251 loc) · 8.16 KB
/
Copy pathci.yml
File metadata and controls
298 lines (251 loc) · 8.16 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
name: CI
on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GO_VERSION: '1.23'
permissions:
contents: read
pull-requests: read
checks: write
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version: [1.21, 1.22, 1.23]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache: true
- name: Install dependencies
run: go mod download
- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.64.8
args: --timeout=5m --verbose --config=.golangci-v1.yml
only-new-issues: false
# Only run linter on latest Go version to avoid duplication
if: matrix.go-version == env.GO_VERSION
- name: Run tests
run: |
# Skip slow acceptance tests that require Terraform download
go test -short -race -coverprofile=coverage.out -covermode=atomic -timeout=60s ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
flags: unittests-go${{ matrix.go-version }}
name: codecov-go${{ matrix.go-version }}
fail_ci_if_error: false
# Only upload coverage for latest Go version
if: matrix.go-version == env.GO_VERSION
test-acceptance:
name: Acceptance Tests
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
env:
TF_ACC: 1
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install dependencies
run: go mod download
- name: Cache Terraform binary and plugins
uses: actions/cache@v4
with:
path: |
~/.terraform.d/plugins
~/.terraform.d/plugin-cache
key: terraform-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-${{ github.run_id }}
restore-keys: |
terraform-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-
terraform-${{ runner.os }}-
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ~1.0
terraform_wrapper: false
- name: Pre-cache Terraform for tests
run: |
# Create a temporary directory for pre-caching
mkdir -p /tmp/tf-cache
cd /tmp/tf-cache
# Create a minimal Terraform configuration to trigger download
cat > main.tf << 'EOF'
terraform {
required_providers {
extip = {
source = "petems/extip"
}
}
}
EOF
# Initialize to download and cache provider requirements
terraform init || true
# Also pre-download common Terraform versions that the SDK might use
export CHECKPOINT_DISABLE=1
export TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache
mkdir -p $TF_PLUGIN_CACHE_DIR
- name: Run acceptance tests
run: |
# Use cached Terraform and run acceptance tests with longer timeout
export CHECKPOINT_DISABLE=1
export TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache
TF_ACC=1 go test -race -timeout=10m ./extip/
- name: Run full test suite with coverage
run: |
# Run all tests including acceptance tests with extended timeout
export CHECKPOINT_DISABLE=1
export TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache
TF_ACC=1 go test -race -coverprofile=coverage.out -covermode=atomic -timeout=10m ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
flags: acceptance
name: codecov-acceptance
build:
name: Build
runs-on: ubuntu-latest
needs: [test]
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
ext: .exe
- goos: freebsd
goarch: amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
go build -v -ldflags="-s -w -X main.version=dev -X main.commit=${{ github.sha }}" \
-o terraform-provider-extip-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }} .
- name: Test binary
if: matrix.goos != 'windows'
run: |
chmod +x terraform-provider-extip-${{ matrix.goos }}-${{ matrix.goarch }}
./terraform-provider-extip-${{ matrix.goos }}-${{ matrix.goarch }} -version || echo "Version flag not supported yet"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: terraform-provider-extip-${{ matrix.goos }}-${{ matrix.goarch }}
path: terraform-provider-extip-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }}
retention-days: 7
security:
name: Security Scan
runs-on: ubuntu-latest
needs: [test]
permissions:
security-events: write
actions: read
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Cache gosec
uses: actions/cache@v4
with:
path: ~/go/bin/gosec
key: gosec-${{ runner.os }}-latest
- name: Install gosec
run: |
if [ ! -f ~/go/bin/gosec ]; then
go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest
fi
echo "$HOME/go/bin" >> $GITHUB_PATH
- name: Run Gosec Security Scanner
run: |
gosec -fmt sarif -out results.sarif ./...
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: results.sarif
- name: Cache govulncheck
uses: actions/cache@v4
with:
path: ~/go/bin/govulncheck
key: govulncheck-${{ runner.os }}-latest
- name: Install govulncheck
run: |
if [ ! -f ~/go/bin/govulncheck ]; then
go install golang.org/x/vuln/cmd/govulncheck@latest
fi
echo "$HOME/go/bin" >> $GITHUB_PATH
- name: Run govulncheck
run: |
govulncheck ./...
validate:
name: Validate
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Validate go.mod and go.sum
run: |
go mod verify
go mod tidy
git diff --exit-code go.mod go.sum
- name: Check formatting
run: make fmtcheck
- name: Run go vet
run: make vet
- name: Validate vendor directory
run: |
go mod vendor
git diff --exit-code vendor/ || (
echo "Vendor directory is out of sync. Run 'go mod vendor' and commit the changes."
exit 1
)