Skip to content

Commit f7ee651

Browse files
committed
ci, versioning, lint improvements
1 parent cde5cad commit f7ee651

File tree

11 files changed

+987
-157
lines changed

11 files changed

+987
-157
lines changed

.github/workflows/main.yml

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,65 @@ permissions:
2323
env:
2424
CI_COMMIT_AUTHOR: trvon
2525
CI_COMMIT_EMAIL: [email protected]
26+
GO_VERSION: '1.22'
2627

2728
jobs:
29+
lint:
30+
name: Lint
31+
runs-on: ubuntu-latest
32+
timeout-minutes: 10
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
37+
- name: Set up Go
38+
uses: actions/setup-go@v4
39+
with:
40+
go-version: ${{ env.GO_VERSION }}
41+
cache: true
42+
43+
- name: Run golangci-lint
44+
uses: golangci/golangci-lint-action@v6
45+
with:
46+
version: latest
47+
args: --timeout=5m
48+
49+
- name: Run go vet
50+
run: go vet ./...
51+
52+
- name: Check formatting
53+
run: |
54+
if [ -n "$(gofmt -s -l .)" ]; then
55+
echo "Go code is not formatted:"
56+
gofmt -s -d .
57+
exit 1
58+
fi
59+
60+
security:
61+
name: Security Checks
62+
runs-on: ubuntu-latest
63+
timeout-minutes: 10
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v4
67+
68+
- name: Set up Go
69+
uses: actions/setup-go@v4
70+
with:
71+
go-version: ${{ env.GO_VERSION }}
72+
cache: true
73+
74+
- name: Run govulncheck
75+
run: |
76+
go install golang.org/x/vuln/cmd/govulncheck@latest
77+
govulncheck ./...
78+
79+
- name: Run tests with race detector
80+
run: go test -race -short ./...
81+
2882
unit-tests:
2983
name: Unit Tests
84+
needs: [lint]
3085
runs-on: ubuntu-latest
3186
timeout-minutes: 15
3287
steps:
@@ -38,24 +93,33 @@ jobs:
3893
- name: Set up Go
3994
uses: actions/setup-go@v4
4095
with:
41-
go-version: '1.18'
96+
go-version: ${{ env.GO_VERSION }}
4297
cache: true
4398

4499
- name: Unit Tests
45100
run: |
46-
go test ./... -v -timeout=120s
101+
go test ./... -v -timeout=120s -coverprofile=coverage.out
47102
timeout-minutes: 5
48103

104+
- name: Upload coverage
105+
uses: codecov/codecov-action@v4
106+
if: always()
107+
with:
108+
files: ./coverage.out
109+
flags: unittests
110+
fail_ci_if_error: false
111+
49112
acceptance-tests:
50113
name: Acceptance Tests
114+
needs: [lint]
51115
runs-on: ubuntu-latest
52116
timeout-minutes: 20
53117
container:
54118
image: gns3/openvswitch:latest
55119
volumes:
56120
- /lib/modules:/lib/modules
57121
options: --cap-add=NET_ADMIN --privileged
58-
122+
59123
steps:
60124
- name: Install dependencies
61125
run: |
@@ -67,15 +131,15 @@ jobs:
67131
uses: actions/checkout@v4
68132
with:
69133
fetch-depth: 0
70-
134+
71135
- name: Verify and setup Go
72136
run: |
73137
echo "Go binary location: $(which go)"
74138
go version
75139
echo "GOPATH: $GOPATH"
76140
# Make sure Go binaries are in PATH
77141
echo "PATH=$PATH:/usr/local/go/bin:$(go env GOPATH)/bin" >> $GITHUB_ENV
78-
142+
79143
- name: Start Open vSwitch service
80144
run: |
81145
/usr/share/openvswitch/scripts/ovs-ctl start
@@ -91,15 +155,19 @@ jobs:
91155

92156
integration-tests:
93157
name: Integration Tests
94-
needs: [unit-tests, acceptance-tests]
158+
needs: [unit-tests, acceptance-tests, security]
95159
runs-on: ubuntu-latest
96160
timeout-minutes: 30
161+
strategy:
162+
matrix:
163+
terraform_version: ['1.6.0', '1.10.5']
164+
opentofu_version: ['1.6.0', '1.8.10']
97165
container:
98166
image: gns3/openvswitch:latest
99167
volumes:
100168
- /lib/modules:/lib/modules
101169
options: --cap-add=NET_ADMIN --privileged
102-
170+
103171
steps:
104172
- name: Install dependencies
105173
run: |
@@ -131,8 +199,8 @@ jobs:
131199

132200
- name: Install Terraform
133201
run: |
134-
wget https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip
135-
unzip terraform_1.6.0_linux_amd64.zip
202+
wget https://releases.hashicorp.com/terraform/${{ matrix.terraform_version }}/terraform_${{ matrix.terraform_version }}_linux_amd64.zip
203+
unzip terraform_${{ matrix.terraform_version }}_linux_amd64.zip
136204
mv terraform /usr/local/bin/
137205
terraform version
138206
timeout-minutes: 5
@@ -155,9 +223,10 @@ jobs:
155223

156224
- name: Install OpenTofu
157225
run: |
158-
wget https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_linux_amd64.zip
159-
unzip -o tofu_1.6.0_linux_amd64.zip
226+
wget https://github.com/opentofu/opentofu/releases/download/v${{ matrix.opentofu_version }}/tofu_${{ matrix.opentofu_version }}_linux_amd64.zip
227+
unzip -o tofu_${{ matrix.opentofu_version }}_linux_amd64.zip
160228
mv tofu /usr/local/bin/
229+
tofu version
161230
timeout-minutes: 5
162231

163232
- name: Test with OpenTofu
@@ -209,21 +278,21 @@ jobs:
209278
- name: Set up Go
210279
uses: actions/setup-go@v4
211280
with:
212-
go-version: '1.18'
281+
go-version: ${{ env.GO_VERSION }}
213282
cache: true
214283

215284
- name: 'Terraform Provider Release'
216285
uses: hashicorp/ghaction-terraform-provider-release/.github/workflows/community.yml@v4
217286
with:
218287
gpg-private-key: '${{ secrets.GPG_PRIVATE_KEY }}'
219288
setup-go-version-file: 'go.mod'
220-
289+
221290
- name: Generate Release Notes
222291
run: |
223292
cd .changes
224293
sed -e "1{/# /d;}" -e "2{/^$/d;}" ${{ steps.version.outputs.CHANGELOG_VERSION }}.md > /tmp/release-notes.txt
225294
timeout-minutes: 2
226-
295+
227296
- name: GH Release
228297
run: |
229298
gh release create "${{ github.event.inputs.versionNumber }}" --notes-file /tmp/release-notes.txt --title "${{ github.event.inputs.versionNumber }}"

.golangci.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
# golangci-lint configuration for Terraform Provider
3+
# See https://golangci-lint.run/usage/configuration/ for all options
4+
5+
run:
6+
timeout: 5m
7+
tests: true
8+
# Define which Go version to target for linting
9+
go: '1.22'
10+
11+
output:
12+
# Format output
13+
formats:
14+
- format: colored-line-number
15+
# Print lines of code with issue
16+
print-issued-lines: true
17+
# Print linter name in the end of issue text
18+
print-linter-name: true
19+
# Sort results by file, line, and column
20+
sort-results: true
21+
22+
linters:
23+
enable:
24+
# Default linters
25+
- errcheck # Check for unchecked errors
26+
- gosimple # Simplify code
27+
- govet # Vet examines Go source code
28+
- ineffassign # Detect ineffectual assignments
29+
- staticcheck # Go static analysis
30+
- unused # Check for unused code
31+
32+
# Additional recommended linters
33+
- gofmt # Check if code was gofmt-ed
34+
- goimports # Check import statements formatting
35+
- misspell # Find commonly misspelled English words
36+
- revive # Fast, configurable, extensible, flexible linter
37+
- gosec # Inspect source code for security problems
38+
- unconvert # Remove unnecessary type conversions
39+
- unparam # Report unused function parameters
40+
- prealloc # Find slice declarations that could be preallocated
41+
- nolintlint # Report ill-formed or insufficient nolint directives
42+
- copyloopvar # Check for loop variables captured by func literals (replaces exportloopref)
43+
- gocritic # Comprehensive Go source code linter
44+
- gocyclo # Compute cyclomatic complexity
45+
- bodyclose # Check HTTP response body is closed
46+
- errorlint # Find code that will cause problems with Go 1.13+ error wrapping
47+
48+
disable:
49+
- typecheck # Disabled because it can conflict with Go build
50+
51+
linters-settings:
52+
errcheck:
53+
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`
54+
check-type-assertions: true
55+
# Report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`
56+
check-blank: false
57+
# Exclude functions - these are known to return errors we intentionally ignore
58+
exclude-functions:
59+
- '(*database/sql.DB).Close'
60+
- '(*database/sql.Rows).Close'
61+
62+
gocyclo:
63+
# Minimal cyclomatic complexity to report
64+
min-complexity: 15
65+
66+
govet:
67+
# Enable all analyzers
68+
enable-all: true
69+
# Disable specific analyzers
70+
disable:
71+
- shadow # Can be too noisy
72+
73+
misspell:
74+
locale: US
75+
ignore-words:
76+
- ovs
77+
- vsctl
78+
- ofctl
79+
- openvswitch
80+
81+
gosec:
82+
# Exclude specific security checks
83+
excludes:
84+
- G204 # Subprocess launched with variable - we need this for ovs-vsctl commands
85+
- G304 # File path provided as taint input
86+
# Confidence level to report issues
87+
confidence: medium
88+
89+
revive:
90+
rules:
91+
- name: exported
92+
disabled: false
93+
arguments:
94+
- "disableStutteringCheck"
95+
- name: package-comments
96+
disabled: true # Not all packages need comments in small projects
97+
98+
gocritic:
99+
enabled-tags:
100+
- diagnostic
101+
- style
102+
- performance
103+
disabled-checks:
104+
- commentedOutCode
105+
- whyNoLint
106+
107+
staticcheck:
108+
# https://staticcheck.io/docs/options#checks
109+
checks:
110+
- "all"
111+
- "-SA1019" # Allow deprecated functions temporarily during migration
112+
113+
issues:
114+
# Maximum issues count per one linter
115+
max-issues-per-linter: 0
116+
# Maximum count of issues with the same text
117+
max-same-issues: 0
118+
119+
# Show all issues from a linter
120+
new: false
121+
122+
# Make issues output unique by line
123+
uniq-by-line: true
124+
125+
# Exclude specific issues
126+
exclude-rules:
127+
# Exclude some linters from running on tests files
128+
- path: _test\.go
129+
linters:
130+
- gosec
131+
- errcheck
132+
- gocritic
133+
134+
# Exclude known issues in legacy code that will be fixed during SDK migration
135+
- path: openvswitch/
136+
text: "SA1019" # Deprecated function usage (terraform v0.12 SDK)
137+
linters:
138+
- staticcheck
139+
140+
# Allow complex functions in test files
141+
- path: _test\.go
142+
linters:
143+
- gocyclo
144+
145+
# Independently of option `exclude` we use default exclude patterns
146+
exclude-use-default: true

.travis.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)