Skip to content

Commit ec8fdf5

Browse files
committed
Used the main branch if for any reason we can't obtain the current commit hash.
1 parent 0140b45 commit ec8fdf5

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

.github/actions/resolve-api-meta/action.yml

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,53 @@ runs:
2828
API_BASE_URL: ${{ inputs.api_base_url }}
2929
API_REFRESH_TOKEN: ${{ inputs.api_refresh_token }}
3030
run: |
31-
set -euo pipefail
31+
# Do not exit on failure; this action should never abort the caller workflow.
32+
set -u
3233
COMMIT_SHA=""
3334
API_VERSION=""
3435
RESOLVED="false"
36+
3537
if [[ -n "${API_REFRESH_TOKEN:-}" ]]; then
3638
echo "Resolving API commit from https://${API_BASE_URL}/v1/metadata ..."
37-
REPLY_JSON=$(curl --fail --silent --show-error --location "https://${API_BASE_URL}/v1/tokens" \
39+
40+
# Exchange refresh token -> access token (handle failures gracefully)
41+
REPLY_JSON=$(curl --silent --show-error --location "https://${API_BASE_URL}/v1/tokens" \
3842
--header 'Content-Type: application/json' \
39-
--data "{ \"refresh_token\": \"${API_REFRESH_TOKEN}\" }")
40-
ACCESS_TOKEN=$(echo "${REPLY_JSON}" | jq -r .access_token)
41-
if [[ -z "${ACCESS_TOKEN}" || "${ACCESS_TOKEN}" == "null" ]]; then
42-
echo "Error: Could not obtain access token from reply" >&2
43-
exit 1
43+
--data "{ \"refresh_token\": \"${API_REFRESH_TOKEN}\" }" ) || {
44+
echo "Warning: token exchange failed; will fallback to 'main'" >&2
45+
REPLY_JSON=""
46+
}
47+
48+
if [[ -n "${REPLY_JSON}" ]]; then
49+
ACCESS_TOKEN=$(echo "${REPLY_JSON}" | jq -r .access_token 2>/dev/null || echo "")
50+
if [[ -z "${ACCESS_TOKEN}" || "${ACCESS_TOKEN}" == "null" ]]; then
51+
echo "Warning: Could not obtain access token from reply; will fallback to 'main'" >&2
52+
else
53+
META_JSON=$(curl --silent --show-error \
54+
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
55+
-H 'accept: application/json' \
56+
"https://${API_BASE_URL}/v1/metadata" ) || {
57+
echo "Warning: metadata request failed; will fallback to 'main'" >&2
58+
META_JSON=""
59+
}
60+
61+
if [[ -n "${META_JSON}" ]]; then
62+
COMMIT_SHA=$(echo "${META_JSON}" | jq -r .commit_hash 2>/dev/null || echo "")
63+
API_VERSION=$(echo "${META_JSON}" | jq -r .version 2>/dev/null || echo "")
64+
if [[ -n "${COMMIT_SHA}" && "${COMMIT_SHA}" != "null" ]]; then
65+
RESOLVED="true"
66+
echo "Resolved API version: ${API_VERSION} (commit ${COMMIT_SHA})"
67+
else
68+
echo "Warning: commit_hash missing in metadata; will fallback to 'main'" >&2
69+
fi
70+
fi
71+
fi
4472
fi
45-
META_JSON=$(curl --fail --silent --show-error \
46-
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
47-
-H 'accept: application/json' \
48-
"https://${API_BASE_URL}/v1/metadata")
49-
COMMIT_SHA=$(echo "${META_JSON}" | jq -r .commit_hash)
50-
API_VERSION=$(echo "${META_JSON}" | jq -r .version)
51-
if [[ -z "${COMMIT_SHA}" || "${COMMIT_SHA}" == "null" ]]; then
52-
echo "Error: Could not extract commit_hash from metadata" >&2
53-
echo "Metadata reply: ${META_JSON}" >&2
54-
exit 1
55-
fi
56-
RESOLVED="true"
57-
echo "Resolved API version: ${API_VERSION} (commit ${COMMIT_SHA})"
5873
else
59-
echo "Error: no API refresh token provided; cannot resolve deployed commit." >&2
60-
exit 1
74+
echo "No API refresh token provided; skipping API metadata resolution and falling back to 'main'."
6175
fi
62-
echo "COMMIT_SHA=${COMMIT_SHA}"
63-
echo "API_VERSION=${API_VERSION}"
64-
echo "RESOLVED=${RESOLVED}"
76+
77+
# Expose outputs (empty COMMIT_SHA and RESOLVED=false indicate fallback to 'main')
6578
echo "COMMIT_SHA=${COMMIT_SHA}" >> "$GITHUB_OUTPUT"
6679
echo "API_VERSION=${API_VERSION}" >> "$GITHUB_OUTPUT"
6780
echo "RESOLVED=${RESOLVED}" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)