Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 58 additions & 41 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -112,45 +132,24 @@ runs:
restore-keys: |
codspeed-instruments-${{ inputs.mode }}-${{ runner.os }}-${{ runner.arch }}-${{steps.versions.outputs.kernel-version }}-

- shell: bash
- name: Lookup installer hash
id: installer-hash
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.0.1
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
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] || '')

# Configure and run codspeed-runner
- name: Install CodSpeed runner
shell: bash
run: |
RUNNER_VERSION="${{ steps.versions.outputs.runner-version }}"
VERSION_TYPE="${{ steps.versions.outputs.version-type }}"

# 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

# 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
Expand All @@ -177,15 +176,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
Expand All @@ -201,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
Expand Down
Loading