Skip to content

Commit 35399af

Browse files
authored
Merge pull request #304 from grafana/303-bug-xk6-lint-exit-code-is-always-0-on-failure
Correct exit code for xk6 lint command
2 parents de1433d + ca716bc commit 35399af

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

docs/workflows/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ The **Extension Validate** ([`extension-validate.yml`](../../.github/workflows/e
271271
xk6-lint-disable:
272272
description: xk6 lint checks to disable.
273273
required: false
274-
default: "security,vulnerability" # disable because they are run in a separate job
274+
# disable security and vulnerability checks because they are run in a separate job
275+
# disable versions check because versions will be created in the release workflow
276+
default: "security,vulnerability,versions"
275277
type: string
276278
xk6-lint-enable-only:
277279
description: xk6 lint checks to enable exclusively (disables the preset).

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ xk6 new -d "Experimenting with k6 extensions" example.com/user/xk6-demo
99
## Run the linter
1010

1111
```bash file=lint.sh
12-
xk6 lint
12+
xk6 lint --preset private
1313
```
1414

1515
## Build k6 with extensions

examples/lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
xk6 lint
1+
xk6 lint --preset private

internal/cmd/lint.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ var (
2929

3030
//go:embed help/presets.md
3131
presetsHelp string
32+
33+
errLintingFailed = errors.New("linting failed")
3234
)
3335

3436
func validPresetIDs() []string {
@@ -238,17 +240,30 @@ func lintRunE(ctx context.Context, args []string, opts *options) (result error)
238240
return err
239241
}
240242

243+
if !compliance.Passed {
244+
result = errLintingFailed
245+
}
246+
241247
if opts.quiet {
242-
return nil
248+
return result
243249
}
244250

245-
if opts.json {
246-
return jsonOutput(compliance, output, opts.compact)
251+
err = lintOutput(opts.json, compliance, output, opts.compact)
252+
if err != nil {
253+
return err
247254
}
248255

249-
textOutput(compliance, output)
256+
return result
257+
}
250258

251-
return nil
259+
func lintOutput(json bool, compliance *lint.Compliance, output io.Writer, compact bool) error {
260+
if !json {
261+
textOutput(compliance, output)
262+
263+
return nil
264+
}
265+
266+
return jsonOutput(compliance, output, compact)
252267
}
253268

254269
func jsonOutput(compliance any, output io.Writer, compact bool) error {

it

Submodule it updated 1 file

releases/v1.2.2.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Grafana **xk6** `v1.2.2` is here! 🎉
2+
3+
This small patch release fixes a critical issue with the exit code of the `xk6 lint` command. This bug was introduced in `v1.2.0`.
4+
5+
### Bug Fix
6+
7+
* **Corrected `xk6 lint` Exit Code:** The `xk6 lint` command now correctly returns a **non-zero exit code (e.g., `1`)** when one or more lint checks fail. Previously, the command always returned `0`, making it impossible for CI/CD pipelines (like GitHub Actions) to correctly detect linting failures and fail the build.

0 commit comments

Comments
 (0)