Testing in GitHub Actions
Automatically run Speakeasy tests on SDK pull requests or other events in a GitHub repository via GitHub Actions.
Setting up a Github Actions Check
This requires previously completing the Github Setup. After completion, navigate to the SDK repository and run the following command:
# It's okay to run this command multiple times if tests are already configured locallyspeakeasy configure tests
This produces a Github Actions workflow like the following that allows running SDK tests as a Github check on Pull Requests.
name: Test SDKspermissions:checks: writecontents: writepull-requests: writestatuses: writeon:workflow_dispatch:inputs:target:description: Specific target to testtype: stringpull_request:paths:- '**'branches:- mainjobs:test:uses: speakeasy-api/sdk-generation-action/.github/workflows/sdk-test.yaml@v15with:target: ${{ github.event.inputs.target }}secrets:github_access_token: ${{ secrets.GITHUB_TOKEN }}speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
Ensuring Tests Run on Automated PR Creation
Warning
Pull requests created by the action using the default GITHUB_TOKEN cannot trigger other workflows. When on: pull_request or on: push workflows act as checks on pull requests, they will not run by default.
To ensure testing checks run by default when an SDK PR is created, implement one of the following options.
Installing the Speakeasy Github App
Installing the Speakeasy Github App and giving the App access to the SDK repository enables triggering testing runs after a PR is created. To install the app, visit this link (opens in a new tab) or follow instructions in the CLI or dashboard.
Setting up your own Github PAT
If not installing the Github App, another option is creating a Github Personal Access Token (PAT) for creating PRs in the SDK repository. This is a workaround recommended (opens in a new tab) by Github.
- Create a fine-grained (opens in a new tab) PAT with
Pull requests Read/Write
permissions. Ensure it has access to the SDK repository. Setting this to no expiration is recommended.
- In all SDK repositories, navigate to
Settings > Secrets and variables > Actions
and save the PAT as a Repository secret under the namePR_CREATION_PAT
.
- In all sdk_generation.yaml workflows, add the
pr-creation-token
as a provided secret at the bottom.
secrets:github_access_token: ${{ secrets.GITHUB_TOKEN }}speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}pr_creation_pat: ${{ secrets.PR_CREATION_PAT }}
Running in Direct mode
If the generation action runs in direct
mode where SDK updates get immediately pushed to main, testing runs as part of the generation action.
If tests fail, the generation action fails and does not push SDK changes to main.