Test every environment at once with a GitHub Actions matrix
The same collection often needs to run against several environments: staging after every merge, production as a read-only smoke check, maybe a second region. Instead of copying the job three times, give GitHub Actions a matrix.
The workflow
name: API tests (all environments)
on:
push:
branches: [main]
workflow_dispatch:
jobs:
api:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
environment: [Staging, Production]
steps:
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Run API tests on ${{ matrix.environment }}
env:
REQUESTARIUM_TOKEN: ${{ secrets.REQUESTARIUM_TOKEN }}
run: >
npx --yes @requestarium/cli run-collection "Users API"
--env "${{ matrix.environment }}"
--junit "results-${{ matrix.environment }}.xml"
--save-run
- uses: actions/upload-artifact@v4
if: always()
with:
name: results-${{ matrix.environment }}
path: results-${{ matrix.environment }}.xmlThe matrix value is the name of a Requestarium environment, so each job picks up that environment's baseUrl and variables. With --save-run, each run lands in the run history with its environment, so you can compare them in the app.
Different requests per environment
Production usually gets a smaller, read-only set. Add the folder to the matrix:
matrix:
include:
- environment: Staging
folder: Regression
- environment: Production
folder: Smoke run: >
npx --yes @requestarium/cli run-collection "Users API"
--env "${{ matrix.environment }}" --folder "${{ matrix.folder }}"Keep anything that writes data (create, delete, refund) out of the production folder. See smoke tests after a deploy for what belongs there.
Different secrets per environment
When production needs its own API key, use GitHub environments: create staging and production under Settings → Environments with a secret API_KEY in each, then:
environment: ${{ matrix.environment == 'Production' && 'production' || 'staging' }}
steps:
- run: >
npx --yes @requestarium/cli run-collection "Users API"
--env "${{ matrix.environment }}" --env-var apiKey=API_KEY
env:
REQUESTARIUM_TOKEN: ${{ secrets.REQUESTARIUM_TOKEN }}
API_KEY: ${{ secrets.API_KEY }}--env-var apiKey=API_KEY reads the CI secret into the apiKey variable and masks it in reports. A GitHub environment can also require an approval before a job runs, which is a sensible guard for anything that touches production.
Add a region or a preview
A new environment is one line in the matrix, as long as a Requestarium environment with that name exists. For a preview deployment whose URL changes every time, override the base URL instead of making an environment per preview:
environment: [Staging, Preview]--var baseUrl=https://pr-${{ github.event.number }}.preview.example.comDon't overload a shared environment
Parallel jobs against the same environment can trip over each other's data. Running different environments in parallel is safe; running the same one twice usually isn't. If you must, make test data unique per job, for example with {{$guid}} in names and emails.