Skip to content
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
58 changes: 58 additions & 0 deletions .github/workflows/selftest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,64 @@ jobs:
unzip -l "${OUTPUT_FILE}" | grep -q "summary.json" \
|| { echo "::error::summary.json not packed into the artifact"; exit 1; }

faker:
name: custom Faker library (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5

- name: Run the action with a GitHub release library
id: loadtest
uses: ./
with:
version: v0.28.0
file: examples/faker.test.yaml
config: examples/faker.config.yaml

- name: Assert generated values and outputs
shell: bash
env:
SUMMARY_JSON: ${{ steps.loadtest.outputs.summary-json }}
SUMMARY_FILE: ${{ steps.loadtest.outputs.summary-file }}
OUTPUT_FILE: ${{ steps.loadtest.outputs.output-file }}
EXIT_CODE: ${{ steps.loadtest.outputs.exit-code }}
run: |
set -euo pipefail

[ "${EXIT_CODE}" = "0" ] || { echo "::error::exit-code=${EXIT_CODE}"; exit 1; }
[ -f "${SUMMARY_FILE}" ] || { echo "::error::summary-file missing"; exit 1; }
[ -f "${OUTPUT_FILE}" ] || { echo "::error::zip artifact missing"; exit 1; }
[ -n "${SUMMARY_JSON}" ] && [ -f "${SUMMARY_JSON}" ] \
|| { echo "::error::summary-json missing — --summary-export did not run"; exit 1; }

log=$(<"${SUMMARY_FILE}")
[[ "${log}" == *"E2E_OK"* ]] \
|| { echo "::error::Faker SQL validation did not pass"; exit 1; }
[[ "${log}" != *"E2E_FAIL"* ]] \
|| { echo "::error::Faker SQL validation failed"; exit 1; }

jq -e '.meta.engine == "native"
and .meta.vus == 1
and .libraries.faker.calls > 0
and .libraries.faker.errors == 0' "${SUMMARY_JSON}"

lock=$(<examples/perfscale.lock)
[[ "${lock}" == *"742a19abda8478e040907838850482702257b894210f1faee2b3660fa877cdab"* ]] \
|| { echo "::error::Faker release digest is not pinned"; exit 1; }

- name: Assert zip contains summary.json
shell: bash
env:
OUTPUT_FILE: ${{ steps.loadtest.outputs.output-file }}
run: |
unzip -l "${OUTPUT_FILE}" | grep -q "summary.json" \
|| { echo "::error::summary.json not packed into the artifact"; exit 1; }

jmeter:
name: jmeter engine
runs-on: ubuntu-latest
Expand Down
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,55 @@ JMeter runs emit no latency percentiles — the final console `summary =` line
is translated into the summary block with `avg`/`min`/`max` only, and the
jmeter process exit code is the gate (no thresholds integration).

### Custom libraries from GitHub

A native test can use custom WASM libraries published as GitHub release
assets. Pin the release URL and its SHA-256 digest in `config.yaml`:

```yaml
vus: 1
duration: 3s
seed: 42
libraries:
- use: https://github.com/Perfscale/faker/releases/download/v0.1.0/faker.wasm
sha256: '742a19abda8478e040907838850482702257b894210f1faee2b3660fa877cdab'
as: faker
capabilities: []
with:
language: en
encoding: url
```

```yaml
- uses: Perfscale/github-action@v1
with:
version: v0.28.0
file: examples/faker.test.yaml
config: examples/faker.config.yaml
```

Before a native `file` run, the action calls `perfscale install` for both YAML
documents. It fetches remote components, verifies their declared digests,
writes or updates `perfscale.lock`, and caches them by content. The subsequent
run resolves libraries through the lockfile and cache. An installation or
digest failure stops the action before the test runs and sets a nonzero
`exit-code`. Use a perfscale release that supports `perfscale install`, such
as v0.28.0.

Commit `perfscale.lock` alongside the YAML that declares the library for
reproducible, offline resolution once the artifact is cached. The same
`libraries:` declaration works for other SDK-built components. Faker's
`language` option defaults to `en`. Its `encoding` defaults to `plain`; use
`url` for percent-encoded values in form bodies and URL query strings, not for
ordinary JSON values. Generated values are available through tokens such as
`${faker.internet(email)}` and `${faker.address(city)}`.

See the complete [Faker config](examples/faker.config.yaml),
[in-memory SQLite test](examples/faker.test.yaml), and generated
[lockfile](examples/perfscale.lock). The test needs no external HTTP service.
See [Perfscale Faker](https://github.com/Perfscale/faker) for all available
generators and options.

## Inputs

| Input | Default | Description |
Expand Down Expand Up @@ -114,7 +163,7 @@ the real path.
| `summary-file` | Path to the captured run summary (perfscale stdout). |
| `summary-json` | Path to the machine-readable JSON summary (empty when disabled/unsupported). |
| `output-file` | Path to the zip artifact with the summary and metrics files. |
| `exit-code` | Exit code returned by `perfscale run`. |
| `exit-code` | Exit code returned by `perfscale install` or `perfscale run`. |

### Consuming the JSON summary

Expand Down
22 changes: 18 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ outputs:
description: 'Path to the zip artifact containing the summary and generated metrics files.'
value: ${{ steps.pack.outputs.output-file }}
exit-code:
description: 'Exit code returned by `perfscale run`.'
description: 'Exit code returned by `perfscale install` or `perfscale run`.'
value: ${{ steps.run.outputs.exit-code }}

runs:
Expand Down Expand Up @@ -179,6 +179,18 @@ runs:
echo "::error::'config' is required when 'file' (native engine) is set"; exit 1
fi

if [ -n "${IN_FILE}" ]; then
echo "+ perfscale install ${IN_FILE} ${IN_CONFIG}"
if perfscale install "${IN_FILE}" "${IN_CONFIG}"; then
:
else
code=$?
echo "::error::perfscale install failed with exit code ${code}"
echo "exit-code=${code}" >> "${GITHUB_OUTPUT}"
exit "${code}"
fi
fi

cmd=(perfscale run)
[ -n "${IN_K6}" ] && cmd+=(--k6 "${IN_K6}")
[ -n "${IN_LOCUST}" ] && cmd+=(--locust "${IN_LOCUST}")
Expand Down Expand Up @@ -215,9 +227,11 @@ runs:
code=${PIPESTATUS[0]}

[ -n "${summary_json}" ] && [ ! -f "${summary_json}" ] && summary_json=""
echo "summary-file=${summary}" >> "${GITHUB_OUTPUT}"
echo "summary-json=${summary_json}" >> "${GITHUB_OUTPUT}"
echo "exit-code=${code}" >> "${GITHUB_OUTPUT}"
{
echo "summary-file=${summary}"
echo "summary-json=${summary_json}"
echo "exit-code=${code}"
} >> "${GITHUB_OUTPUT}"
exit "${code}"

- name: Pack metrics
Expand Down
14 changes: 14 additions & 0 deletions examples/faker.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=../schema/config.schema.json
vus: 1
duration: 3s
seed: 42
libraries:
# Pin the GitHub release asset by content, not just by its URL.
- use: https://github.com/Perfscale/faker/releases/download/v0.1.0/faker.wasm
sha256: '742a19abda8478e040907838850482702257b894210f1faee2b3660fa877cdab'
as: faker
capabilities: []
with:
language: en
# Use percent-encoded values in forms and URL query strings.
encoding: url
57 changes: 57 additions & 0 deletions examples/faker.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# yaml-language-server: $schema=../schema/test.schema.json
#
# Validate the custom Faker library without an external HTTP service.
# Run: perfscale run -f examples/faker.test.yaml -c examples/faker.config.yaml
steps:
- name: open db
use: std/db-connect@v1
with:
driver: sqlite
dsn: "sqlite::memory:"
outputs: db

- name: validate generated values
use: std/db-query@v1
with:
id: "${{ db.id }}"
query: >
SELECT CASE WHEN
instr(?, '%40') > 0 AND instr(?, '@') = 0
AND instr(?, '%20') > 0 AND instr(?, ' ') = 0
AND ? = '4111111111111111'
AND CAST(? AS INTEGER) BETWEEN CAST(strftime('%Y','now') AS INTEGER) + 1 AND CAST(strftime('%Y','now') AS INTEGER) + 71
AND CAST(? AS INTEGER) BETWEEN 1 AND 12
AND CAST(? AS INTEGER) BETWEEN 100 AND 999
AND CAST(? AS INTEGER) BETWEEN 10000 AND 99999
THEN 'E2E_OK' ELSE 'E2E_FAIL' END AS result,
? AS email, ? AS street_address, ? AS city,
? AS credit_card_number, ? AS expiration_year
params:
- "${faker.internet(email)}"
- "${faker.internet(email)}"
- "${faker.address(street_address)}"
- "${faker.address(street_address)}"
- "${faker.payment(credit_card_number)}"
- "${faker.payment(credit_card_expiration_year)}"
- "${faker.payment(credit_card_expiration_month)}"
- "${faker.payment(credit_card_cvv)}"
- "${faker.address(zip_code)}"
- "${faker.internet(email)}"
- "${faker.address(street_address)}"
- "${faker.address(city)}"
- "${faker.payment(credit_card_number)}"
- "${faker.payment(credit_card_expiration_year)}"
outputs: rows

- name: show result
use: std/log@v1
with:
message: "E2E-RESULT ${{ rows.data }}"

- name: close db
use: std/db-close@v1
with: { id: "${{ db.id }}" }

- name: pace iterations
use: std/sleep@v1
with: { seconds: 2 }
5 changes: 5 additions & 0 deletions examples/perfscale.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version = 1

[[libraries]]
use = "https://github.com/Perfscale/faker/releases/download/v0.1.0/faker.wasm"
sha256 = "742a19abda8478e040907838850482702257b894210f1faee2b3660fa877cdab"
Loading