From 4745cb752479d86d635b67fac637184958fad613 Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Tue, 14 Oct 2025 15:47:05 +0200 Subject: [PATCH 1/5] feat: allow specifying branch names or git refs for the runner version --- action.yml | 56 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/action.yml b/action.yml index e83290c..036b96a 100644 --- a/action.yml +++ b/action.yml @@ -38,7 +38,7 @@ inputs: required: false runner-version: - 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'." + 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'. For debugging: 'branch:branch-name' or 'ref:commit-sha'." required: false instruments: @@ -71,9 +71,48 @@ runs: RUNNER_VERSION="${{ inputs.runner-version }}" if [ -z "$RUNNER_VERSION" ]; then RUNNER_VERSION=$(cat $GITHUB_ACTION_PATH/.codspeed-runner-version) - elif [ "$RUNNER_VERSION" != "latest" ]; then + fi + + # Detect version type (priority: latest > version number > branch/ref prefixes) + if [ "$RUNNER_VERSION" = "latest" ]; then + VERSION_TYPE="latest" + elif echo "$RUNNER_VERSION" | grep -qE '^v?[0-9]+\.[0-9]+\.[0-9]+'; then + # Version number (with or without 'v' prefix) + VERSION_TYPE="release" # Strip 'v' prefix if present to normalize version format RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^v//') + elif echo "$RUNNER_VERSION" | grep -q '^branch:'; then + VERSION_TYPE="branch" + RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^branch://') + elif echo "$RUNNER_VERSION" | grep -q '^ref:'; then + VERSION_TYPE="ref" + RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^ref://') + else + # Default to release version + VERSION_TYPE="release" + RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^v//') + fi + + # Install the CodSpeedHQ/runner + if [ "$VERSION_TYPE" = "latest" ]; then + curl -fsSL http://github.com/CodSpeedHQ/runner/releases/latest/download/codspeed-runner-installer.sh | bash -s -- --quiet + elif [ "$VERSION_TYPE" = "branch" ]; then + # Install from specific branch using cargo + source $HOME/.cargo/env + cargo install --git https://github.com/CodSpeedHQ/runner --branch "$RUNNER_VERSION" + elif [ "$VERSION_TYPE" = "ref" ]; then + # Install from specific commit/ref using cargo + source $HOME/.cargo/env + cargo install --git https://github.com/CodSpeedHQ/runner --rev "$RUNNER_VERSION" + else + # Release version + 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) + if [ "$head_status" -eq 404 ]; then + echo "Error: Version $RUNNER_VERSION is not available in https://github.com/CodSpeedHQ/runner/releases, please a correct version." + exit 1 + else + curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v$RUNNER_VERSION/codspeed-runner-installer.sh | bash -s -- --quiet + fi fi # Get the runner arguments @@ -97,18 +136,5 @@ runs: RUNNER_ARGS="$RUNNER_ARGS --mongo-uri-env-name=${{ inputs.mongo-uri-env-name }}" fi - # Install the CodSpeedHQ/runner - if [ "$RUNNER_VERSION" = "latest" ]; then - curl -fsSL http://github.com/CodSpeedHQ/runner/releases/latest/download/codspeed-runner-installer.sh | bash -s -- --quiet - else - 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) - if [ "$head_status" -eq 404 ]; then - echo "Error: Version $RUNNER_VERSION is not available in https://github.com/CodSpeedHQ/runner/releases, please a correct version." - exit 1 - else - curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v$RUNNER_VERSION/codspeed-runner-installer.sh | bash -s -- --quiet - fi - fi - # Run the benchmarks codspeed run $RUNNER_ARGS -- '${{ inputs.run }}' From 114da162b07b99212ec3ef625740b0d5cb7e7c3e Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Tue, 14 Oct 2025 15:55:03 +0200 Subject: [PATCH 2/5] feat: add instruments-cache-dir argument --- README.md | 6 ++++++ action.yml | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index e4cee57..8891834 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,12 @@ GitHub Actions for running [CodSpeed](https://codspeed.io) in your CI. # Only used if the `mongodb` instrument is enabled. mongo_uri_env_name: "" + # [OPTIONAL] + # The directory to use for caching installations of instruments (like valgrind or perf). + # This will speed up subsequent workflow runs by reusing previously installed instruments. + # Defaults to $HOME/.cache/codspeed-action if not specified. + instruments-cache-dir: "" + # [OPTIONAL] # A custom upload url, only if you are using an on premise CodSpeed instance upload-url: "" diff --git a/action.yml b/action.yml index 036b96a..e1b715b 100644 --- a/action.yml +++ b/action.yml @@ -46,15 +46,28 @@ inputs: Comma separated list of instruments to enable. The following instruments are available: - `mongodb`: MongoDB instrumentation, requires the MongoDB instrument to be enabled for the organization in CodSpeed required: false + mongo-uri-env-name: description: | The name of the environment variable containing the MongoDB URI. Requires the `mongodb` instrument to be activated in `instruments`. 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. required: false + instruments-cache-dir: + description: | + The directory to use for caching installations of instruments (like valgrind or perf). Defaults to `$HOME/.cache/codspeed-action`. + required: false + default: "~/.cache/codspeed-action" + runs: using: "composite" steps: + - name: Cache CodSpeed instruments + uses: actions/cache@v4 + with: + path: ${{ inputs.instruments-cache-dir }} + key: codspeed-instruments-${{ runner.os }}-${{ runner.arch }} + - shell: bash env: GH_MATRIX: "${{ toJson(matrix) }}" @@ -135,6 +148,9 @@ runs: if [ -n "${{ inputs.mongo-uri-env-name }}" ]; then RUNNER_ARGS="$RUNNER_ARGS --mongo-uri-env-name=${{ inputs.mongo-uri-env-name }}" fi + if [ -n "${{ inputs.instruments-cache-dir }}" ]; then + RUNNER_ARGS="$RUNNER_ARGS --setup-cache-dir=${{ inputs.instruments-cache-dir }}" + fi # Run the benchmarks codspeed run $RUNNER_ARGS -- '${{ inputs.run }}' From d1ce9d48b1cb914730f8323f9627a6c2f1d2ac4d Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Wed, 15 Oct 2025 10:07:22 +0200 Subject: [PATCH 3/5] feat: add way to disable instruments cache --- README.md | 5 +++++ action.yml | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8891834..7c50083 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,11 @@ GitHub Actions for running [CodSpeed](https://codspeed.io) in your CI. # Only used if the `mongodb` instrument is enabled. mongo_uri_env_name: "" + # [OPTIONAL] + # Enable caching of instrument installations (like valgrind or perf) to speed up + # subsequent workflow runs. Set to 'false' to disable caching. Defaults to 'true'. + cache-instruments: "true" + # [OPTIONAL] # The directory to use for caching installations of instruments (like valgrind or perf). # This will speed up subsequent workflow runs by reusing previously installed instruments. diff --git a/action.yml b/action.yml index e1b715b..6729133 100644 --- a/action.yml +++ b/action.yml @@ -53,6 +53,12 @@ inputs: 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. required: false + cache-instruments: + description: | + Enable caching of instrument installations (like valgrind or perf) to speed up subsequent workflow runs. Set to 'false' to disable caching. + required: false + default: "true" + instruments-cache-dir: description: | The directory to use for caching installations of instruments (like valgrind or perf). Defaults to `$HOME/.cache/codspeed-action`. @@ -63,6 +69,7 @@ runs: using: "composite" steps: - name: Cache CodSpeed instruments + if: inputs.cache-instruments == 'true' uses: actions/cache@v4 with: path: ${{ inputs.instruments-cache-dir }} @@ -148,7 +155,7 @@ runs: if [ -n "${{ inputs.mongo-uri-env-name }}" ]; then RUNNER_ARGS="$RUNNER_ARGS --mongo-uri-env-name=${{ inputs.mongo-uri-env-name }}" fi - if [ -n "${{ inputs.instruments-cache-dir }}" ]; then + if [ "${{ inputs.cache-instruments }}" = "true" ] && [ -n "${{ inputs.instruments-cache-dir }}" ]; then RUNNER_ARGS="$RUNNER_ARGS --setup-cache-dir=${{ inputs.instruments-cache-dir }}" fi From 945f984220cdf57aa17978a91c6c07359878bed7 Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Wed, 15 Oct 2025 10:38:36 +0200 Subject: [PATCH 4/5] feat: use runner version for cache key --- action.yml | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/action.yml b/action.yml index 6729133..574a218 100644 --- a/action.yml +++ b/action.yml @@ -38,7 +38,7 @@ inputs: required: false runner-version: - 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'. For debugging: 'branch:branch-name' or 'ref:commit-sha'." + 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'." required: false instruments: @@ -68,12 +68,28 @@ inputs: runs: using: "composite" steps: + - name: Determine runner and kernel version + id: versions + shell: bash + run: | + RUNNER_VERSION="${{ inputs.runner-version }}" + if [ -z "$RUNNER_VERSION" ]; then + RUNNER_VERSION=$(cat $GITHUB_ACTION_PATH/.codspeed-runner-version) + fi + echo "runner-version=$RUNNER_VERSION" >> $GITHUB_OUTPUT + + # Get kernel version for cache key + KERNEL_VERSION=$(uname -r) + echo "kernel-version=$KERNEL_VERSION" >> $GITHUB_OUTPUT + - name: Cache CodSpeed instruments if: inputs.cache-instruments == 'true' uses: actions/cache@v4 with: path: ${{ inputs.instruments-cache-dir }} - key: codspeed-instruments-${{ runner.os }}-${{ runner.arch }} + key: codspeed-instruments-${{ runner.os }}-${{ runner.arch }}-${{steps.versions.outputs.kernel-version }}-${{ steps.versions.outputs.runner-version }} + restore-keys: | + codspeed-instruments-${{ runner.os }}-${{ runner.arch }}-${{steps.versions.outputs.kernel-version }}- - shell: bash env: @@ -88,12 +104,9 @@ runs: fi # Configure and run codspeed-runner - RUNNER_VERSION="${{ inputs.runner-version }}" - if [ -z "$RUNNER_VERSION" ]; then - RUNNER_VERSION=$(cat $GITHUB_ACTION_PATH/.codspeed-runner-version) - fi + RUNNER_VERSION="${{ steps.versions.outputs.runner-version }}" - # Detect version type (priority: latest > version number > branch/ref prefixes) + # Detect version type (priority: latest > version number > branch/rev prefixes) if [ "$RUNNER_VERSION" = "latest" ]; then VERSION_TYPE="latest" elif echo "$RUNNER_VERSION" | grep -qE '^v?[0-9]+\.[0-9]+\.[0-9]+'; then @@ -104,9 +117,9 @@ runs: elif echo "$RUNNER_VERSION" | grep -q '^branch:'; then VERSION_TYPE="branch" RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^branch://') - elif echo "$RUNNER_VERSION" | grep -q '^ref:'; then - VERSION_TYPE="ref" - RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^ref://') + elif echo "$RUNNER_VERSION" | grep -q '^rev:'; then + VERSION_TYPE="rev" + RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^rev://') else # Default to release version VERSION_TYPE="release" @@ -120,8 +133,8 @@ runs: # Install from specific branch using cargo source $HOME/.cargo/env cargo install --git https://github.com/CodSpeedHQ/runner --branch "$RUNNER_VERSION" - elif [ "$VERSION_TYPE" = "ref" ]; then - # Install from specific commit/ref using cargo + elif [ "$VERSION_TYPE" = "rev" ]; then + # Install from specific commit/rev using cargo source $HOME/.cargo/env cargo install --git https://github.com/CodSpeedHQ/runner --rev "$RUNNER_VERSION" else From bc1167777035338ddfc2fbd103f0c9cd323611ff Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Thu, 16 Oct 2025 17:18:12 +0200 Subject: [PATCH 5/5] ci: use newer version for format test --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd86a22..e50ad12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,8 +69,8 @@ jobs: matrix: version: - "latest" - - "3.5.0" - - "v3.5.0" + - "4.2.0" + - "v4.2.0" runs-on: ubuntu-latest env: