Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 14 additions & 2 deletions action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"
Expand Down
Loading