From f748d0cb3f169e32c7ed28a40c67c5daaefd63da Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Wed, 4 Mar 2026 14:06:43 +0100 Subject: [PATCH 1/2] fix: stop using `curl --fail-with-body` and `jq` to maximize compatibility --- action.yml | 67 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/action.yml b/action.yml index c89e13a..05eaa95 100644 --- a/action.yml +++ b/action.yml @@ -97,7 +97,27 @@ runs: if [ -z "$RUNNER_VERSION" ]; then RUNNER_VERSION=$(cat $GITHUB_ACTION_PATH/.codspeed-runner-version) fi + # Strip 'v' prefix if present to normalize version format + RUNNER_VERSION="${RUNNER_VERSION#v}" + + # Detect version type (priority: latest > version number > branch/rev prefixes) + if [ "$RUNNER_VERSION" = "latest" ]; then + VERSION_TYPE="latest" + elif echo "$RUNNER_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+'; then + VERSION_TYPE="release" + 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 '^rev:'; then + VERSION_TYPE="rev" + RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^rev://') + else + # Default to release version + VERSION_TYPE="release" + fi + echo "runner-version=$RUNNER_VERSION" >> $GITHUB_OUTPUT + echo "version-type=$VERSION_TYPE" >> $GITHUB_OUTPUT # Get kernel version for cache key KERNEL_VERSION=$(uname -r) @@ -112,6 +132,17 @@ runs: restore-keys: | codspeed-instruments-${{ inputs.mode }}-${{ runner.os }}-${{ runner.arch }}-${{steps.versions.outputs.kernel-version }}- + - name: Lookup installer hash + id: installer-hash + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.0.1 + env: + RUNNER_VERSION: ${{ steps.versions.outputs.runner-version }} + with: + script: | + const hashes = require(`${process.env.GITHUB_ACTION_PATH}/.codspeed-runner-installer-hashes.json`) + const version = process.env.RUNNER_VERSION + core.setOutput('hash', hashes[version] || '') + - shell: bash env: GH_MATRIX: "${{ toJson(matrix) }}" @@ -128,26 +159,7 @@ runs: # Configure and run codspeed-runner RUNNER_VERSION="${{ steps.versions.outputs.runner-version }}" - - # 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 - # 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 '^rev:'; then - VERSION_TYPE="rev" - RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^rev://') - else - # Default to release version - VERSION_TYPE="release" - RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^v//') - fi + VERSION_TYPE="${{ steps.versions.outputs.version-type }}" # Install the runner SKIP_HASH_CHECK_WARNING_WARNING="${{ inputs.skip-hash-check-warning }}" @@ -177,15 +189,18 @@ runs: INSTALLER_TMP=$(mktemp) trap "rm -f $INSTALLER_TMP" EXIT - if ! curl -sSL --fail-with-body "$INSTALLER_URL" -o "$INSTALLER_TMP" 2>/dev/null; then - error_msg=$(jq -r '.error // empty' "$INSTALLER_TMP" 2>/dev/null) - install_output=$(cat "$INSTALLER_TMP") - echo "::error title=Failed to install CodSpeed CLI::Installation of CodSpeed CLI with version $RUNNER_VERSION failed.%0AReason: ${error_msg:-$install_output}" + CURL_ERR=$(mktemp) + if ! HTTP_CODE=$(curl -sSL -o "$INSTALLER_TMP" -w "%{http_code}" "$INSTALLER_URL" 2>"$CURL_ERR"); then + echo "::error title=Failed to install CodSpeed CLI::Installation of CodSpeed CLI with version $RUNNER_VERSION failed.%0AReason: $(cat "$CURL_ERR")" + exit 1 + fi + if [ "$HTTP_CODE" -ge 400 ]; then + error_body=$(cat "$INSTALLER_TMP") + echo "::error title=Failed to install CodSpeed CLI::Installation of CodSpeed CLI with version $RUNNER_VERSION failed.%0AReason: HTTP $HTTP_CODE - ${error_body:-no response body}" exit 1 fi - HASHES_FILE="$GITHUB_ACTION_PATH/.codspeed-runner-installer-hashes.json" - EXPECTED_HASH=$(jq -r --arg v "$RUNNER_VERSION" '.[$v] // empty' "$HASHES_FILE") + EXPECTED_HASH="${{ steps.installer-hash.outputs.hash }}" if [ -z "$EXPECTED_HASH" ]; then echo "::error::No pinned hash found for installer version $RUNNER_VERSION. Update .codspeed-runner-installer-hashes.json." exit 1 From c61f6b67a545e829c2aceea47fe0b22f64719458 Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Wed, 4 Mar 2026 18:13:52 +0100 Subject: [PATCH 2/2] feat: split install and run into two different steps This allows the path to be properly updated when installing on a minimal system From the generated installer by cargo-dist ``` add_install_dir_to_ci_path() { # Attempt to do CI-specific rituals to get the install-dir on PATH faster local _install_dir="$1" # If GITHUB_PATH is present, then write install_dir to the file it refs. # After each GitHub Action, the contents will be added to PATH. # So if you put a curl | sh for this script in its own "run" step, # the next step will have this dir on PATH. # # Note that GITHUB_PATH will not resolve any variables, so we in fact # want to write install_dir and not install_dir_expr if [ -n "${GITHUB_PATH:-}" ]; then ensure echo "$_install_dir" >> "$GITHUB_PATH" fi } ``` --- action.yml | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/action.yml b/action.yml index 05eaa95..9445084 100644 --- a/action.yml +++ b/action.yml @@ -143,26 +143,13 @@ runs: const version = process.env.RUNNER_VERSION core.setOutput('hash', hashes[version] || '') - - shell: bash - env: - GH_MATRIX: "${{ toJson(matrix) }}" - GH_STRATEGY: "${{ toJson(strategy) }}" - # This is needed to properly handle quotes and multiline commands in the 'run' input properly, rather than doing `RUN_INPUT_RUN=${{ inputs.run }}` in the script - CODSPEED_INPUT_RUN: ${{ inputs.run }} + - name: Install CodSpeed runner + shell: bash run: | - # Validate required inputs - # (custom message for smoother v4 migration) - if [ -z "${{ inputs.mode }}" ]; then - 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." - exit 1 - fi - - # Configure and run codspeed-runner RUNNER_VERSION="${{ steps.versions.outputs.runner-version }}" VERSION_TYPE="${{ steps.versions.outputs.version-type }}" - # Install the runner - SKIP_HASH_CHECK_WARNING_WARNING="${{ inputs.skip-hash-check-warning }}" + SKIP_HASH_CHECK_WARNING="${{ inputs.skip-hash-check-warning }}" if [ "$VERSION_TYPE" = "latest" ]; then if [ "$SKIP_HASH_CHECK_WARNING" != "true" ]; then @@ -216,6 +203,21 @@ runs: bash "$INSTALLER_TMP" --quiet fi + - name: Run the benchmarks + shell: bash + env: + GH_MATRIX: "${{ toJson(matrix) }}" + GH_STRATEGY: "${{ toJson(strategy) }}" + # This is needed to properly handle quotes and multiline commands in the 'run' input properly, rather than doing `RUN_INPUT_RUN=${{ inputs.run }}` in the script + CODSPEED_INPUT_RUN: ${{ inputs.run }} + run: | + # Validate required inputs + # (custom message for smoother v4 migration) + if [ -z "${{ inputs.mode }}" ]; then + 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." + exit 1 + fi + # Build the runner arguments array RUNNER_ARGS=() if [ -n "${{ inputs.token }}" ]; then