Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Enable build via GitHub Actions #12

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build

on:
# Enable manually triggering this workflow via the API or web UI
workflow_dispatch:
push:
branches:
- main
tags:
- v*
pull_request:

jobs:
build-with-xk6:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.18.x
- name: Get module name
run: |
echo "::set-output name=Module::$(go list -m)"
id: module-name
- name: Verify builds with xk6
run: |
go install go.k6.io/xk6/cmd/xk6@latest
xk6 build --with ${{ steps.module-name.outputs.Module }}=.

run-unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.18.x
- name: Run unit tests
run: go test -v -cover -race ./...
47 changes: 47 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Lint

on:
# Enable manually triggering this workflow via the API or web UI
workflow_dispatch:
push:
branches:
- main
tags:
- v*
pull_request:

jobs:
check-modules:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.18.x
- name: Check module dependencies
run: |
go version
test -z "$(go mod tidy && git status go.* --porcelain)"
go mod verify

run-golangci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.18.x
- name: Retrieve golangci-lint version
run: |
echo "::set-output name=Version::$(head -n 1 "${GITHUB_WORKSPACE}/.golangci.yml" | tr -d '# ')"
id: version
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: ${{ steps.version.outputs.Version }}
only-new-issues: true
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
k6
k6.exe

.DS_Store
.idea
.vscode

vendor
84 changes: 84 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# v1.47.2
# Please don't remove the first line. It is used 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
- funlen
- gocognit
- lll
- linters:
- paralleltest # false positive: https://github.com/kunwardeep/paralleltest/issues/8.
text: "does not use range value in test Run"

linters-settings:
cyclop:
max-complexity: 25
dupl:
threshold: 150
exhaustive:
default-signifies-exhaustive: true
funlen:
lines: 80
statements: 60
goconst:
min-len: 10
min-occurrences: 4
govet:
check-shadowing: true
maligned:
suggest-new: true
nolintlint:
# Disable to ensure that nolint directives don't have a leading space. Default is true.
allow-leading-space: false

linters:
enable-all: true
disable:
- decorder
- execinquery
- exhaustivestruct
- exhaustruct
- gci
- gochecknoinits
- gocyclo # replaced by cyclop since it also calculates the package complexity
- godot
- godox
- goerr113 # most of the errors here are meant for humans
- goheader
- golint # this linter is deprecated
- gomnd
- gomodguard
- grouper
- interfacer # deprecated
- ireturn
- maintidx
- maligned # replaced by govet 'fieldalignment'
- nlreturn
- nonamedreturns
- nosnakecase
- scopelint # deprecated, replaced by exportloopref
- tagliatelle
- testpackage
- thelper
- varnamelen
- wrapcheck # a little bit too much for k6, maybe after https://github.com/tomarrell/wrapcheck/issues/2 is fixed
- wsl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to update this list with the one from the current k6 master branch - maybe just copy the whole file ;)

fast: false
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
MAKEFLAGS += --silent

all: clean format test build

## help: Prints a list of available build targets.
help:
echo "Usage: make <OPTIONS> ... <TARGETS>"
echo ""
echo "Available targets are:"
echo ''
sed -n 's/^##//p' ${PWD}/Makefile | column -t -s ':' | sed -e 's/^/ /'
echo
echo "Targets run by default are: `sed -n 's/^all: //p' ./Makefile | sed -e 's/ /, /g' | sed -e 's/\(.*\), /\1, and /'`"

## clean: Removes any previously created build artifacts.
clean:
rm -f ./k6

## build: Builds a custom 'k6' with the local extension.
build:
go install go.k6.io/xk6/cmd/xk6@latest
xk6 build --with $(shell go list -m)=.

## format: Applies Go formatting to code.
format:
go fmt ./...

## test: Executes any unit tests.
test:
go test -cover -race ./...

.PHONY: build clean format help test
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
> It may also break in the future as xk6 evolves. USE AT YOUR OWN RISK!
> Any issues with the tool should be raised [here](https://github.com/grafana/xk6-amqp/issues).

</br>
</br>

<div align="center">

# xk6-amqp
AMQP xk6 plugin. Built for [k6](https://go.k6.io/k6) using [xk6](https://github.com/grafana/xk6).

</div>
A k6 extension for publishing and consuming of messages [AMQP](https://www.amqp.org/) queues and exchanges.

## Build

Expand All @@ -23,24 +16,24 @@ To build a `k6` binary with this extension, first ensure you have the prerequisi

Then:

1. Download `xk6`:
1. Download [xk6](https://github.com/grafana/xk6):
```bash
$ go install go.k6.io/xk6/cmd/xk6@latest
```

2. Build the binary:
2. [Build the k6 binary](https://github.com/grafana/xk6#command-usage):
```bash
$ xk6 build --with github.com/grafana/xk6-amqp@latest
```
## Development
To make development a little smoother, use the `Makefile` in the root folder. The default target will format your code, run tests, and create a `k6` binary with your local code rather than from GitHub.

To make development a little smoother, you may run the build script provided in the root folder. It will create a k6 binary with your local code rather than from GitHub.

```bash
$ ./build.sh && ./k6 run my-test-script.js
```shell
git clone [email protected]:grafana/xk6-amqp.git
cd xk6-amqp
make
```


## Example

```javascript
Expand Down Expand Up @@ -125,4 +118,4 @@ default ✓ [======================================] 1 VUs 00m00.0s/10m0s 1/1

```

Inspect examples folder for more details.
Inspect examples folder for more details.
3 changes: 0 additions & 3 deletions build.sh

This file was deleted.

Loading