From 93f3bff7c426114926bb32dd720990b0513cfb7c Mon Sep 17 00:00:00 2001 From: Vitali Haradkou <8816260+vitalics@users.noreply.github.com> Date: Tue, 27 Oct 2026 11:30:13 +0300 Subject: [PATCH] feat: install custom libraries and add Faker example --- .github/workflows/selftest.yml | 58 ++++++++++++++++++++++++++++++++++ README.md | 51 +++++++++++++++++++++++++++++- action.yml | 22 ++++++++++--- examples/faker.config.yaml | 14 ++++++++ examples/faker.test.yaml | 57 +++++++++++++++++++++++++++++++++ examples/perfscale.lock | 5 +++ 6 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 examples/faker.config.yaml create mode 100644 examples/faker.test.yaml create mode 100644 examples/perfscale.lock diff --git a/.github/workflows/selftest.yml b/.github/workflows/selftest.yml index 924ca70..2316a76 100644 --- a/.github/workflows/selftest.yml +++ b/.github/workflows/selftest.yml @@ -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=$(> "${GITHUB_OUTPUT}" + exit "${code}" + fi + fi + cmd=(perfscale run) [ -n "${IN_K6}" ] && cmd+=(--k6 "${IN_K6}") [ -n "${IN_LOCUST}" ] && cmd+=(--locust "${IN_LOCUST}") @@ -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 diff --git a/examples/faker.config.yaml b/examples/faker.config.yaml new file mode 100644 index 0000000..bd17917 --- /dev/null +++ b/examples/faker.config.yaml @@ -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 diff --git a/examples/faker.test.yaml b/examples/faker.test.yaml new file mode 100644 index 0000000..4def778 --- /dev/null +++ b/examples/faker.test.yaml @@ -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 } diff --git a/examples/perfscale.lock b/examples/perfscale.lock new file mode 100644 index 0000000..2bd4f6a --- /dev/null +++ b/examples/perfscale.lock @@ -0,0 +1,5 @@ +version = 1 + +[[libraries]] +use = "https://github.com/Perfscale/faker/releases/download/v0.1.0/faker.wasm" +sha256 = "742a19abda8478e040907838850482702257b894210f1faee2b3660fa877cdab"