Skip to content

Commit 6efc998

Browse files
author
latdx-mirror-bot
committed
ci: overlay fork CI for upstream PR jongpie#994
Upstream-SHA: b4a6561 Fork-CI-Tree: 5d7cf77
1 parent b4a6561 commit 6efc998

4 files changed

Lines changed: 519 additions & 107 deletions

File tree

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: 'LATdx Apex Tests'
2+
description: >-
3+
Install the LATdx CLI, resolve a license (explicit key via the
4+
LATDX_LICENSE_KEY env var, or a short-lived OSS license minted from the
5+
GitHub Actions OIDC token on public repos), and run the full local Apex
6+
test suite against the job's default Salesforce org.
7+
8+
inputs:
9+
cli-version:
10+
description: "LATdx CLI version to install (semver like '0.31.1') or 'latest'."
11+
required: false
12+
default: 'latest'
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: 'Install LATdx CLI'
18+
shell: bash
19+
env:
20+
CLI_VERSION: ${{ inputs.cli-version }}
21+
run: |
22+
set -euo pipefail
23+
if [[ ! "$CLI_VERSION" =~ ^(latest|[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
24+
echo "::error::Invalid 'cli-version' input. Must be 'latest' or a semver like '0.31.1'."
25+
exit 1
26+
fi
27+
# latdx.com serves the maintained install script, but Cloudflare
28+
# returns 403 to some hosted-runner egress IP ranges; fall back to
29+
# the GitHub raw mirror so the install succeeds from any runner.
30+
script=""
31+
for url in "https://latdx.com/install.sh" "https://raw.githubusercontent.com/nebulity/latdx-cli/main/install.sh"; do
32+
if script="$(curl -fsSL "$url")"; then
33+
break
34+
fi
35+
script=""
36+
done
37+
if [ -z "$script" ]; then
38+
echo "::error::Could not download the LATdx install script from any source."
39+
exit 1
40+
fi
41+
if [ "$CLI_VERSION" = "latest" ]; then
42+
printf '%s' "$script" | bash
43+
else
44+
printf '%s' "$script" | bash -s -- "$CLI_VERSION"
45+
fi
46+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
47+
48+
- name: 'Verify LATdx CLI'
49+
shell: bash
50+
run: latdx --version
51+
52+
- name: 'Resolve LATdx license'
53+
shell: bash
54+
run: |
55+
set -uo pipefail
56+
57+
# Precedence:
58+
# 1. LATDX_LICENSE_KEY already in the environment (repo secret) -> use it.
59+
# 2. GH OIDC token available + repo public -> exchange for an OSS
60+
# auto-license via https://latdx.com/api/oss/license.
61+
# 3. Nothing -> daemon runs free-tier (capped at 100 tests, exit 2).
62+
63+
if [ -n "${LATDX_LICENSE_KEY:-}" ]; then
64+
echo "Using LATdx license from environment."
65+
exit 0
66+
fi
67+
68+
if [ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ] || [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ]; then
69+
echo "::warning title=LATdx OSS license::OIDC token unavailable (missing 'permissions: id-token: write' on the job). Free-tier cap (100 tests/run) applies."
70+
exit 0
71+
fi
72+
73+
OIDC_RESPONSE="$(curl -sS -f -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
74+
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=https%3A%2F%2Flatdx.com" || true)"
75+
OIDC_TOKEN="$(echo "$OIDC_RESPONSE" | jq -r '.value // empty')"
76+
if [ -z "$OIDC_TOKEN" ]; then
77+
echo "::warning title=LATdx OSS license::Failed to mint GitHub OIDC token; falling back to free-tier cap."
78+
exit 0
79+
fi
80+
81+
EXCHANGE_BODY="$(mktemp)"
82+
trap 'rm -f "$EXCHANGE_BODY"' EXIT
83+
HTTP_CODE="$(curl -sS -o "$EXCHANGE_BODY" -w "%{http_code}" \
84+
-X POST https://latdx.com/api/oss/license \
85+
-H "Authorization: Bearer $OIDC_TOKEN" \
86+
-H "Content-Type: application/json" \
87+
--max-time 15 || echo "000")"
88+
89+
case "$HTTP_CODE" in
90+
200)
91+
LATDX_JWT="$(jq -r '.license // empty' < "$EXCHANGE_BODY")"
92+
if [ -z "$LATDX_JWT" ]; then
93+
echo "::warning title=LATdx OSS license::Exchange returned 200 without a license; falling back to free-tier cap."
94+
exit 0
95+
fi
96+
echo "::add-mask::$LATDX_JWT"
97+
echo "LATDX_LICENSE_KEY=$LATDX_JWT" >> "$GITHUB_ENV"
98+
USED="$(jq -r '.monthly_used // "?"' < "$EXCHANGE_BODY")"
99+
CAP="$(jq -r '.monthly_cap // "?"' < "$EXCHANGE_BODY")"
100+
echo "OSS auto-license active (monthly_used=$USED, monthly_cap=$CAP) - free-tier cap lifted for this run."
101+
;;
102+
403)
103+
REASON="$(jq -r '.reason // "denied"' < "$EXCHANGE_BODY")"
104+
ERROR="$(jq -r '.error // "OSS license denied."' < "$EXCHANGE_BODY")"
105+
echo "::warning title=LATdx OSS license::${ERROR} (reason=${REASON}). Free-tier cap (100 tests/run) applies."
106+
;;
107+
429)
108+
USED="$(jq -r '.monthly_used // "?"' < "$EXCHANGE_BODY")"
109+
CAP="$(jq -r '.monthly_cap // "?"' < "$EXCHANGE_BODY")"
110+
RESET="$(jq -r '.reset_at // "next UTC month"' < "$EXCHANGE_BODY")"
111+
echo "::warning title=LATdx OSS license::Monthly cap reached (${USED}/${CAP}); resets ${RESET}. Free-tier cap applies for this run."
112+
;;
113+
503)
114+
echo "::warning title=LATdx OSS license::OSS path temporarily unavailable. Free-tier cap applies for this run."
115+
;;
116+
000)
117+
echo "::warning title=LATdx OSS license::Could not reach the LATdx site. Free-tier cap applies for this run."
118+
;;
119+
*)
120+
ERROR="$(jq -r '.error // ""' < "$EXCHANGE_BODY")"
121+
echo "::warning title=LATdx OSS license::Unexpected response ${HTTP_CODE} from /api/oss/license (${ERROR}). Free-tier cap applies."
122+
;;
123+
esac
124+
125+
- name: 'Run Apex tests with LATdx'
126+
shell: bash
127+
run: latdx test run

0 commit comments

Comments
 (0)