From f33bb0b031a4354c62c46b58f683a9a5ce9b4e53 Mon Sep 17 00:00:00 2001 From: Natty Linden Date: Thu, 15 Oct 2026 00:14:26 +0000 Subject: [PATCH] Revert use of newer curl arguments to simplify curling for API responses Runners like linux-large using Ubuntu 22.04 do, in fact, have a curl too old to have `--fail-with-body` or `--json`. --- .github/workflows/test.yaml | 6 ++++-- action.sh | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 24bd51e..4acae85 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -28,15 +28,17 @@ jobs: # One or more test cases run in a container, so we can tell that the # Action works when run in a containerized job. image: ${{ matrix.container-image }} - runs-on: ubuntu-latest + runs-on: ${{ matrix.runs-on || 'ubuntu-latest' }} strategy: # Finish all test cases even once one of them fails. fail-fast: false matrix: - case: [runner, container] + case: [runner, runner-old, container] include: - case: container container-image: python:3.12 + - case: runner-old + runs-on: linux-large steps: - uses: actions/checkout@v7 diff --git a/action.sh b/action.sh index 6050460..158930b 100755 --- a/action.sh +++ b/action.sh @@ -2,8 +2,20 @@ set -euxo pipefail +# https://superuser.com/a/1641410 +curlf() { + output_file=$(mktemp) + code="$(curl --silent --output "$output_file" --write-out "%{http_code}" "$@")" + if [[ "$code" -lt 200 || "$code" -gt 299 ]]; then + >&2 cat "$output_file" + return 22 + fi + cat "$output_file" + rm "$output_file" +} + request() { - if ! resp="$(curl --silent --fail-with-body "$@")" + if ! resp="$(curlf "$@")" then curl_exit_code="$?" echo "$resp" >&2 @@ -40,7 +52,7 @@ CLOUDSMITH_ACCOUNT=${CLOUDSMITH_ACCOUNT:-$GITHUB_REPOSITORY_OWNER} echo "Retrieving actions OIDC token" id_token=$(request -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=api://AzureADTokenExchange" | pluck_field value) echo "Retrieving Cloudsmith token for account: $CLOUDSMITH_ACCOUNT (service account: $SERVICE_SLUG)" -cloudsmith_token=$(request --json '{"oidc_token":"'"$id_token"'", "service_slug":"'"$SERVICE_SLUG"'"}' "https://api.cloudsmith.io/openid/$CLOUDSMITH_ACCOUNT/" | pluck_field token) +cloudsmith_token=$(request -X POST -H "Content-Type: application/json" -d '{"oidc_token":"'"$id_token"'", "service_slug":"'"$SERVICE_SLUG"'"}' "https://api.cloudsmith.io/openid/$CLOUDSMITH_ACCOUNT/" | pluck_field token) echo "value=$cloudsmith_token" >> "$GITHUB_OUTPUT" file="$(mktemp)"