Skip to main content

GitHub Actions

Runner OS

For now, only the following OS and versions are supported on the runners:

  • Ubuntu 20.04 and later
  • Debian 11 and later

Setupโ€‹

1. Allow the Action to upload on CodSpeedโ€‹

Public repositories

CodSpeed allows tokenless uploads for public repositories, allowing runs to be triggered from public forks directly.

To enable this, you don't need to store the token and you can simply omit the token input when creating the benchmarks workflow.

First, you need to get your CodSpeed Token. There are multiple ways to retrieve it:

  • Once you enable a repository on CodSpeed, you'll be prompted to copy the token
  • You can also find it on the repository settings page
Token scope

Be mindful that a token is scoped to a specific repository. Make sure that you are on the correct repository settings page when copying the token.

Then, create a new encrypted secret in your repository with the name CODSPEED_TOKEN and the value of your token.

2. Create the benchmarks workflowโ€‹

The next step is to create a new workflow to run the benchmarks for your repository.

You can do this by creating the codspeed.yml file in the .github/workflows directory with the following content:

.github/workflows/codspeed.yml
name: codspeed-benchmarks

on:
# Run on pushes to the main branch
push:
branches:
- "master" # or "main"
# Run on pull requests
pull_request:
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# ...
# Setup your environment here:
# - Configure your Python/Rust/Node version
# - Install your dependencies
# - Build your benchmarks (if using a compiled language)
# ...
- name: Run benchmarks
uses: CodSpeedHQ/action@v2
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: "<Insert your benchmark command here>"

The most important step of this workflow is the usage of CodSpeedHQ/action. This action will configure the CodSpeed environment and upload the benchmarks results.

Sample configurationsโ€‹

3. Check the resultsโ€‹

Once the workflow is created, your pull requests will receive a performance report comment and will also receive some additional checks:

4. Next Stepsโ€‹

Now that everything is up and running (and hopefully green ๐ŸŽ‰), you can start enhancing your workflow to get the most out of CodSpeed.

Advancedโ€‹

Defining environment variablesโ€‹

You can define environment variables for your benchmarks by using the env key in the section of the action:

- name: Run benchmarks
uses: CodSpeedHQ/action@v2
env:
MY_ENV_VAR: "my-value"
with:
token: ${{ secrets.CODSPEED_TOKEN }}