Skip to content

Commit f748d0c

Browse files
fix: stop using curl --fail-with-body and jq to maximize compatibility
1 parent eee5404 commit f748d0c

1 file changed

Lines changed: 41 additions & 26 deletions

File tree

action.yml

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,27 @@ runs:
9797
if [ -z "$RUNNER_VERSION" ]; then
9898
RUNNER_VERSION=$(cat $GITHUB_ACTION_PATH/.codspeed-runner-version)
9999
fi
100+
# Strip 'v' prefix if present to normalize version format
101+
RUNNER_VERSION="${RUNNER_VERSION#v}"
102+
103+
# Detect version type (priority: latest > version number > branch/rev prefixes)
104+
if [ "$RUNNER_VERSION" = "latest" ]; then
105+
VERSION_TYPE="latest"
106+
elif echo "$RUNNER_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+'; then
107+
VERSION_TYPE="release"
108+
elif echo "$RUNNER_VERSION" | grep -q '^branch:'; then
109+
VERSION_TYPE="branch"
110+
RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^branch://')
111+
elif echo "$RUNNER_VERSION" | grep -q '^rev:'; then
112+
VERSION_TYPE="rev"
113+
RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^rev://')
114+
else
115+
# Default to release version
116+
VERSION_TYPE="release"
117+
fi
118+
100119
echo "runner-version=$RUNNER_VERSION" >> $GITHUB_OUTPUT
120+
echo "version-type=$VERSION_TYPE" >> $GITHUB_OUTPUT
101121
102122
# Get kernel version for cache key
103123
KERNEL_VERSION=$(uname -r)
@@ -112,6 +132,17 @@ runs:
112132
restore-keys: |
113133
codspeed-instruments-${{ inputs.mode }}-${{ runner.os }}-${{ runner.arch }}-${{steps.versions.outputs.kernel-version }}-
114134
135+
- name: Lookup installer hash
136+
id: installer-hash
137+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.0.1
138+
env:
139+
RUNNER_VERSION: ${{ steps.versions.outputs.runner-version }}
140+
with:
141+
script: |
142+
const hashes = require(`${process.env.GITHUB_ACTION_PATH}/.codspeed-runner-installer-hashes.json`)
143+
const version = process.env.RUNNER_VERSION
144+
core.setOutput('hash', hashes[version] || '')
145+
115146
- shell: bash
116147
env:
117148
GH_MATRIX: "${{ toJson(matrix) }}"
@@ -128,26 +159,7 @@ runs:
128159
129160
# Configure and run codspeed-runner
130161
RUNNER_VERSION="${{ steps.versions.outputs.runner-version }}"
131-
132-
# Detect version type (priority: latest > version number > branch/rev prefixes)
133-
if [ "$RUNNER_VERSION" = "latest" ]; then
134-
VERSION_TYPE="latest"
135-
elif echo "$RUNNER_VERSION" | grep -qE '^v?[0-9]+\.[0-9]+\.[0-9]+'; then
136-
# Version number (with or without 'v' prefix)
137-
VERSION_TYPE="release"
138-
# Strip 'v' prefix if present to normalize version format
139-
RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^v//')
140-
elif echo "$RUNNER_VERSION" | grep -q '^branch:'; then
141-
VERSION_TYPE="branch"
142-
RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^branch://')
143-
elif echo "$RUNNER_VERSION" | grep -q '^rev:'; then
144-
VERSION_TYPE="rev"
145-
RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^rev://')
146-
else
147-
# Default to release version
148-
VERSION_TYPE="release"
149-
RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^v//')
150-
fi
162+
VERSION_TYPE="${{ steps.versions.outputs.version-type }}"
151163
152164
# Install the runner
153165
SKIP_HASH_CHECK_WARNING_WARNING="${{ inputs.skip-hash-check-warning }}"
@@ -177,15 +189,18 @@ runs:
177189
INSTALLER_TMP=$(mktemp)
178190
trap "rm -f $INSTALLER_TMP" EXIT
179191
180-
if ! curl -sSL --fail-with-body "$INSTALLER_URL" -o "$INSTALLER_TMP" 2>/dev/null; then
181-
error_msg=$(jq -r '.error // empty' "$INSTALLER_TMP" 2>/dev/null)
182-
install_output=$(cat "$INSTALLER_TMP")
183-
echo "::error title=Failed to install CodSpeed CLI::Installation of CodSpeed CLI with version $RUNNER_VERSION failed.%0AReason: ${error_msg:-$install_output}"
192+
CURL_ERR=$(mktemp)
193+
if ! HTTP_CODE=$(curl -sSL -o "$INSTALLER_TMP" -w "%{http_code}" "$INSTALLER_URL" 2>"$CURL_ERR"); then
194+
echo "::error title=Failed to install CodSpeed CLI::Installation of CodSpeed CLI with version $RUNNER_VERSION failed.%0AReason: $(cat "$CURL_ERR")"
195+
exit 1
196+
fi
197+
if [ "$HTTP_CODE" -ge 400 ]; then
198+
error_body=$(cat "$INSTALLER_TMP")
199+
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}"
184200
exit 1
185201
fi
186202
187-
HASHES_FILE="$GITHUB_ACTION_PATH/.codspeed-runner-installer-hashes.json"
188-
EXPECTED_HASH=$(jq -r --arg v "$RUNNER_VERSION" '.[$v] // empty' "$HASHES_FILE")
203+
EXPECTED_HASH="${{ steps.installer-hash.outputs.hash }}"
189204
if [ -z "$EXPECTED_HASH" ]; then
190205
echo "::error::No pinned hash found for installer version $RUNNER_VERSION. Update .codspeed-runner-installer-hashes.json."
191206
exit 1

0 commit comments

Comments
 (0)