Skip to content

Commit e582566

Browse files
authored
Merge pull request #12 from szkiba/feature/simplification
refactor: Simplification
2 parents 8ca278d + 2df3356 commit e582566

27 files changed

+287
-2068
lines changed

.github/workflows/build.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build
2+
on: [pull_request]
3+
4+
jobs:
5+
build:
6+
name: Bundle xk6 extensions
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Check out code
11+
uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
15+
- name: Build
16+
id: build
17+
uses: szkiba/xk6bundler@v0
18+
with:
19+
with: github.com/szkiba/xk6-dotenv=/github/workspace
20+
k6_version: latest

.github/workflows/release.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
7+
jobs:
8+
release:
9+
name: Bundle xk6 extensions
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
packages: write
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ${{ github.repository }}
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Build
25+
id: build
26+
uses: szkiba/xk6bundler@v0
27+
with:
28+
with: github.com/szkiba/xk6-dotenv=/github/workspace
29+
k6_version: latest
30+
31+
- name: Create Release
32+
uses: softprops/action-gh-release@v1
33+
with:
34+
files: dist/*.tar.gz
35+
36+
- name: Log in to the Container registry
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Extract metadata (tags, labels) for Docker
44+
id: meta
45+
uses: docker/metadata-action@v5
46+
with:
47+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
48+
tags: |
49+
type=semver,pattern={{version}}
50+
type=semver,pattern={{major}}.{{minor}}
51+
type=semver,pattern={{major}}
52+
53+
- name: Build and push Docker image
54+
uses: docker/build-push-action@v5
55+
with:
56+
push: true
57+
context: ./${{ steps.build.outputs.dockerdir }}
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
/k6
2-
.task
3-
node_modules
2+
/k6.exe

.golangci.yml

+129-36
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,135 @@
1-
# MIT License
2-
#
3-
# Copyright (c) 2021 Iván Szkiba
4-
#
5-
# Permission is hereby granted, free of charge, to any person obtaining a copy
6-
# of this software and associated documentation files (the "Software"), to deal
7-
# in the Software without restriction, including without limitation the rights
8-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
# copies of the Software, and to permit persons to whom the Software is
10-
# furnished to do so, subject to the following conditions:
11-
#
12-
# The above copyright notice and this permission notice shall be included in all
13-
# copies or substantial portions of the Software.
14-
#
15-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
# SOFTWARE.
1+
# v1.55.2
2+
# Please don't remove the first line. It uses in CI to determine the golangci version
3+
run:
4+
deadline: 5m
5+
6+
issues:
7+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
8+
max-issues-per-linter: 0
9+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
10+
max-same-issues: 0
11+
12+
# We want to try and improve the comments in the k6 codebase, so individual
13+
# non-golint items from the default exclusion list will gradually be added
14+
# to the exclude-rules below
15+
exclude-use-default: false
16+
17+
exclude-rules:
18+
# Exclude duplicate code and function length and complexity checking in test
19+
# files (due to common repeats and long functions in test code)
20+
- path: _(test|gen)\.go
21+
linters:
22+
- cyclop
23+
- dupl
24+
- gocognit
25+
- funlen
26+
- lll
27+
- path: js\/modules\/k6\/http\/.*_test\.go
28+
linters:
29+
# k6/http module's tests are quite complex because they often have several nested levels.
30+
# The module is in maintainance mode, so we don't intend to port the tests to a parallel version.
31+
- paralleltest
32+
- tparallel
33+
- linters:
34+
- staticcheck # Tracked in https://github.com/grafana/xk6-grpc/issues/14
35+
text: "The entire proto file grpc/reflection/v1alpha/reflection.proto is marked as deprecated."
36+
- linters:
37+
- forbidigo
38+
text: 'use of `os\.(SyscallError|Signal|Interrupt)` forbidden'
39+
40+
linters-settings:
41+
nolintlint:
42+
# Disable to ensure that nolint directives don't have a leading space. Default is true.
43+
allow-leading-space: false
44+
exhaustive:
45+
default-signifies-exhaustive: true
46+
govet:
47+
check-shadowing: true
48+
cyclop:
49+
max-complexity: 25
50+
maligned:
51+
suggest-new: true
52+
dupl:
53+
threshold: 150
54+
goconst:
55+
min-len: 10
56+
min-occurrences: 4
57+
funlen:
58+
lines: 80
59+
statements: 60
60+
forbidigo:
61+
forbid:
62+
- '^(fmt\\.Print(|f|ln)|print|println)$'
63+
# Forbid everything in os, except os.Signal and os.SyscalError
64+
- '^os\.(.*)$(# Using anything except Signal and SyscallError from the os package is forbidden )?'
65+
# Forbid everything in syscall except the uppercase constants
66+
- '^syscall\.[^A-Z_]+$(# Using anything except constants from the syscall package is forbidden )?'
67+
- '^logrus\.Logger$'
2268

2369
linters:
24-
presets:
25-
- bugs
26-
- style
27-
- unused
28-
- complexity
29-
- format
30-
- performance
70+
disable-all: true
3171
enable:
72+
- asasalint
73+
- asciicheck
74+
- bidichk
75+
- bodyclose
76+
- contextcheck
77+
- cyclop
78+
- dogsled
79+
- dupl
80+
- durationcheck
81+
- errcheck
82+
- errchkjson
83+
- errname
84+
- errorlint
85+
- exhaustive
3286
- exportloopref
33-
disable:
34-
- nolintlint
35-
- exhaustivestruct
87+
- forbidigo
88+
- forcetypeassert
89+
- funlen
90+
- gocheckcompilerdirectives
3691
- gochecknoglobals
37-
- gochecknoinits
92+
- gocognit
93+
- goconst
94+
- gocritic
95+
- gofmt
96+
- gofumpt
97+
- goimports
98+
- gomoddirectives
99+
- goprintffuncname
100+
- gosec
101+
- gosimple
102+
- govet
103+
- importas
104+
- ineffassign
105+
- interfacebloat
38106
- lll
39-
- maligned
40-
- interfacer
41-
- scopelint
42-
- wrapcheck
107+
- makezero
108+
- misspell
109+
- nakedret
110+
- nestif
111+
- nilerr
112+
- nilnil
113+
- noctx
114+
- nolintlint
115+
- nosprintfhostport
116+
- paralleltest
117+
- prealloc
118+
- predeclared
119+
- promlinter
120+
- revive
121+
- reassign
122+
- rowserrcheck
123+
- sqlclosecheck
124+
- staticcheck
125+
- stylecheck
126+
- tenv
127+
- tparallel
128+
- typecheck
129+
- unconvert
130+
- unparam
131+
- unused
132+
- usestdlibvars
133+
- wastedassign
134+
- whitespace
135+
fast: false

README.md

+19-30
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,36 @@ This extension follow the [convention](https://github.com/bkeepers/dotenv#what-o
1515
| 3rd | `.env.production` | production | No. | Shared environment-specific settings |
1616
| Last | `.env` | (any _expect_ `false`) | Depends | The Original |
1717

18-
19-
The underlying implementation is https://github.com/joho/godotenv
20-
21-
Built for [k6](https://go.k6.io/k6) using [xk6](https://github.com/grafana/xk6).
22-
2318
## Usage
2419

25-
Import an entire module's contents:
26-
```JavaScript
27-
import * as dotenv from "k6/x/dotenv";
28-
```
20+
The `.env` files are loaded automatically when starting k6. To use it, simply create the appropriate `.env` file (see table above) and set (optional) the `K6_ENV` environment variable.
2921

30-
Import a single export from a module:
31-
```JavaScript
32-
import { parse } from "k6/x/dotenv";
22+
For the most convenient use, create a file called `.env.local` and write the environment variables you want to set in it. One variable per line, in `name=value` form.
23+
24+
```sh
25+
SOME_ENV_VAR=somevalue
3326
```
3427

35-
## API
28+
If you want to be really fancy with your env file you can do comments and exports:
3629

37-
This extension can be used as a library:
30+
```sh
31+
# I am a comment and that is OK
32+
SOME_VAR=someval
33+
FOO=BAR # comments at line end are OK too
34+
export BAR=BAZ
35+
```
3836

39-
- [parse](docs/README.md#parse)
40-
- [stringify](docs/README.md#stringify)
37+
## Download
4138

42-
For complete API documentation click [here](docs/README.md)!
39+
You can download pre-built k6 binaries from [Releases](https://github.com/szkiba/xk6-dotenv/releases/) page. Check [Packages](https://github.com/szkiba/xk6-dotenv/pkgs/container/xk6-dotenv) page for pre-built k6 Docker images.
4340

4441
## Build
4542

46-
To build a `k6` binary with this extension, first ensure you have the prerequisites:
43+
The [xk6](https://github.com/grafana/xk6) build tool can be used to build a k6 that will include xk6-faker extension:
4744

48-
- [Go toolchain](https://go101.org/article/go-toolchain.html)
49-
- Git
50-
51-
Then:
45+
```bash
46+
$ xk6 build --with github.com/szkiba/xk6-dotenv@latest
47+
```
5248

53-
1. Install `xk6`:
54-
```bash
55-
$ go install go.k6.io/xk6/cmd/xk6@latest
56-
```
49+
For more build options and how to use xk6, check out the [xk6 documentation](https://github.com/grafana/xk6).
5750

58-
2. Build the binary:
59-
```bash
60-
$ xk6 build --with github.com/szkiba/xk6-dotenv@latest
61-
```

Taskfile.yml

-63
This file was deleted.

0 commit comments

Comments
 (0)