Skip to content

Commit

Permalink
refactor: making xk6-faker more maintainable
Browse files Browse the repository at this point in the history
  • Loading branch information
szkiba committed Mar 12, 2024
1 parent c174d69 commit 59c349b
Show file tree
Hide file tree
Showing 51 changed files with 6,328 additions and 4,305 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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-faker=/github/workspace
40 changes: 40 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Docs
on:
push:
branches: [master, feature/simplifa-api]
paths:
- .github/workflows/docs.yml
- index.js
- index.d.ts
- tsconfig.json

jobs:
docs:
name: Docs
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write

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

- name: Install bun
uses: oven-sh/setup-bun@v1
- name: Generate API doc
run: bun x typedoc
- name: Copy index.d.ts
run: cp index.d.ts build/docs/

- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: "build/docs"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v3
32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: lint

on:
pull_request:
workflow_dispatch:
push:
paths-ignore:
- "docs/**"
- README.md
- "releases/**"

permissions:
contents: read

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: "1.21"
cache: false
- name: Go linter
uses: golangci/golangci-lint-action@v3
with:
version: v1.55
args: --timeout=30m
install-mode: binary
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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-faker=/github/workspace

- 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 }}
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: test

on:
pull_request:
workflow_dispatch:
push:
paths-ignore:
- "docs/**"
- README.md
- "releases/**"

jobs:
test:
name: Test
strategy:
matrix:
platform:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{matrix.platform}}
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
- name: Checkout code
uses: actions/checkout@v4

- name: Test
run: go test -count 1 -race -coverprofile=coverage.txt ./...

- name: Upload Coverage
if: ${{ matrix.platform == 'ubuntu-latest' && github.ref_name == 'master' }}
uses: codecov/codecov-action@v3
with:
directory: build

- name: Generate Go Report Card
if: ${{ matrix.platform == 'ubuntu-latest' && github.ref_name == 'master' }}
uses: creekorful/[email protected]
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/k6
.task
node_modules
vendor/
*_skeleton.go
/build
/node_modules
yarn.lock
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"go.lintTool": "golangci-lint",
"go.lintFlags": ["--fast"]
"go.lintFlags": ["--fast"],
"go.buildTags": "codegen"
}
Loading

0 comments on commit 59c349b

Please sign in to comment.