GitHub Actions
Copy this workflow into .github/workflows/tarn.yml:
name: API Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - name: Install Tarn run: curl -fsSL https://raw.githubusercontent.com/NazarKalytiuk/tarn/main/install.sh | sh - name: Validate YAML run: tarn validate - name: Run tests run: tarn run --format json --json-mode compact --no-progress env: BASE_URL: ${{ secrets.API_BASE_URL }} API_KEY: ${{ secrets.API_KEY }}
Validate before run
Run tarn validate at the start of CI to catch YAML and config issues before execution:
$ tarn validate $ tarn validate --format json
Failing the pipeline
tarn run exits non-zero when any test fails. For JSON output, check summary.status in the report:
$ tarn run --format json --json-mode compact --no-progress # exits 1 if any test fails
Saving JSON report as artifact
- name: Run tests run: tarn run --format json=reports/run.json --no-progress - name: Upload report uses: actions/upload-artifact@v4 with: name: tarn-report path: reports/run.json
The JSON report contains structured failure data including failure_category, error_code, request and response payloads, and remediation_hints — ideal for post-processing in CI.
Using environment secrets
Pass secrets via env vars. They override tarn.env.yaml values due to the priority chain:
- name: Run tests run: tarn run env: BASE_URL: ${{ secrets.API_BASE_URL }} API_KEY: ${{ secrets.API_KEY }}
Using named environments
$ tarn run --env prod $ tarn run --env staging
Define each environment's variables in tarn.env.prod.yaml and tarn.env.staging.yaml.
Using --var for overrides
$ tarn run --var base_url=https://staging.example.com --var api_key=test123
The --var flag has the highest priority in the variable resolution chain, above shell env and env files.
Format check in CI
$ tarn fmt --check tests/ # exits 1 if any file needs formatting
Add this as a lint step early in your pipeline. It shares the same formatter engine as the LSP's textDocument/formatting, so passing --check means byte-identical output to "Format Document" in any editor.
Other CI systems
| System | Pattern |
|---|---|
| GitLab CI | Use artifacts:reports to persist the JSON report |
| CircleCI | Use store_artifacts for the JSON report |
| Jenkins | Use archiveArtifacts to preserve the report |
Best practices for CI
- Always run
tarn validatebeforetarn run - Use
--no-progressin CI for clean output - Use
--format json --json-mode compactfor machine parsing - Use deterministic faker seed:
TARN_FAKER_SEED=42 tarn run - Pass secrets via CI env vars, not in
tarn.env.yaml - Format gating:
tarn fmt --checkin a lint step