Reusable workflow for automated API testing using Apidog CLI. Runs test scenarios and generates comprehensive reports with support for both manual environment specification and automatic environment detection.
- Automated API testing: Execute Apidog test scenarios via CLI
- Environment detection: Automatic detection based on git tags (beta/rc)
- Multiple output formats: HTML, CLI, JSON reports
- Configurable iterations: Run tests multiple times for reliability
- Artifact retention: 30-day report storage
- Flexible runners: Support for different GitHub runner types
- Automatic cleanup: CLI cleanup after test execution
api-tests:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/api-dog-e2e-tests.yml@v1.0.0
with:
test_iterations: "1"
output_formats: "html,cli"
node_version: "20"
runner_type: "firmino-lxc-runners"
secrets: inheritapi-tests:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/api-dog-e2e-tests.yml@v1.0.0
with:
auto_detect_environment: true
secrets: inheritname: Build and Test Pipeline
on:
push:
tags:
- 'v*.*.*-beta.*'
- 'v*.*.*-rc.*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# ... build steps ...
update_gitops:
needs: build
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/gitops-update.yml@v1.0.0
with:
# ... gitops configuration ...
e2e_tests:
needs: update_gitops
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/api-dog-e2e-tests.yml@v1.0.0
with:
auto_detect_environment: true
test_iterations: "3"
output_formats: "html,cli,json"
secrets: inherit| Input | Type | Default | Description |
|---|---|---|---|
node_version |
string | 20 |
Node.js version to use |
test_iterations |
string | 1 |
Number of test iterations |
output_formats |
string | html,cli |
Report formats (comma-separated: html, cli, json) |
runner_type |
string | firmino-lxc-runners |
GitHub runner type |
auto_detect_environment |
boolean | false |
Enable automatic environment detection from tag |
| Secret | Description |
|---|---|
test_scenario_id |
Apidog test scenario ID |
apidog_access_token |
Apidog access token for authentication |
| Secret | Description | Required When |
|---|---|---|
environment_id |
Apidog environment ID | auto_detect_environment is false |
dev_environment_id |
Apidog dev environment ID | auto_detect_environment is true |
stg_environment_id |
Apidog staging environment ID | auto_detect_environment is true |
When auto_detect_environment is enabled, the workflow automatically detects the environment based on git tag:
| Tag Pattern | Environment | Environment ID Used |
|---|---|---|
*-beta.* |
dev | dev_environment_id |
*-rc.* |
stg | stg_environment_id |
Note: Tags must contain -beta. or -rc. (with dot) for detection to work.
- html: Generates HTML report with detailed test results
- cli: Console output with colored results
- json: JSON format for programmatic processing
with:
output_formats: "html,cli,json"Run tests multiple times to ensure reliability:
with:
test_iterations: "3" # Run tests 3 timesUseful for:
- Detecting flaky tests
- Performance consistency checks
- Load testing scenarios
Test reports are automatically uploaded as artifacts with:
- Name:
apidog-e2e-test-reports-{TAG_TYPE} - Retention: 30 days
- Contents: All generated reports (HTML, JSON, etc.)
- Checkout Repository: Clone the repository
- Setup Node.js: Install specified Node.js version
- Install Apidog CLI: Install apidog-cli globally
- Determine Environment: Auto-detect or use manual environment ID
- Run Tests: Execute Apidog test scenario
- Upload Reports: Save test reports as artifacts
- Cleanup: Remove apidog-cli installation
with:
auto_detect_environment: trueThis ensures tests run against the correct environment based on the tag.
with:
test_iterations: "3"Helps identify flaky tests and ensures consistency.
with:
output_formats: "html,cli,json"- HTML for human review
- CLI for quick feedback
- JSON for automation/metrics
with:
runner_type: "firmino-lxc-runners"Faster execution and better resource control.
jobs:
update_gitops:
# ... update deployment ...
e2e_tests:
needs: update_gitops
uses: ./.github/workflows/api-dog-e2e-tests.yml@v1.0.0Ensures tests run after deployment is complete.
Error: Unrecognized tag format for e2e tests
Solution: Ensure your tag contains -beta. or -rc. with a dot:
- ✅
v1.2.3-beta.1 - ✅
v1.2.3-rc.2 - ❌
v1.2.3-beta(missing dot) - ❌
v1.2.3-rc(missing dot)
Solution: Increase test iterations to identify flaky tests:
with:
test_iterations: "5"Error: Environment ID not set
Solution: When using auto_detect_environment: true, ensure both environment secrets are configured at the repository or organization level:
APIDOG_DEV_ENVIRONMENT_IDAPIDOG_STG_ENVIRONMENT_ID
Then use secrets: inherit in your workflow call.
The workflow automatically cleans up the CLI after execution. If you encounter issues:
- Check Node.js version compatibility
- Verify network access to npm registry
- Review runner permissions
- Open Apidog application
- Navigate to your test scenario
- Copy the scenario ID from the URL or settings
- Go to Apidog Settings → API Access
- Generate a new access token
- Store in GitHub Secrets as
APIDOG_ACCESS_TOKEN
- Open Apidog application
- Go to Environments section
- Copy environment IDs for dev and staging
- Store in GitHub Secrets
name: E2E Tests
on:
push:
branches: [main]
jobs:
api-tests:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/api-dog-e2e-tests.yml@v1.0.0
secrets: inheritname: Release Pipeline
on:
push:
tags:
- 'v*.*.*-beta.*'
- 'v*.*.*-rc.*'
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
# ... build and deploy steps ...
e2e_tests:
needs: build_and_deploy
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/api-dog-e2e-tests.yml@v1.0.0
with:
auto_detect_environment: true
test_iterations: "3"
output_formats: "html,cli,json"
runner_type: "firmino-lxc-runners"
secrets: inheritname: Scheduled E2E Tests
on:
schedule:
- cron: '0 */6 * * *' # Every 6 hours
jobs:
test_dev:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/api-dog-e2e-tests.yml@v1.0.0
with:
test_iterations: "2"
secrets: inherit
test_stg:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/api-dog-e2e-tests.yml@v1.0.0
with:
test_iterations: "2"
secrets: inherit- GitOps Update - Update GitOps repository before running tests
- PR Security Scan - Security scanning for pull requests