├── .codspeed-runner-version ├── .vscode └── settings.json ├── .prettierrc.json ├── CHANGELOG.md ├── examples ├── nodejs-typescript-codspeed.yml ├── go-codspeed.yml ├── cpp-cmake-codspeed.yml ├── python-pytest-codspeed.yml └── rust-cargo-codspeed.yml ├── LICENSE ├── scripts └── release.sh ├── .github └── workflows │ ├── bump-runner-version.yml │ └── ci.yml ├── .gitignore ├── README.md └── action.yml /.codspeed-runner-version: -------------------------------------------------------------------------------- 1 | 4.5.1 2 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "esbenp.prettier-vscode", 3 | "editor.formatOnSave": true 4 | } 5 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "useTabs": false, 4 | "bracketSpacing": false, 5 | "arrowParens": "avoid" 6 | } 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | This project is kept in sync with the [CodSpeedHQ/runner](https://github.com/CodSpeedHQ/runner) project. 4 | 5 | Checkout the [CodSpeedHQ/runner Changelog](https://github.com/CodSpeedHQ/runner/blob/main/CHANGELOG.md) for more details. 6 | -------------------------------------------------------------------------------- /examples/nodejs-typescript-codspeed.yml: -------------------------------------------------------------------------------- 1 | name: CodSpeed 2 | 3 | on: 4 | push: 5 | branches: 6 | - "main" # or "master" 7 | pull_request: # required to have reports on PRs 8 | # `workflow_dispatch` allows CodSpeed to trigger backtest 9 | # performance analysis in order to generate initial data. 10 | workflow_dispatch: 11 | 12 | permissions: # optional for public repositories 13 | contents: read 14 | id-token: write # for OpenID Connect authentication with CodSpeed 15 | 16 | jobs: 17 | codspeed: 18 | name: Run benchmarks 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | 23 | - uses: actions/setup-node@v3 24 | 25 | - name: Install dependencies 26 | run: npm install 27 | 28 | - name: Run benchmarks 29 | uses: CodSpeedHQ/action@v4 30 | with: 31 | mode: simulation 32 | run: node -r esbuild-register benches/bench.ts 33 | -------------------------------------------------------------------------------- /examples/go-codspeed.yml: -------------------------------------------------------------------------------- 1 | name: CodSpeed 2 | 3 | on: 4 | push: 5 | branches: 6 | - "main" # or "master" 7 | pull_request: # required to have reports on PRs 8 | # `workflow_dispatch` allows CodSpeed to trigger backtest 9 | # performance analysis in order to generate initial data. 10 | workflow_dispatch: 11 | 12 | permissions: # optional for public repositories 13 | contents: read 14 | id-token: write # for OpenID Connect authentication with CodSpeed 15 | 16 | jobs: 17 | codspeed: 18 | name: Run benchmarks 19 | runs-on: codspeed-macro 20 | steps: 21 | - uses: actions/checkout@v4 22 | 23 | - name: Setup Go 24 | uses: actions/setup-go@v5 25 | with: 26 | go-version: stable 27 | 28 | - name: Run Go benchmarks 29 | uses: CodSpeedHQ/action@main 30 | with: 31 | mode: walltime # go only supports walltime mode 32 | run: go test -bench=. -benchtime=5s 33 | -------------------------------------------------------------------------------- /examples/cpp-cmake-codspeed.yml: -------------------------------------------------------------------------------- 1 | name: CodSpeed 2 | 3 | on: 4 | push: 5 | branches: 6 | - "main" # or "master" 7 | pull_request: # required to have reports on PRs 8 | # `workflow_dispatch` allows CodSpeed to trigger backtest 9 | # performance analysis in order to generate initial data. 10 | workflow_dispatch: 11 | 12 | permissions: # optional for public repositories 13 | contents: read 14 | id-token: write # for OpenID Connect authentication with CodSpeed 15 | 16 | jobs: 17 | codspeed: 18 | name: Run benchmarks 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | 23 | - name: Build C++ benchmarks 24 | run: | 25 | mkdir -p build && cd build 26 | cmake -DCODSPEED_MODE=simulation .. 27 | make -j 28 | 29 | - name: Run C++ benchmarks 30 | uses: CodSpeedHQ/action@v4 31 | with: 32 | mode: simulation 33 | run: ./path/to/built/benchmark 34 | -------------------------------------------------------------------------------- /examples/python-pytest-codspeed.yml: -------------------------------------------------------------------------------- 1 | name: CodSpeed 2 | 3 | on: 4 | push: 5 | branches: 6 | - "main" # or "master" 7 | pull_request: # required to have reports on PRs 8 | # `workflow_dispatch` allows CodSpeed to trigger backtest 9 | # performance analysis in order to generate initial data. 10 | workflow_dispatch: 11 | 12 | permissions: # optional for public repositories 13 | contents: read 14 | id-token: write # for OpenID Connect authentication with CodSpeed 15 | 16 | jobs: 17 | codspeed: 18 | name: Run benchmarks 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | 23 | - uses: actions/setup-python@v3 24 | with: 25 | python-version: "3.9" 26 | 27 | - name: Install dependencies 28 | run: pip install -r requirements.txt 29 | 30 | - name: Run benchmarks 31 | uses: CodSpeedHQ/action@v4 32 | with: 33 | mode: simulation 34 | run: pytest tests/ --codspeed 35 | -------------------------------------------------------------------------------- /examples/rust-cargo-codspeed.yml: -------------------------------------------------------------------------------- 1 | name: CodSpeed 2 | 3 | on: 4 | push: 5 | branches: 6 | - "main" # or "master" 7 | pull_request: # required to have reports on PRs 8 | # `workflow_dispatch` allows CodSpeed to trigger backtest 9 | # performance analysis in order to generate initial data. 10 | workflow_dispatch: 11 | 12 | permissions: # optional for public repositories 13 | contents: read 14 | id-token: write # for OpenID Connect authentication with CodSpeed 15 | 16 | jobs: 17 | codspeed: 18 | name: Run benchmarks 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | 23 | - name: Setup rust toolchain, cache and cargo-codspeed binary 24 | uses: moonrepo/setup-rust@v0 25 | with: 26 | channel: stable 27 | cache-target: release 28 | bins: cargo-codspeed 29 | 30 | - name: Build the benchmark target(s) 31 | run: cargo codspeed build 32 | 33 | - name: Run the benchmarks 34 | uses: CodSpeedHQ/action@v4 35 | with: 36 | mode: simulation 37 | run: cargo codspeed run 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2022 CodSpeed and contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /scripts/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Usage: ./scripts/release.sh 3 | set -ex 4 | 5 | # Prechecks 6 | if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then 7 | echo "You must be on the main branch to release" 8 | exit 1 9 | fi 10 | git diff --exit-code 11 | 12 | # Bump version 13 | NEW_VERSION=$(cat .codspeed-runner-version) 14 | # verify that NEW_VERSION is a valid semver 15 | if ! [[ "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then 16 | echo "Version must be a valid semver (e.g. 1.2.3)" 17 | exit 1 18 | fi 19 | MAJOR_VERSION=$(echo $NEW_VERSION | cut -d. -f1) 20 | 21 | # Ask for confirmation 22 | read -p "Are you sure you want to release v$NEW_VERSION? Bumping the v$MAJOR_VERSION major version ?(y/n) " -n 1 -r 23 | echo 24 | if [[ ! $REPLY =~ ^[Yy]$ ]]; then 25 | exit 1 26 | fi 27 | 28 | # Fail if there are any unstaged changes left 29 | git diff --exit-code 30 | git commit -m "Release v$NEW_VERSION 🚀" --allow-empty 31 | git tag -s -fa v$NEW_VERSION -m "Release v$NEW_VERSION 🚀" 32 | git tag -s -fa v$MAJOR_VERSION -m "Release v$NEW_VERSION 🚀" 33 | git push origin tag v$NEW_VERSION 34 | git push -f origin tag v$MAJOR_VERSION 35 | git push --follow-tags 36 | 37 | RUNNER_NOTES=$(gh release view v$NEW_VERSION -R CodSpeedHQ/runner --json body | jq -r .body) 38 | RUNNER_NOTES="$RUNNER_NOTES 39 | 40 | 41 | **Full Runner Changelog**: https://github.com/CodSpeedHQ/runner/blob/main/CHANGELOG.md" 42 | gh release create v$NEW_VERSION --title "v$NEW_VERSION" --notes "$RUNNER_NOTES" -d 43 | -------------------------------------------------------------------------------- /.github/workflows/bump-runner-version.yml: -------------------------------------------------------------------------------- 1 | name: Bump the runner version 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | version: 7 | description: "Runner version" 8 | required: true 9 | 10 | permissions: 11 | contents: write 12 | pull-requests: write 13 | 14 | jobs: 15 | main: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v4 19 | with: 20 | fetch-depth: 0 21 | - name: Bump 22 | env: 23 | GH_TOKEN: ${{ github.token }} 24 | run: | 25 | # Check that the version is a valid semver 26 | if ! echo "${{ github.event.inputs.version }}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$'; then 27 | echo "Invalid version" 28 | exit 1 29 | fi 30 | # Check that this release exists in the CodSpeedHQ/runner repository 31 | if ! gh release view v${{ github.event.inputs.version }} -R CodSpeedHQ/runner; then 32 | echo "Release ${{ github.event.inputs.version }} does not exist in CodSpeedHQ/runner" 33 | exit 1 34 | fi 35 | 36 | git config --global user.email "github-actions[bot]@users.noreply.github.com" 37 | git config --global user.name "github-actions[bot]" 38 | echo "Bumping runner version to ${{ github.event.inputs.version }}" 39 | BRANCH_NAME=bump-runner-version/${{ github.event.inputs.version }} 40 | git checkout -b $BRANCH_NAME 41 | echo ${{ github.event.inputs.version }} > .codspeed-runner-version 42 | git add .codspeed-runner-version 43 | git commit -m "chore: bump runner version to ${{ github.event.inputs.version }}" 44 | git push origin $BRANCH_NAME 45 | gh pr create --title "chore: bump runner version to ${{ github.event.inputs.version }}" --body "Bump runner version to ${{ github.event.inputs.version }}" --base main --head $BRANCH_NAME 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependency directory 2 | node_modules 3 | 4 | # Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | lerna-debug.log* 12 | 13 | # Diagnostic reports (https://nodejs.org/api/report.html) 14 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 15 | 16 | # Runtime data 17 | pids 18 | *.pid 19 | *.seed 20 | *.pid.lock 21 | 22 | # Directory for instrumented libs generated by jscoverage/JSCover 23 | lib-cov 24 | 25 | # Coverage directory used by tools like istanbul 26 | coverage 27 | *.lcov 28 | 29 | # nyc test coverage 30 | .nyc_output 31 | 32 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 33 | .grunt 34 | 35 | # Bower dependency directory (https://bower.io/) 36 | bower_components 37 | 38 | # node-waf configuration 39 | .lock-wscript 40 | 41 | # Compiled binary addons (https://nodejs.org/api/addons.html) 42 | build/Release 43 | 44 | # Dependency directories 45 | jspm_packages/ 46 | 47 | # TypeScript v1 declaration files 48 | typings/ 49 | 50 | # TypeScript cache 51 | *.tsbuildinfo 52 | 53 | # Optional npm cache directory 54 | .npm 55 | 56 | # Optional eslint cache 57 | .eslintcache 58 | 59 | # Optional REPL history 60 | .node_repl_history 61 | 62 | # Output of 'npm pack' 63 | *.tgz 64 | 65 | # Yarn Integrity file 66 | .yarn-integrity 67 | 68 | # dotenv environment variables file 69 | .env 70 | .env.test 71 | 72 | # parcel-bundler cache (https://parceljs.org/) 73 | .cache 74 | 75 | # next.js build output 76 | .next 77 | 78 | # nuxt.js build output 79 | .nuxt 80 | 81 | # vuepress build output 82 | .vuepress/dist 83 | 84 | # Serverless directories 85 | .serverless/ 86 | 87 | # FuseBox cache 88 | .fusebox/ 89 | 90 | # DynamoDB Local files 91 | .dynamodb/ 92 | 93 | # OS metadata 94 | .DS_Store 95 | Thumbs.db 96 | 97 | # Ignore built ts files 98 | __tests__/runner/* 99 | lib/**/* -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths-ignore: 8 | - "**.md" 9 | pull_request: 10 | paths-ignore: 11 | - "**.md" 12 | workflow_dispatch: 13 | 14 | jobs: 15 | test-action: 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | os: 20 | - ubuntu-22.04 21 | - ubuntu-24.04 22 | - ubuntu-latest 23 | - codspeedhq-arm64-ubuntu-22.04 24 | - codspeedhq-arm64-ubuntu-24.04 25 | mode: 26 | - simulation 27 | - instrumentation 28 | - walltime 29 | 30 | runs-on: ${{ matrix.os }} 31 | env: 32 | CODSPEED_SKIP_UPLOAD: true 33 | steps: 34 | - uses: actions/checkout@v4 35 | - name: Check basic action execution 36 | uses: ./ 37 | with: 38 | allow-empty: true 39 | mode: ${{ matrix.mode }} 40 | run: echo "Working!" 41 | - name: Check action execution with env variables 42 | uses: ./ 43 | env: 44 | MY_ENV_VAR: "Hello" 45 | with: 46 | allow-empty: true 47 | mode: ${{ matrix.mode }} 48 | run: | 49 | output=$(echo "$MY_ENV_VAR") 50 | if [ "$output" != "Hello" ]; then 51 | echo "Assertion failed: Expected 'Hello' but got '$output'" 52 | exit 1 53 | fi 54 | - name: Check action in a custom directory 55 | uses: ./ 56 | with: 57 | allow-empty: true 58 | mode: ${{ matrix.mode }} 59 | working-directory: examples 60 | # Check that the directory is actually changed 61 | run: if [ $(basename $(pwd)) != "examples" ]; then exit 1; fi 62 | - name: Check action with multiline command 63 | uses: ./ 64 | with: 65 | allow-empty: true 66 | mode: ${{ matrix.mode }} 67 | run: | 68 | echo "Working"; 69 | echo "with"; 70 | echo "multiple lines"; 71 | test-version-formats: 72 | strategy: 73 | fail-fast: false 74 | matrix: 75 | version: 76 | - "latest" 77 | - "4.4.1" 78 | - "v4.4.1" 79 | 80 | runs-on: ubuntu-latest 81 | env: 82 | CODSPEED_SKIP_UPLOAD: true 83 | steps: 84 | - uses: actions/checkout@v4 85 | - name: Check action with version format ${{ matrix.version }} 86 | uses: ./ 87 | with: 88 | allow-empty: true 89 | runner-version: ${{ matrix.version }} 90 | mode: simulation 91 | run: echo "Testing version format ${{ matrix.version }}!" 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

CodSpeed Action

3 | 4 | [![CI](https://github.com/CodSpeedHQ/action/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/action/actions/workflows/ci.yml) 5 | [![GitHub release (latest by date)](https://img.shields.io/github/v/release/CodSpeedHQ/action)](https://github.com/CodSpeedHQ/action/releases) 6 | [![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF) 7 | 8 | GitHub Actions for running [CodSpeed](https://codspeed.io) in your CI. 9 | 10 |
11 | 12 | # Usage 13 | 14 | ```yaml 15 | - uses: CodSpeedHQ/action@v4 16 | with: 17 | # [REQUIRED] 18 | # The command used to run your CodSpeed benchmarks 19 | run: "" 20 | 21 | # [REQUIRED] 22 | # The measurement mode to use: "simulation" (recommended), or "walltime". 23 | # More details on the instruments at https://docs.codspeed.io/instruments/ 24 | mode: "simulation" 25 | 26 | # [OPTIONAL] 27 | # CodSpeed recommends using OpenID Connect (OIDC) for authentication. 28 | # 29 | # If you are not using OpenID Connect, set the CodSpeed upload token 30 | # that can be found at https://codspeed.io///settings 31 | # It's strongly recommended to use a secret for this value 32 | # If you're instrumenting a public repository, you can omit this value altogether 33 | # 34 | # More information in the CodSpeed documentation: 35 | # https://codspeed.io/docs/integrations/ci/github-actions#authentication 36 | token: "" 37 | 38 | # [OPTIONAL] 39 | # The directory where the `run` command will be executed. 40 | # ⚠️ WARNING: if you use `defaults.run.working-directory`, you must still set this parameter. 41 | working-directory: "" 42 | 43 | # [OPTIONAL] 44 | # Comma-separated list of instruments to enable. Possible values: mongodb. 45 | instruments: "" 46 | 47 | # [OPTIONAL] 48 | # The name of the environment variable that contains the MongoDB URI to patch. 49 | # If not provided, user will have to provide it dynamically through a CodSpeed integration. 50 | # Only used if the `mongodb` instrument is enabled. 51 | mongo_uri_env_name: "" 52 | 53 | # [OPTIONAL] 54 | # Enable caching of instrument installations (like valgrind or perf) to speed up 55 | # subsequent workflow runs. Set to 'false' to disable caching. Defaults to 'true'. 56 | cache-instruments: "true" 57 | 58 | # [OPTIONAL] 59 | # The directory to use for caching installations of instruments (like valgrind or perf). 60 | # This will speed up subsequent workflow runs by reusing previously installed instruments. 61 | # Defaults to $HOME/.cache/codspeed-action if not specified. 62 | instruments-cache-dir: "" 63 | 64 | # [OPTIONAL] 65 | # A custom upload url, only if you are using an on premise CodSpeed instance 66 | upload-url: "" 67 | ``` 68 | 69 | # Example usage 70 | 71 | ## Python with `pytest` and [`pytest-codspeed`](https://github.com/CodSpeedHQ/pytest-codspeed) 72 | 73 | This workflow will run the benchmarks found in the `tests/` folder and upload the results to CodSpeed. 74 | 75 | It will be triggered on every push to the `main` branch and on every pull request. 76 | 77 | ```yaml 78 | name: CodSpeed 79 | 80 | on: 81 | push: 82 | branches: 83 | - "main" # or "master" 84 | pull_request: # required to have reports on PRs 85 | # `workflow_dispatch` allows CodSpeed to trigger backtest 86 | # performance analysis in order to generate initial data. 87 | workflow_dispatch: 88 | 89 | jobs: 90 | benchmarks: 91 | name: Run benchmarks 92 | runs-on: ubuntu-latest 93 | permissions: # optional for public repositories 94 | contents: read 95 | id-token: write # for OpenID Connect authentication with CodSpeed 96 | steps: 97 | - uses: actions/checkout@v4 98 | - uses: actions/setup-python@v3 99 | with: 100 | python-version: "3.9" 101 | 102 | - name: Install dependencies 103 | run: pip install -r requirements.txt 104 | 105 | - name: Run benchmarks 106 | uses: CodSpeedHQ/action@v4 107 | with: 108 | mode: simulation 109 | run: pytest tests/ --codspeed 110 | ``` 111 | 112 | ## Rust with `cargo-codspeed` and `codspeed-criterion-compat` / `codspeed-bencher-compat` 113 | 114 | This workflow will run the benchmarks found in the `tests/` folder and upload the results to CodSpeed. 115 | 116 | It will be triggered on every push to the `main` branch and on every pull request. 117 | 118 | ```yml 119 | name: CodSpeed 120 | 121 | on: 122 | push: 123 | branches: 124 | - "main" # or "master" 125 | pull_request: # required to have reports on PRs 126 | # `workflow_dispatch` allows CodSpeed to trigger backtest 127 | # performance analysis in order to generate initial data. 128 | workflow_dispatch: 129 | 130 | jobs: 131 | name: Run benchmarks 132 | benchmarks: 133 | runs-on: ubuntu-latest 134 | permissions: # optional for public repositories 135 | contents: read 136 | id-token: write # for OpenID Connect authentication with CodSpeed 137 | steps: 138 | - uses: actions/checkout@v4 139 | 140 | - name: Setup rust toolchain, cache and cargo-codspeed binary 141 | uses: moonrepo/setup-rust@v0 142 | with: 143 | channel: stable 144 | cache-target: release 145 | bins: cargo-codspeed 146 | 147 | - name: Build the benchmark target(s) 148 | run: cargo codspeed build 149 | 150 | - name: Run the benchmarks 151 | uses: CodSpeedHQ/action@v4 152 | with: 153 | mode: simulation 154 | run: cargo codspeed run 155 | ``` 156 | 157 | ## Node.js with `codspeed-node`, TypeScript and `vitest` 158 | 159 | This workflow will run the benchmarks defined with `vitest`'s `bench` function and upload the results to CodSpeed. 160 | 161 | It will be triggered on every push to the `main` branch and on every pull request. 162 | 163 | ```yml 164 | name: CodSpeed 165 | 166 | on: 167 | push: 168 | branches: 169 | - "main" # or "master" 170 | pull_request: # required to have reports on PRs 171 | # `workflow_dispatch` allows CodSpeed to trigger backtest 172 | # performance analysis in order to generate initial data. 173 | workflow_dispatch: 174 | 175 | jobs: 176 | benchmarks: 177 | name: Run benchmarks 178 | runs-on: ubuntu-latest 179 | permissions: # optional for public repositories 180 | contents: read 181 | id-token: write # for OpenID Connect authentication with CodSpeed 182 | steps: 183 | - uses: actions/checkout@v4 184 | 185 | - uses: actions/setup-node@v3 186 | 187 | - name: Install dependencies 188 | run: npm install 189 | 190 | - name: Run benchmarks 191 | uses: CodSpeedHQ/action@v4 192 | with: 193 | mode: simulation 194 | run: npx vitest bench 195 | ``` 196 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "CodSpeed Performance Analysis" 2 | description: "Continuous benchmarking and performance checks" 3 | branding: 4 | color: orange 5 | icon: activity 6 | 7 | author: "Arthur Pastel" 8 | inputs: 9 | run: 10 | description: "The command to run the benchmarks" 11 | required: true 12 | 13 | mode: 14 | description: | 15 | The mode to run the benchmarks in. The following modes are available: 16 | - `simulation`: Run the benchmarks with CPU simulation measurements. 17 | - `walltime`: Run the benchmarks with walltime measurement. 18 | - `instrumentation`: (Deprecated) Legacy name for `simulation`. Please use `simulation` instead. 19 | 20 | We strongly recommend starting with the `simulation` mode. 21 | 22 | Using the `walltime` mode on traditional VMs/Hosted Runners might lead to inconsistent data. For the best results, we recommend using CodSpeed Hosted Macro Runners, which are fine-tuned for performance measurement consistency. 23 | Check out the [Walltime Instrument Documentation](https://docs.codspeed.io/instruments/walltime/) for more details. 24 | required: true 25 | 26 | token: 27 | description: | 28 | CodSpeed upload token. Only required for private repositories. 29 | required: false 30 | 31 | working-directory: 32 | description: | 33 | The directory where the `run` command will be executed. 34 | Warning: if you use defaults.working-directory, you must still set this parameter. 35 | required: false 36 | 37 | upload-url: 38 | description: "The upload endpoint (for on-premise deployments)" 39 | required: false 40 | 41 | runner-version: 42 | description: "The version of the runner to use. Use 'latest' to automatically fetch the latest release version from GitHub, or specify a version like '3.5.0' or 'v3.5.0'." 43 | required: false 44 | 45 | instruments: 46 | description: | 47 | Comma separated list of instruments to enable. The following instruments are available: 48 | - `mongodb`: MongoDB instrumentation, requires the MongoDB instrument to be enabled for the organization in CodSpeed 49 | required: false 50 | 51 | mongo-uri-env-name: 52 | description: | 53 | The name of the environment variable containing the MongoDB URI. Requires the `mongodb` instrument to be activated in `instruments`. 54 | If the instrumentation is enabled and this value is not set, the user will need to dynamically provide the MongoDB URI to the CodSpeed runner. 55 | required: false 56 | 57 | cache-instruments: 58 | description: | 59 | Enable caching of instrument installations (like valgrind or perf) to speed up subsequent workflow runs. Set to 'false' to disable caching. 60 | required: false 61 | default: "true" 62 | 63 | instruments-cache-dir: 64 | description: | 65 | The directory to use for caching installations of instruments (like valgrind or perf). Defaults to `$HOME/.cache/codspeed-action`. 66 | required: false 67 | default: "~/.cache/codspeed-action" 68 | 69 | allow-empty: 70 | description: | 71 | Allow the action to complete successfully even if no benchmarks were found or run. Set to 'true' to enable this behavior. 72 | required: false 73 | default: "false" 74 | 75 | runs: 76 | using: "composite" 77 | steps: 78 | - name: Determine runner and kernel version 79 | id: versions 80 | shell: bash 81 | run: | 82 | RUNNER_VERSION="${{ inputs.runner-version }}" 83 | if [ -z "$RUNNER_VERSION" ]; then 84 | RUNNER_VERSION=$(cat $GITHUB_ACTION_PATH/.codspeed-runner-version) 85 | fi 86 | echo "runner-version=$RUNNER_VERSION" >> $GITHUB_OUTPUT 87 | 88 | # Get kernel version for cache key 89 | KERNEL_VERSION=$(uname -r) 90 | echo "kernel-version=$KERNEL_VERSION" >> $GITHUB_OUTPUT 91 | 92 | - name: Cache CodSpeed instruments 93 | if: inputs.cache-instruments == 'true' 94 | uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 95 | with: 96 | path: ${{ inputs.instruments-cache-dir }} 97 | key: codspeed-instruments-${{ inputs.mode }}-${{ runner.os }}-${{ runner.arch }}-${{steps.versions.outputs.kernel-version }}-${{ steps.versions.outputs.runner-version }} 98 | restore-keys: | 99 | codspeed-instruments-${{ inputs.mode }}-${{ runner.os }}-${{ runner.arch }}-${{steps.versions.outputs.kernel-version }}- 100 | 101 | - shell: bash 102 | env: 103 | GH_MATRIX: "${{ toJson(matrix) }}" 104 | GH_STRATEGY: "${{ toJson(strategy) }}" 105 | run: | 106 | # Validate required inputs 107 | # (custom message for smoother v4 migration) 108 | if [ -z "${{ inputs.mode }}" ]; then 109 | echo "::error title=Missing required input 'mode'::The 'mode' input is required as of CodSpeed Action v4. Please explicitly set 'mode' to 'simulation' or 'walltime'. Before, this variable was automatically set to instrumentation on every runner except for CodSpeed macro runners where it was set to walltime by default. See https://codspeed.io/docs/instruments for details." 110 | exit 1 111 | fi 112 | 113 | # Configure and run codspeed-runner 114 | RUNNER_VERSION="${{ steps.versions.outputs.runner-version }}" 115 | 116 | # Detect version type (priority: latest > version number > branch/rev prefixes) 117 | if [ "$RUNNER_VERSION" = "latest" ]; then 118 | VERSION_TYPE="latest" 119 | elif echo "$RUNNER_VERSION" | grep -qE '^v?[0-9]+\.[0-9]+\.[0-9]+'; then 120 | # Version number (with or without 'v' prefix) 121 | VERSION_TYPE="release" 122 | # Strip 'v' prefix if present to normalize version format 123 | RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^v//') 124 | elif echo "$RUNNER_VERSION" | grep -q '^branch:'; then 125 | VERSION_TYPE="branch" 126 | RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^branch://') 127 | elif echo "$RUNNER_VERSION" | grep -q '^rev:'; then 128 | VERSION_TYPE="rev" 129 | RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^rev://') 130 | else 131 | # Default to release version 132 | VERSION_TYPE="release" 133 | RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^v//') 134 | fi 135 | 136 | # Install the CodSpeedHQ/runner 137 | if [ "$VERSION_TYPE" = "latest" ]; then 138 | curl -fsSL http://github.com/CodSpeedHQ/runner/releases/latest/download/codspeed-runner-installer.sh | bash -s -- --quiet 139 | elif [ "$VERSION_TYPE" = "branch" ]; then 140 | # Install from specific branch using cargo 141 | source $HOME/.cargo/env 142 | cargo install --locked --git https://github.com/CodSpeedHQ/runner --branch "$RUNNER_VERSION" codspeed-runner 143 | elif [ "$VERSION_TYPE" = "rev" ]; then 144 | # Install from specific commit/rev using cargo 145 | source $HOME/.cargo/env 146 | cargo install --locked --git https://github.com/CodSpeedHQ/runner --rev "$RUNNER_VERSION" codspeed-runner 147 | else 148 | # Release version 149 | head_status=$(curl -I -fsSL -w "%{http_code}" -o /dev/null https://github.com/CodSpeedHQ/runner/releases/download/v$RUNNER_VERSION/codspeed-runner-installer.sh) 150 | if [ "$head_status" -eq 404 ]; then 151 | echo "Error: Version $RUNNER_VERSION is not available in https://github.com/CodSpeedHQ/runner/releases, please a correct version." 152 | exit 1 153 | else 154 | curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v$RUNNER_VERSION/codspeed-runner-installer.sh | bash -s -- --quiet 155 | fi 156 | fi 157 | 158 | # Get the runner arguments 159 | RUNNER_ARGS="" 160 | if [ -n "${{ inputs.token }}" ]; then 161 | RUNNER_ARGS="$RUNNER_ARGS --token ${{ inputs.token }}" 162 | fi 163 | if [ -n "${{ inputs.working-directory }}" ]; then 164 | RUNNER_ARGS="$RUNNER_ARGS --working-directory=${{ inputs.working-directory }}" 165 | fi 166 | if [ -n "${{ inputs.upload-url }}" ]; then 167 | RUNNER_ARGS="$RUNNER_ARGS --upload-url=${{ inputs.upload-url }}" 168 | fi 169 | if [ -n "${{ inputs.mode }}" ]; then 170 | RUNNER_ARGS="$RUNNER_ARGS --mode=${{ inputs.mode }}" 171 | fi 172 | if [ -n "${{ inputs.instruments }}" ]; then 173 | RUNNER_ARGS="$RUNNER_ARGS --instruments=${{ inputs.instruments }}" 174 | fi 175 | if [ -n "${{ inputs.mongo-uri-env-name }}" ]; then 176 | RUNNER_ARGS="$RUNNER_ARGS --mongo-uri-env-name=${{ inputs.mongo-uri-env-name }}" 177 | fi 178 | if [ "${{ inputs.cache-instruments }}" = "true" ] && [ -n "${{ inputs.instruments-cache-dir }}" ]; then 179 | RUNNER_ARGS="$RUNNER_ARGS --setup-cache-dir=${{ inputs.instruments-cache-dir }}" 180 | fi 181 | if [ "${{ inputs.allow-empty }}" = "true" ]; then 182 | RUNNER_ARGS="$RUNNER_ARGS --allow-empty" 183 | fi 184 | 185 | # Run the benchmarks 186 | codspeed run $RUNNER_ARGS -- '${{ inputs.run }}' 187 | --------------------------------------------------------------------------------