Skip to content

Commit df6b8a8

Browse files
committed
Added a missing action.
1 parent 1012555 commit df6b8a8

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Resolve API commit/version
2+
description: Resolve deployed API commit SHA and version from the metadata endpoint
3+
inputs:
4+
api_base_url:
5+
description: Base URL host for the API (e.g. api-dev.mobilitydatabase.org)
6+
required: false
7+
default: api.mobilitydatabase.org
8+
api_refresh_token:
9+
description: API refresh token
10+
required: false
11+
outputs:
12+
COMMIT_SHA:
13+
description: Resolved commit SHA
14+
value: ${{ steps.resolve.outputs.COMMIT_SHA }}
15+
API_VERSION:
16+
description: Resolved API version
17+
value: ${{ steps.resolve.outputs.API_VERSION }}
18+
runs:
19+
using: composite
20+
steps:
21+
- id: resolve
22+
name: Resolve via API and expose outputs
23+
shell: bash
24+
env:
25+
API_BASE_URL: ${{ inputs.api_base_url }}
26+
API_REFRESH_TOKEN: ${{ inputs.api_refresh_token }}
27+
run: |
28+
set -euo pipefail
29+
COMMIT_SHA=""
30+
API_VERSION=""
31+
if [[ -n "${API_REFRESH_TOKEN:-}" ]]; then
32+
echo "Resolving API commit from https://${API_BASE_URL}/v1/metadata ..."
33+
REPLY_JSON=$(curl --fail --silent --show-error --location "https://${API_BASE_URL}/v1/tokens" \
34+
--header 'Content-Type: application/json' \
35+
--data "{ \"refresh_token\": \"${API_REFRESH_TOKEN}\" }")
36+
ACCESS_TOKEN=$(echo "${REPLY_JSON}" | jq -r .access_token)
37+
if [[ -z "${ACCESS_TOKEN}" || "${ACCESS_TOKEN}" == "null" ]]; then
38+
echo "Error: Could not obtain access token from reply" >&2
39+
exit 1
40+
fi
41+
META_JSON=$(curl --fail --silent --show-error \
42+
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
43+
-H 'accept: application/json' \
44+
"https://${API_BASE_URL}/v1/metadata")
45+
COMMIT_SHA=$(echo "${META_JSON}" | jq -r .commit_hash)
46+
API_VERSION=$(echo "${META_JSON}" | jq -r .version)
47+
if [[ -z "${COMMIT_SHA}" || "${COMMIT_SHA}" == "null" ]]; then
48+
echo "Error: Could not extract commit_hash from metadata" >&2
49+
echo "Metadata reply: ${META_JSON}" >&2
50+
exit 1
51+
fi
52+
echo "Resolved API version: ${API_VERSION} (commit ${COMMIT_SHA})"
53+
else
54+
echo "No token provided; skipping API metadata resolution."
55+
fi
56+
echo "COMMIT_SHA=${COMMIT_SHA}"
57+
echo "API_VERSION=${API_VERSION}"
58+
echo "COMMIT_SHA=${COMMIT_SHA}" >> "$GITHUB_OUTPUT"
59+
echo "API_VERSION=${API_VERSION}" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)