Running in CI
Learn how to run your Autoblocks tests in a CI environment.
Prerequisites
Make sure you’ve followed our quick start guide and have your tests running locally.
Once you have your tests set up and running locally,
you can run them in a CI environment via the same npx autoblocks testing exec
command.
Setup
Create secrets
You will need to add your Autoblocks API key as a secret in your GitHub repository. Make sure to include any other secrets your tests depend on, such as your OpenAI API key.
You can get your Autoblocks API key from the settings page and follow the instructions here for adding a repository secret.
Ensure your commit email address is configured
We associate test runs on feature branches with your Autoblocks user based on the commit author’s email address. Make sure your commit email address matches your Autoblocks user email address.
You can update your commit address globally:
Or within a specific repository:
Examples
Run on every push
Run your tests on every push to your repository:
Why do you need to set the GITHUB_TOKEN
as an environment variable?
The CLI uses the automated GITHUB_TOKEN
secret
to fetch metadata about the run that is not directly available within the run’s context.
The GITHUB_TOKEN
is created for you automatically by GitHub and is available to use in your workflow file.
You do not need to add it to your repository’s secrets.
Its scope is determined by your workflow’s permissions.
Run only when a pull request is opened or updated
Run your tests when a pull request is opened or updated:
Run on a schedule
Run your tests on a schedule:
Run manually
Run your tests manually via a workflow_dispatch event:
See the GitHub documentation on manually running a workflow.
Run only on certain commits
This workflow will run your tests only when a commit contains a certain string.
For example, you can run your tests only when a commit message contains [autoblocks]
:
Or, if you are triggering on pull requests:
Run in multiple scenarios
You can use a combination of all of the above to run your tests in multiple scenarios:
More examples
Check out some end to end examples in our examples repository:
Slack Notifications
You can receive Slack notifications with test results by setting the AUTOBLOCKS_SLACK_WEBHOOK_URL
environment variable. To get set up:
- Create a webhook URL for the channel where you want results to be posted by following Slack’s instructions on setting up incoming webhooks
- Add this webhook URL to your repository as a secret called
AUTOBLOCKS_SLACK_WEBHOOK_URL
in addition to the secrets you already added in the setup section
Then, set the environment variable in your workflow:
If you have multiple triggers for your workflow and only want to receive Slack notifications for some of them, you can add a step that only sets the environment variable for certain event types:
GitHub Comments
A summary of test results is posted automatically as a comment on the pull request associated with the commit that triggered the test run. If a commit is pushed but a pull request hasn’t been opened yet, the summary is posted on the commit instead.
Autoblocks updates the same comment with the latest test results each time the workflow runs. This prevents the comment section from becoming cluttered.
If you would like to disable comments, you can set the AUTOBLOCKS_DISABLE_GITHUB_COMMENTS
environment variable to 1
.
GitHub Actions Permissions (Advanced)
If your GitHub organization has set the default permissions
for GITHUB_TOKEN
to be restricted, you will need to explicitly give the workflow permission to post comments on pull requests or commits.
- Commenting on a pull request from a
pull_request
event:
- Commenting on a pull request from a
push
event:
Other CI Providers
Using a CI provider other than GitHub Actions? Contact us at support@autoblocks.ai and we’ll help get you set up.