Skip to content

Commit c649dd2

Browse files
authored
Merge pull request #133 from grafana/shared-workflows
Shared workflows
2 parents afa43ea + e7abd07 commit c649dd2

File tree

14 files changed

+212
-197
lines changed

14 files changed

+212
-197
lines changed

.devcontainer/devcontainer.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@
2222
"features": {
2323
"ghcr.io/devcontainers/features/github-cli:1": {},
2424
"ghcr.io/devcontainers/features/go:1": {
25-
"version": "1.23",
26-
"golangciLintVersion": "1.63.4"
25+
"version": "1.24",
26+
"golangciLintVersion": "2.1.6"
27+
},
28+
"ghcr.io/guiyomh/features/goreleaser:0": { "version": "2.9.0" },
29+
"ghcr.io/michidk/devcontainers-features/bun:1": { "version": "1.2.12" },
30+
"ghcr.io/szkiba/devcontainer-features/gosec:1": { "version": "2.22.4" },
31+
"ghcr.io/szkiba/devcontainer-features/govulncheck:1": {
32+
"version": "1.1.4"
2733
},
28-
"ghcr.io/guiyomh/features/goreleaser:0": { "version": "2.6.1" },
29-
"ghcr.io/michidk/devcontainers-features/bun:1": { "version": "1.2.1" },
3034
"ghcr.io/szkiba/devcontainer-features/cdo:1": { "version": "0.1.2" },
3135
"ghcr.io/szkiba/devcontainer-features/mdcode:1": { "version": "0.2.0" },
3236
"ghcr.io/szkiba/devcontainer-features/bats:1": { "version": "1.11.1" },
33-
"ghcr.io/grafana/devcontainer-features/xk6:1": { "version": "0.14.0" }
37+
"ghcr.io/grafana/devcontainer-features/xk6:1": { "version": "0.19.2" }
3438
},
3539

3640
"remoteEnv": {
3741
"GH_TOKEN": "${localEnv:GH_TOKEN}",
38-
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}"
42+
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}",
43+
"XK6_EARLY_ACCESS": "true"
3944
}
4045
}

.github/workflows/release.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ permissions: {}
99
jobs:
1010
release:
1111
name: Release
12-
uses: grafana/k6-extension-workflows/.github/workflows/release.yml@v0.2.1
12+
uses: grafana/xk6/.github/workflows/extension-release.yml@v0.19.2
1313
with:
1414
cgo: true
15+
go-version: ${{vars.GO_VERSION}}
16+
k6-version: ${{vars.K6_VERSION}}
17+
xk6-version: ${{vars.XK6_VERSION}}
18+
os: ${{vars.OS}}
19+
arch: ${{vars.ARCH}}
1520
with: |
1621
github.com/grafana/xk6-sql-driver-ramsql
1722
github.com/grafana/xk6-sql-driver-sqlite3

.github/workflows/validate.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
name: Validate
22

3+
permissions: {}
4+
35
on:
46
workflow_dispatch:
57
push:
68
branches: ["main", "master"]
79
pull_request:
810
branches: ["main", "master"]
911

10-
permissions: {}
11-
1212
jobs:
1313
validate:
1414
name: Validate
15-
uses: grafana/k6-extension-workflows/.github/workflows/validate.yml@v0.2.1
15+
uses: grafana/xk6/.github/workflows/extension-validate.yml@v0.19.2
16+
permissions:
17+
pages: write
18+
id-token: write
19+
with:
20+
go-version: ${{vars.GO_VERSION}}
21+
go-versions: ${{vars.GO_VERSIONS}}
22+
golangci-lint-version: ${{vars.GOLANGCI_LINT_VERSION}}
23+
platforms: ${{vars.PLATFORMS}}
24+
k6-versions: ${{vars.K6_VERSIONS}}
25+
xk6-version: ${{vars.XK6_VERSION}}

.golangci.yml

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
1-
# v1.63.4
2-
# Please don't remove the first line. This is a must until the reusable GitHub workflow is refactored.
3-
4-
issues:
5-
max-issues-per-linter: 0
6-
max-same-issues: 0
7-
exclude-use-default: false
8-
1+
version: "2"
92
linters:
10-
enable-all: true
3+
default: all
114
disable:
12-
- wrapcheck
13-
- varnamelen
14-
- exhaustruct
15-
- exportloopref
5+
# k6 extensions must be registered from the init() function.
166
- gochecknoinits
7+
8+
# The constructor of k6 extensions must return an interface.
179
- ireturn
1810

19-
linters-settings:
20-
depguard:
21-
rules:
22-
prevent_accidental_imports:
23-
allow:
24-
- $gostd
25-
- github.com/brianvoe/gofakeit/v6
26-
- github.com/stretchr/testify/require
27-
- github.com/grafana/sobek
28-
- github.com/grafana/k6
29-
- github.com/grafana/xk6-sql
30-
- github.com/proullon/ramsql/driver
11+
# In many cases (e.g. options) it is normal usage not to specify all structure fields.
12+
- exhaustruct
13+
14+
# Many go standard library API functions have typical parameter names shorter than 3 characters.
15+
# It is better to use the usual parameter names than to create one that conforms to the rule.
16+
- varnamelen
17+
18+
# Except for general-purpose public APIs,
19+
# wrapping errors is more inconvenient and error prone than useful.
20+
- wrapcheck
21+
settings:
22+
depguard:
23+
rules:
24+
prevent_accidental_imports:
25+
allow:
26+
- $gostd
27+
- github.com/stretchr/testify/require
28+
- go.k6.io/k6
29+
- github.com/grafana/sobek
30+
- github.com/grafana/xk6-sql
31+
- github.com/proullon/ramsql/driver
32+
issues:
33+
max-issues-per-linter: 0
34+
max-same-issues: 0
35+
formatters:
36+
enable:
37+
- gci
38+
- gofmt
39+
- gofumpt
40+
- goimports

CONTRIBUTING.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ The `Makefile` is generated from the task list defined in the `CONTRIBUTING.md`
111111
make makefile
112112
```
113113

114+
### security - Run security and vulnerability checks
115+
116+
The [gosec] tool is used for security checks. The [govulncheck] tool is used to check the vulnerability of dependencies.
117+
118+
```bash
119+
gosec -quiet ./...
120+
govulncheck ./...
121+
```
122+
123+
[gosec]: https://github.com/securego/gosec
124+
[govulncheck]: https://github.com/golang/vuln
125+
[security]: <#security---run-security-and-vulnerability-checks>
126+
114127
### lint - Run the linter
115128

116129
The [golangci-lint] tool is used for static analysis of the source code. It is advisable to run it before committing the changes.
@@ -119,6 +132,7 @@ The [golangci-lint] tool is used for static analysis of the source code. It is a
119132
golangci-lint run
120133
```
121134

135+
[lint]: <#lint---run-the-linter>
122136
[golangci-lint]: https://github.com/golangci/golangci-lint
123137

124138
### test - Run the tests
@@ -172,6 +186,7 @@ mdcode update
172186
```
173187

174188
[mdcode]: <https://github.com/szkiba/mdcode>
189+
[readme]: #readme---update-readmemd
175190

176191
### clean - Clean the working directory
177192

@@ -193,12 +208,12 @@ bun x typedoc --out build/docs
193208

194209
[doc]: #doc---generate-api-documentation
195210

196-
### all - Clean build
211+
### all - Run all
197212

198213
Performs the most important tasks. It can be used to check whether the CI workflow will run successfully.
199214

200215
Requires
201-
: [clean], [format], [test], [build], [doc]
216+
: [clean], [lint], [security], [test], [build], [doc], [example], [readme], [makefile]
202217

203218
### format - Format the go source codes
204219

@@ -213,4 +228,4 @@ go fmt ./...
213228
```bash
214229
cdo --makefile Makefile
215230
```
216-
[makefile]: <#makefile---generate-the-makefile>
231+
[makefile]: <#makefile---generate-the-makefile>

Makefile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ __help__:
88
@echo 'Usage: make [target]'
99
@echo ''
1010
@echo 'Targets:'
11-
@echo ' all Clean build'
11+
@echo ' all Run all'
1212
@echo ' build Build custom k6 with extension'
1313
@echo ' clean Clean the working directory'
1414
@echo ' coverage View the test coverage report'
@@ -18,11 +18,12 @@ __help__:
1818
@echo ' lint Run the linter'
1919
@echo ' makefile Generate the Makefile'
2020
@echo ' readme Update README.md'
21+
@echo ' security Run security and vulnerability checks'
2122
@echo ' test Run the tests'
2223

23-
# Clean build
24+
# Run all
2425
.PHONY: all
25-
all: clean format test build doc
26+
all: clean lint security test build doc example readme makefile
2627

2728
# Build custom k6 with extension
2829
.PHONY: build
@@ -87,6 +88,14 @@ readme:
8788
mdcode update;\
8889
)
8990

91+
# Run security and vulnerability checks
92+
.PHONY: security
93+
security:
94+
@(\
95+
gosec -quiet ./...;\
96+
govulncheck ./...;\
97+
)
98+
9099
# Run the tests
91100
.PHONY: test
92101
test:

README.md

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ xk6-sql is a [Grafana k6 extension](https://grafana.com/docs/k6/latest/extension
1212

1313
Check out the API documentation [here](https://sql.x.k6.io). The TypeScript declaration file can be downloaded from [here](https://sql.x.k6.io/index.d.ts).
1414

15-
> [!NOTE]
16-
> To use the TypeScript declaration file in your IDE (e.g. Visual Studio Code), you need to create a `jsconfig.json` (or `tsconfig.json`) file with the following content:
17-
>
18-
> ```json file=examples/jsconfig.json
19-
> {
20-
> "compilerOptions": {
21-
> "target": "ES6",
22-
> "module": "ES6",
23-
> "paths": {
24-
> "k6/x/sql": ["./typings/xk6-sql/index.d.ts"]
25-
> }
26-
> }
27-
>}
28-
>```
29-
> You will need to update the TypeScript declaration file location in the example above to where you downloaded it.
15+
To use the TypeScript declaration file in your IDE (e.g. Visual Studio Code), you need to create a `jsconfig.json` (or `tsconfig.json`) file with the following content:
16+
17+
```json file=examples/jsconfig.json
18+
{
19+
"compilerOptions": {
20+
"target": "ES6",
21+
"module": "ES6",
22+
"paths": {
23+
"k6/x/sql": ["./typings/xk6-sql/index.d.ts"]
24+
}
25+
}
26+
}
27+
```
28+
29+
You will need to update the TypeScript declaration file location in the example above to where you downloaded it.
3030

3131
## Usage
3232

@@ -78,39 +78,6 @@ export default function () {
7878
}
7979
```
8080

81-
<details>
82-
<summary><b>output</b></summary>
83-
84-
```bash file=examples/example.txt
85-
86-
/\ Grafana /‾‾/
87-
/\ / \ |\ __ / /
88-
/ \/ \ | |/ / / ‾‾\
89-
/ \ | ( | (‾) |
90-
/ __________ \ |_|\_\ \_____/
91-
92-
execution: local
93-
script: examples/example.js
94-
output: -
95-
96-
scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
97-
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
98-
99-
time="2024-10-21T15:47:50+02:00" level=info msg="4 rows inserted" source=console
100-
time="2024-10-21T15:47:50+02:00" level=info msg="Pan, Peter" source=console
101-
102-
data_received........: 0 B 0 B/s
103-
data_sent............: 0 B 0 B/s
104-
iteration_duration...: avg=371.25µs min=371.25µs med=371.25µs max=371.25µs p(90)=371.25µs p(95)=371.25µs
105-
iterations...........: 1 1061.969082/s
106-
107-
108-
running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
109-
default ✓ [ 100% ] 1 VUs 00m00.0s/10m0s 1/1 iters, 1 per VU
110-
```
111-
112-
</details>
113-
11481
## Build
11582

11683
The [xk6](https://github.com/grafana/xk6) build tool can be used to build a k6 that will include **xk6-sql** extension and database drivers.

examples/example.txt

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

examples/examples.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ setup() {
1414
}
1515

1616
@test 'example.js' {
17-
$EXE run examples/example.js >examples/example.txt 2>&1
18-
[ $? -eq 0 ]
19-
grep -q 'msg="Pan, Peter"' examples/example.txt
17+
run $EXE run example.js
18+
[ $status -eq 0 ]
19+
echo "$output" | grep -q 'msg="Pan, Peter"'
2020
}

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ require (
66
github.com/grafana/sobek v0.0.0-20250320150027-203dc85b6d98
77
github.com/proullon/ramsql v0.1.4
88
github.com/stretchr/testify v1.10.0
9-
go.k6.io/k6 v0.58.0
9+
go.k6.io/k6 v1.0.0
1010
)
1111

1212
require (
1313
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
1414
github.com/davecgh/go-spew v1.1.1 // indirect
1515
github.com/dlclark/regexp2 v1.11.4 // indirect
16-
github.com/evanw/esbuild v0.25.1 // indirect
16+
github.com/evanw/esbuild v0.25.3 // indirect
1717
github.com/fatih/color v1.18.0 // indirect
1818
github.com/fsnotify/fsnotify v1.6.0 // indirect
1919
github.com/go-logr/logr v1.4.2 // indirect
@@ -43,14 +43,14 @@ require (
4343
go.opentelemetry.io/otel/trace v1.35.0 // indirect
4444
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
4545
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
46-
golang.org/x/net v0.37.0 // indirect
47-
golang.org/x/sys v0.31.0 // indirect
48-
golang.org/x/text v0.23.0 // indirect
46+
golang.org/x/net v0.39.0 // indirect
47+
golang.org/x/sys v0.32.0 // indirect
48+
golang.org/x/text v0.24.0 // indirect
4949
golang.org/x/time v0.11.0 // indirect
5050
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a // indirect
5151
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect
52-
google.golang.org/grpc v1.71.0 // indirect
53-
google.golang.org/protobuf v1.36.5 // indirect
52+
google.golang.org/grpc v1.71.1 // indirect
53+
google.golang.org/protobuf v1.36.6 // indirect
5454
gopkg.in/guregu/null.v3 v3.5.0 // indirect
5555
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
5656
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)