Skip to content

Commit

Permalink
refactor: Simplification
Browse files Browse the repository at this point in the history
- remove JavaScript API
- remove k6 direct dependency

BREAKING CHANGE:
  • Loading branch information
szkiba committed Apr 1, 2024
1 parent 8ca278d commit 827944e
Show file tree
Hide file tree
Showing 27 changed files with 280 additions and 2,070 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build
on: [pull_request]

jobs:
build:
name: Bundle xk6 extensions
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Build
id: build
uses: szkiba/xk6bundler@v0
with:
with: github.com/szkiba/xk6-dotenv=/github/workspace
k6_version: latest
59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release
on:
push:
tags:
- "v*"

jobs:
release:
name: Bundle xk6 extensions
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Build
id: build
uses: szkiba/xk6bundler@v0
with:
with: github.com/szkiba/xk6-dotenv=/github/workspace
k6_version: latest

- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: dist/*.tar.gz

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
context: ./${{ steps.build.outputs.dockerdir }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/k6
.task
node_modules
/k6.exe
165 changes: 129 additions & 36 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,135 @@
# MIT License
#
# Copyright (c) 2021 Iván Szkiba
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# v1.55.2
# Please don't remove the first line. It uses in CI to determine the golangci version
run:
deadline: 5m

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

# We want to try and improve the comments in the k6 codebase, so individual
# non-golint items from the default exclusion list will gradually be added
# to the exclude-rules below
exclude-use-default: false

exclude-rules:
# Exclude duplicate code and function length and complexity checking in test
# files (due to common repeats and long functions in test code)
- path: _(test|gen)\.go
linters:
- cyclop
- dupl
- gocognit
- funlen
- lll
- path: js\/modules\/k6\/http\/.*_test\.go
linters:
# k6/http module's tests are quite complex because they often have several nested levels.
# The module is in maintainance mode, so we don't intend to port the tests to a parallel version.
- paralleltest
- tparallel
- linters:
- staticcheck # Tracked in https://github.com/grafana/xk6-grpc/issues/14
text: "The entire proto file grpc/reflection/v1alpha/reflection.proto is marked as deprecated."
- linters:
- forbidigo
text: 'use of `os\.(SyscallError|Signal|Interrupt)` forbidden'

linters-settings:
nolintlint:
# Disable to ensure that nolint directives don't have a leading space. Default is true.
allow-leading-space: false
exhaustive:
default-signifies-exhaustive: true
govet:
check-shadowing: true
cyclop:
max-complexity: 25
maligned:
suggest-new: true
dupl:
threshold: 150
goconst:
min-len: 10
min-occurrences: 4
funlen:
lines: 80
statements: 60
forbidigo:
forbid:
- '^(fmt\\.Print(|f|ln)|print|println)$'
# Forbid everything in os, except os.Signal and os.SyscalError
- '^os\.(.*)$(# Using anything except Signal and SyscallError from the os package is forbidden )?'
# Forbid everything in syscall except the uppercase constants
- '^syscall\.[^A-Z_]+$(# Using anything except constants from the syscall package is forbidden )?'
- '^logrus\.Logger$'

linters:
presets:
- bugs
- style
- unused
- complexity
- format
- performance
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- cyclop
- dogsled
- dupl
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exportloopref
disable:
- nolintlint
- exhaustivestruct
- forbidigo
- forcetypeassert
- funlen
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gofmt
- gofumpt
- goimports
- gomoddirectives
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- interfacebloat
- lll
- maligned
- interfacer
- scopelint
- wrapcheck
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- prealloc
- predeclared
- promlinter
- revive
- reassign
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
fast: false
44 changes: 12 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,27 @@ This extension follow the [convention](https://github.com/bkeepers/dotenv#what-o
| 3rd | `.env.production` | production | No. | Shared environment-specific settings |
| Last | `.env` | (any _expect_ `false`) | Depends | The Original |


The underlying implementation is https://github.com/joho/godotenv

Built for [k6](https://go.k6.io/k6) using [xk6](https://github.com/grafana/xk6).

## Usage

Import an entire module's contents:
```JavaScript
import * as dotenv from "k6/x/dotenv";
```
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.

Import a single export from a module:
```JavaScript
import { parse } from "k6/x/dotenv";
```
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.

## API

This extension can be used as a library:
```sh
SOME_ENV_VAR=somevalue
```

- [parse](docs/README.md#parse)
- [stringify](docs/README.md#stringify)
## Download

For complete API documentation click [here](docs/README.md)!
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.

## Build

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

- [Go toolchain](https://go101.org/article/go-toolchain.html)
- Git

Then:
```bash
$ xk6 build --with github.com/szkiba/xk6-dotenv@latest
```

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

2. Build the binary:
```bash
$ xk6 build --with github.com/szkiba/xk6-dotenv@latest
```
63 changes: 0 additions & 63 deletions Taskfile.yml

This file was deleted.

Loading

0 comments on commit 827944e

Please sign in to comment.