Skip to content

Commit

Permalink
Reimplement using k6foundry (#111)
Browse files Browse the repository at this point in the history
* Use k6foundry for building
* refactor build options parsing for testability
* update README with warning about breaking change
* Update go version

---------

Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
  • Loading branch information
pablochacin authored Nov 15, 2024
1 parent 3d1b684 commit 686292c
Show file tree
Hide file tree
Showing 40 changed files with 3,986 additions and 2,651 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go-version: [ 1.18.x, 1.19.x ]
go-version: [ 1.22.x ]

# Set some variables per OS, usable via ${{ matrix.VAR }}
# XK6_BIN_PATH: the path to the compiled k6 binary, for artifact publishing
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.22.x
check-latest: true
- name: Retrieve golangci-lint version
run: |
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v1.50.1
# v1.59.1
# Please don't remove the first line. It uses in CI to determine the golangci version
linters-settings:
errcheck:
Expand Down
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ xk6 build [<k6_version>]
- `--with` can be used multiple times to add extensions by specifying the Go module name and optionally its version, similar to `go get`. Module name is required, but specific version and/or local replacement are optional. For an up-to-date list of k6 extensions, head to our [extensions page](https://k6.io/docs/extensions/).
- `--replace` can be used multiple times to add replacements by specifying the Go module name and the replacement module, similar to `go mod edit -replace=`. Version of the replacement can be specified with the `@version` suffix in the replacement path.

Versions can be anything compatible with `go get`.

Examples:

```bash
Expand Down Expand Up @@ -167,36 +169,16 @@ xk6 run -u 10 -d 10s test.js

The race detector can be enabled by setting the env variable `XK6_RACE_DETECTOR=1` or through the `XK6_BUILD_FLAGS` env variable.


## Library usage

```go
builder := xk6.Builder{
K6Version: "v0.35.0",
Extensions: []xk6.Dependency{
{
PackagePath: "github.com/grafana/xk6-browser",
Version: "v0.1.1",
},
},
}
err := builder.Build(context.Background(), "./k6")
```

Versions can be anything compatible with `go get`.


## Environment variables

Because the subcommands and flags are constrained to benefit rapid extension prototyping, xk6 does read some environment variables to take cues for its behavior and/or configuration when there is no room for flags.

- `K6_VERSION` sets the version of k6 to build.
- `XK6_BUILD_FLAGS` sets any go build flags if needed. Defaults to '-ldflags=-w -s'.
- `XK6_RACE_DETECTOR=1` enables the Go race detector in the build.
- `XK6_BUILD_FLAGS` sets any go build flags if needed. Defaults to '-ldflags=-w -s -trim'.
- `XK6_RACE_DETECTOR=1` enables the Go race detector in the build. Forces `GCO_ENABLED=1`.
- `XK6_SKIP_CLEANUP=1` causes xk6 to leave build artifacts on disk after exiting.
- `XK6_K6_REPO` optionally sets the path to the main k6 repository. This is useful when building with k6 forks.


## Keeping dependencies in sync

We recommend extension maintainers to keep dependencies in common with k6 core in the same version k6 core uses. This guarantees binary compatibility of the JS runtime, and ensures uses will not have to face unforeseen build-time errors when compiling several extensions together with xk6.
Expand All @@ -207,6 +189,26 @@ The [`go-depsync`](https://github.com/grafana/go-depsync/) tool can check for th
/your/extension$ go-depsync --parent go.k6.io/k6
```

## Library usage

> !Breaking change: since v0.14.0 `xk6.Builder.Build` function no longer reads environment variables to complete missing attributes. Use `xk6.FromOSEnv()` to create a builder from environment variables and then complete or override attributes as needed.
```go
// create builder with defaults from environment variables
builder := xk6.FromOSEnv()

// complete/override attributes
builder.K6Version = "v0.35.0",
builder.Extensions = []xk6.Dependency{
{
PackagePath: "github.com/grafana/xk6-browser",
Version: "v0.1.1",
},
}

err := builder.Build(context.Background(), log. "./k6")
```

---

> This project originally forked from the [xcaddy](https://github.com/caddyserver/xcaddy) project. **Thank you!**
Loading

0 comments on commit 686292c

Please sign in to comment.