Skip to content

Add K6 e2e tests and improve the CI #1714

Add K6 e2e tests and improve the CI

Add K6 e2e tests and improve the CI #1714

Workflow file for this run

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
# docs: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: πŸ§ͺ Tests
on:
workflow_dispatch: {}
push:
branches: [master, main]
paths-ignore: ['**.md']
tags-ignore: ['**']
pull_request:
paths-ignore: ['**.md']
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
git-leaks:
name: Check for GitLeaks
runs-on: ubuntu-latest
steps:
- {uses: actions/checkout@v4, with: {fetch-depth: 0}}
- uses: gacts/gitleaks@v1
lint-and-test:
name: Test and lint (backend)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- {uses: actions/setup-go@v5, with: {go-version-file: go.mod}}
- run: go install "github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected]"
- run: go generate -skip readme ./...
- uses: golangci/golangci-lint-action@v6
- run: go test -race -covermode=atomic ./...
lint-and-test-web:
name: Test and lint (web)
runs-on: ubuntu-latest
env: {FORCE_COLOR: 'true', NPM_PREFIX: './web'}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: {node-version: 22, cache: 'npm', cache-dependency-path: ./web/package-lock.json}
- run: npm --prefix "$NPM_PREFIX" install -dd --no-audit
- run: npm --prefix "$NPM_PREFIX" run generate
- run: npm --prefix "$NPM_PREFIX" run lint
- run: npm --prefix "$NPM_PREFIX" run test
- run: npm --prefix "$NPM_PREFIX" run build
build-app:
name: Build for ${{ matrix.os }} (${{ matrix.arch }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [linux, darwin, windows]
arch: [amd64, arm64]
env: {FORCE_COLOR: 'true', NPM_PREFIX: './web'}
# needs: [lint-and-test, lint-and-test-web] # TODO: uncomment
steps:
- uses: actions/checkout@v4
- {uses: gacts/github-slug@v1, id: slug}
- id: values
run: |
echo "binary-name=webhook-tester-${{ matrix.os }}-${{ matrix.arch }}`[ ${{ matrix.os }} = 'windows' ] && echo '.exe'`" >> $GITHUB_OUTPUT
echo "deb-name=webhook-tester_0.0.0-1_${{ matrix.arch }}" >> $GITHUB_OUTPUT
# build the frontend
- uses: actions/setup-node@v4
with: {node-version: 22, cache: 'npm', cache-dependency-path: ./web/package-lock.json}
- run: |
npm --prefix "$NPM_PREFIX" install --no-audit
npm --prefix "$NPM_PREFIX" run generate
npm --prefix "$NPM_PREFIX" run build
# build the backend
- {uses: actions/setup-go@v5, with: {go-version-file: go.mod}}
- run: go install "github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected]"
- run: go generate -skip readme ./...
- env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
LDFLAGS: -s -w -X gh.tarampamp.am/webhook-tester/v2/internal/version.version=v0.0.0@${{ steps.slug.outputs.commit-hash-short }}
run: go build -trimpath -ldflags "$LDFLAGS" -o ./${{ steps.values.outputs.binary-name }} ./cmd/webhook-tester/
# try to run the binary
- if: matrix.os == runner.os && matrix.arch == 'amd64'
run: ./${{ steps.values.outputs.binary-name }} -h
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.values.outputs.binary-name }}
path: ./${{ steps.values.outputs.binary-name }}
if-no-files-found: error
retention-days: 7
# build a Debian package
- if: matrix.os == 'linux' && matrix.arch == 'amd64'
env:
PKG_NAME: ${{ steps.values.outputs.deb-name }}
run: |
mkdir -p ${{ env.PKG_NAME }}/usr/local/bin ${{ env.PKG_NAME }}/DEBIAN
cp ${{ steps.values.outputs.binary-name }} ${{ env.PKG_NAME }}/usr/local/bin/webhook-tester
echo -e "Package: webhook_tester\nVersion: ${{ steps.slug.outputs.version }}" > ${{ env.PKG_NAME }}/DEBIAN/control
echo -e "Architecture: ${{ matrix.arch }}\nMaintainer: ${{ github.actor }}" >> ${{ env.PKG_NAME }}/DEBIAN/control
echo -e "Description: Powerful tool for testing WebHooks and more" >> ${{ env.PKG_NAME }}/DEBIAN/control
dpkg-deb --build --root-owner-group ${{ env.PKG_NAME }}
- if: matrix.os == 'linux' && matrix.arch == 'amd64'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.values.outputs.binary-name }}.deb
path: ./${{ steps.values.outputs.deb-name }}.deb
if-no-files-found: error
retention-days: 7
e2e-test:
name: End-to-end tests
runs-on: ubuntu-latest
needs: [build-app]
steps:
- uses: actions/checkout@v4
- {uses: actions/download-artifact@v4, with: {name: webhook-tester-linux-amd64}}
- run: chmod +x ./webhook-tester-linux-amd64
- run: ./webhook-tester-linux-amd64 start --port 8081 & # start the server in the background
- uses: grafana/setup-k6-action@v1
- uses: grafana/run-k6-action@v1
with: {path: ./tests/k6/run/*.js}
build-docker-image:
name: Build the docker image
runs-on: ubuntu-latest
needs: [lint-and-test, lint-and-test-web]
steps:
- uses: actions/checkout@v4
- uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: false
tags: app:local