Skip to content

Commit 96e676c

Browse files
committed
fix(release): hydrate fresh Anthropic OAuth access
1 parent a467ceb commit 96e676c

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎scripts/ci-hydrate-live-auth.sh‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,38 @@ write_secret_file() {
2828
chmod 600 "$destination"
2929
}
3030

31+
activate_claude_oauth_access_token() {
32+
local credentials="${OPENCLAW_CLAUDE_CREDENTIALS_JSON:-}"
33+
if [[ -z "$credentials" ]]; then
34+
return
35+
fi
36+
37+
local access_token expires_at now_ms
38+
local min_remaining_ms="$(( 90 * 60 * 1000 ))"
39+
access_token="$(jq -r '.claudeAiOauth.accessToken // empty' <<<"$credentials" 2>/dev/null || true)"
40+
expires_at="$(jq -r '.claudeAiOauth.expiresAt // 0' <<<"$credentials" 2>/dev/null || true)"
41+
now_ms="$(( $(date +%s) * 1000 ))"
42+
43+
if [[ "$access_token" != sk-ant-oat* ]]; then
44+
echo "::warning::Claude credentials JSON has no usable OAuth access token; keeping the configured Anthropic fallback." >&2
45+
return
46+
fi
47+
# Stable live shards can run for an hour, so never shadow the fallback with
48+
# a token that could expire before setup, retries, and cleanup complete.
49+
if ! [[ "$expires_at" =~ ^[0-9]+$ ]] || (( expires_at <= now_ms + min_remaining_ms )); then
50+
echo "::warning::Claude credentials JSON OAuth access token lacks 90 minutes of remaining life; keeping the configured Anthropic fallback." >&2
51+
return
52+
fi
53+
54+
echo "::add-mask::$access_token"
55+
export ANTHROPIC_OAUTH_TOKEN="$access_token"
56+
if [[ -n "${GITHUB_ENV:-}" ]]; then
57+
printf 'ANTHROPIC_OAUTH_TOKEN=%s\n' "$access_token" >>"$GITHUB_ENV"
58+
fi
59+
}
60+
61+
activate_claude_oauth_access_token
62+
3163
for env_key in \
3264
OPENAI_API_KEY \
3365
OPENAI_BASE_URL \

‎test/scripts/package-acceptance-workflow.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,10 +1421,16 @@ describe("package artifact reuse", () => {
14211421
);
14221422
});
14231423

1424-
it("reuses the Claude setup-token for direct Anthropic live provider lanes", () => {
1424+
it("prefers fresh Claude OAuth credentials for direct Anthropic live provider lanes", () => {
14251425
const hydrateScript = readFileSync(CI_HYDRATE_LIVE_AUTH_SCRIPT, "utf8");
14261426

14271427
expect(hydrateScript).toContain(" ANTHROPIC_OAUTH_TOKEN \\");
1428+
expect(hydrateScript).toContain("access_token=\"$(jq -r '.claudeAiOauth.accessToken // empty'");
1429+
expect(hydrateScript).toContain('export ANTHROPIC_OAUTH_TOKEN="$access_token"');
1430+
expect(hydrateScript).toContain('local min_remaining_ms="$(( 90 * 60 * 1000 ))"');
1431+
expect(hydrateScript).toContain(
1432+
'printf \'ANTHROPIC_OAUTH_TOKEN=%s\\n\' "$access_token" >>"$GITHUB_ENV"',
1433+
);
14281434
for (const jobName of [
14291435
"validate_live_models_docker",
14301436
"validate_live_models_docker_targeted",

0 commit comments

Comments
 (0)