Skip to content

Commit e5e2328

Browse files
committed
lint: Move test running into CI.
1 parent 480862d commit e5e2328

File tree

4 files changed

+139
-40
lines changed

4 files changed

+139
-40
lines changed

.github/workflows/go-dep-submission.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ on:
55
branches:
66
- main
77

8-
# The API requires write permission on the repository to submit dependencies
98
permissions:
10-
contents: write
9+
contents: read
1110

1211
jobs:
1312
go-action-detection:
1413
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
1516
steps:
1617
- name: Harden Runner
1718
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0

.github/workflows/test.yml

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
# This workflow uses actions that are not certified by GitHub. They are provided
3+
# by a third-party and are governed by separate terms of service, privacy
4+
# policy, and support documentation.
5+
6+
name: Tests
7+
on:
8+
push:
9+
branches:
10+
- main
11+
pull_request:
12+
branches:
13+
- main
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
examples:
20+
runs-on: ubuntu-latest
21+
name: Examples
22+
steps:
23+
- name: Harden Runner
24+
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
25+
with:
26+
egress-policy: audit
27+
28+
- name: Checkout Source
29+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Install Go
34+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
35+
with:
36+
go-version: '>= 1.21'
37+
cache: true
38+
39+
- name: Run example tests
40+
run: |
41+
make examples
42+
43+
unit:
44+
runs-on: ubuntu-latest
45+
name: Unit
46+
steps:
47+
- name: Harden Runner
48+
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
49+
with:
50+
egress-policy: audit
51+
52+
- name: Checkout Source
53+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
54+
with:
55+
fetch-depth: 0
56+
57+
- name: Install Go
58+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
59+
with:
60+
go-version: '>= 1.21'
61+
cache: true
62+
63+
- name: Run unit tests
64+
run: |
65+
make unit
66+
67+
acc:
68+
runs-on: ubuntu-latest
69+
name: Acceptance (${{ matrix.terraform_version }})
70+
71+
strategy:
72+
fail-fast: false
73+
matrix:
74+
terraform_version:
75+
- '1.1'
76+
- '1.2'
77+
- '1.3'
78+
- '1.4'
79+
- '1.5'
80+
- '1.6'
81+
82+
steps:
83+
- name: Harden Runner
84+
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
85+
with:
86+
egress-policy: audit
87+
88+
- name: Checkout Source
89+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
90+
with:
91+
fetch-depth: 0
92+
93+
- name: Install Go
94+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
95+
with:
96+
go-version: '>= 1.21'
97+
cache: true
98+
99+
- name: Install Terraform
100+
uses: hashicorp/setup-terraform@v2
101+
with:
102+
terraform_version: ${{ matrix.terraform_version }}
103+
terraform_wrapper: false
104+
105+
- name: Run acceptance tests
106+
run: |
107+
make acc

.pre-commit-config.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ repos:
9797
language: system
9898
stages: [commit, push]
9999

100+
- id: actionlint
101+
name: Actionlint
102+
description: Lint GitHub Actions workflows
103+
entry: bash -c 'actionlint'
104+
language: system
105+
stages: [commit, push]
106+
100107
- id: unconvert
101108
name: 'Go: unconvert (current GOOS/GOARCH)'
102109
description: Analyzes Go packages to identify unnecessary type conversions.
@@ -110,3 +117,17 @@ repos:
110117
entry: bash -c 'smrcptr -skip-std=true --constructor=true ./...'
111118
language: system
112119
stages: [commit, push]
120+
121+
- id: govulncheck
122+
name: 'Go: Vulnerability check'
123+
description: Check for Go security vulnerabilities. (https://go.dev/blog/vuln)
124+
entry: bash -c 'govulncheck -test ./...'
125+
language: system
126+
stages: [commit, push]
127+
128+
- id: osvscanner
129+
name: OSV Scanner
130+
description: Check for security vulnerabilities. (https://osv.dev)
131+
entry: bash -c 'osv-scanner -r .'
132+
language: system
133+
stages: [commit, push]

Makefile

+8-38
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ current_dir := $(dir $(mkfile_path))
1111
# Global stuff.
1212

1313
GO=$(shell which go)
14-
HOMEBREW_PACKAGES=bash bats-core coreutils findutils git git-lfs go grep jq librsvg nodejs pre-commit python@3.11 tfschema trufflesecurity/trufflehog/trufflehog
14+
HOMEBREW_PACKAGES=bash bats-core coreutils findutils git git-lfs go grep jq librsvg nodejs pre-commit python@3.11 shellcheck tfschema trufflesecurity/trufflehog/trufflehog
1515

1616
# Determine the operating system and CPU arch.
1717
OS=$(shell uname -o | tr '[:upper:]' '[:lower:]')
@@ -66,6 +66,7 @@ install-tools-go:
6666
$(GO) install github.com/nikolaydubina/go-cover-treemap@latest
6767
$(GO) install github.com/orlangure/gocovsh@latest
6868
$(GO) install github.com/pelletier/go-toml/v2/cmd/tomljson@latest
69+
$(GO) install github.com/rhysd/actionlint/cmd/actionlint@latest
6970
$(GO) install github.com/securego/gosec/v2/cmd/gosec@latest
7071
$(GO) install github.com/trufflesecurity/driftwood@latest
7172
$(GO) install golang.org/x/perf/cmd/benchstat@latest
@@ -210,32 +211,6 @@ binsize:
210211
#-------------------------------------------------------------------------------
211212
# Linting
212213

213-
.PHONY: vuln
214-
## vuln: [lint]* Checks for known security vulnerabilities.
215-
vuln:
216-
@ $(ECHO) " "
217-
@ $(ECHO) "\033[1;33m=====> Running govulncheck (https://go.dev/blog/vuln)...\033[0m"
218-
govulncheck ./...
219-
220-
@ $(ECHO) " "
221-
@ $(ECHO) "\033[1;33m=====> Running govulncheck -test (https://go.dev/blog/vuln)...\033[0m"
222-
govulncheck -test ./...
223-
224-
@ $(ECHO) " "
225-
@ $(ECHO) "\033[1;33m=====> Running osv-scanner (https://osv.dev)...\033[0m"
226-
osv-scanner -r .
227-
228-
@ $(ECHO) " "
229-
@ $(ECHO) "\033[1;33m=====> Running gosec (https://github.com/securego/gosec)...\033[0m"
230-
gosec -terse -tests ./...
231-
232-
.PHONY: secrets
233-
## secrets: [lint]* Checks for verifiable secrets.
234-
secrets:
235-
@ $(ECHO) " "
236-
@ $(ECHO) "\033[1;33m=====> Running TruffleHog...\033[0m"
237-
trufflehog git file://. --json --only-verified --concurrency=$(nproc) 2>/dev/null | jq '.'
238-
239214
.PHONY: pre-commit
240215
## pre-commit: [lint]* Runs `pre-commit` against all files.
241216
pre-commit:
@@ -265,16 +240,9 @@ license:
265240
@ - licensei header
266241
@ $(ECHO) " "
267242

268-
.PHONY: unconvert
269-
## unconvert: [lint]* Identify unnecessary type conversions. All GOOS/GOARCH matches.
270-
unconvert:
271-
@ $(ECHO) " "
272-
@ $(ECHO) "\033[1;33m=====> Running unconvert (all GOOS/GOARCH)...\033[0m"
273-
unconvert -all -fastmath -tests -v ./...
274-
275243
.PHONY: lint
276244
## lint: [lint]* Runs ALL linting/validation tasks.
277-
lint: vuln license unconvert pre-commit
245+
lint: license pre-commit
278246

279247
#-------------------------------------------------------------------------------
280248
# Testing
@@ -307,7 +275,7 @@ list-tests:
307275

308276
@ $(ECHO) " "
309277
@ $(ECHO) "\033[1;33m=====> Fuzzing tests...\033[0m"
310-
@ cat ./corefunc/*_test.go | ggrep "func Fuzz" | gsed 's/func\s//g' | gsed -r 's/\(.*//g' | gsed -r 's/Fuzz/make fuzz NAME=/g'
278+
@ $(ECHO) "make fuzz"
311279

312280
@ $(ECHO) " "
313281
@ $(ECHO) "\033[1;33m=====> BATS tests...\033[0m"
@@ -358,11 +326,13 @@ examples:
358326
gotestsum --format testname -- -run=Example$(NAME) -count=1 -parallel=$(shell nproc) -timeout 30s -coverpkg=./corefunc/... -coverprofile=__coverage.out -v ./corefunc/...
359327

360328
.PHONY: fuzz
361-
## fuzz: [test]* Runs the fuzzer for 10 minutes. Set NAME= (without 'Fuzz') to run a specific test by name
329+
## fuzz: [test]* Runs the fuzzer for 1 minute per test.
362330
fuzz:
363331
@ $(ECHO) " "
364332
@ $(ECHO) "\033[1;33m=====> Running the fuzzer (https://go.dev/doc/tutorial/fuzz)...\033[0m"
365-
$(GO) test -run='^$$' -fuzz=Fuzz$(NAME) -fuzztime 10m -parallel=$(shell nproc) -v ./corefunc/...
333+
$(GO) test -run='^$$' -fuzz=FuzzEnvEnsure -fuzztime 1m -v ./corefunc
334+
$(GO) test -run='^$$' -fuzz=FuzzStrIterativeReplace -fuzztime 1m -v ./corefunc
335+
$(GO) test -run='^$$' -fuzz=FuzzTruncateLabel -fuzztime 1m -v ./corefunc
366336

367337
.PHONY: quickbench
368338
## quickbench: [test]* Runs the benchmarks with minimal data for a quick check

0 commit comments

Comments
 (0)