Skip to content

Commit 52a3d24

Browse files
committed
ci(e2e): extract instance-key resolution into Node helper
1 parent 605ee4e commit 52a3d24

2 files changed

Lines changed: 53 additions & 26 deletions

File tree

.github/workflows/mobile-e2e.yml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,7 @@ jobs:
7070
id: keys
7171
env:
7272
INTEGRATION_STAGING_INSTANCE_KEYS: ${{ secrets.INTEGRATION_STAGING_INSTANCE_KEYS }}
73-
run: |
74-
if [ -z "$INTEGRATION_STAGING_INSTANCE_KEYS" ]; then
75-
echo "::error::INTEGRATION_STAGING_INSTANCE_KEYS secret is not set"
76-
exit 1
77-
fi
78-
pk=$(echo "$INTEGRATION_STAGING_INSTANCE_KEYS" | jq -er ".[\"$EXPO_INSTANCE_NAME\"].pk") || {
79-
echo "::error::No entry '$EXPO_INSTANCE_NAME' found in INTEGRATION_STAGING_INSTANCE_KEYS"
80-
exit 1
81-
}
82-
sk=$(echo "$INTEGRATION_STAGING_INSTANCE_KEYS" | jq -er ".[\"$EXPO_INSTANCE_NAME\"].sk")
83-
echo "::add-mask::$sk"
84-
echo "pk=$pk" >> "$GITHUB_OUTPUT"
85-
echo "sk=$sk" >> "$GITHUB_OUTPUT"
73+
run: node scripts/resolve-instance-keys.mjs INTEGRATION_STAGING_INSTANCE_KEYS "$EXPO_INSTANCE_NAME"
8674

8775
- name: Write quickstart .env
8876
working-directory: clerk-expo-quickstart/NativeComponentQuickstart
@@ -187,19 +175,7 @@ jobs:
187175
id: keys
188176
env:
189177
INTEGRATION_STAGING_INSTANCE_KEYS: ${{ secrets.INTEGRATION_STAGING_INSTANCE_KEYS }}
190-
run: |
191-
if [ -z "$INTEGRATION_STAGING_INSTANCE_KEYS" ]; then
192-
echo "::error::INTEGRATION_STAGING_INSTANCE_KEYS secret is not set"
193-
exit 1
194-
fi
195-
pk=$(echo "$INTEGRATION_STAGING_INSTANCE_KEYS" | jq -er ".[\"$EXPO_INSTANCE_NAME\"].pk") || {
196-
echo "::error::No entry '$EXPO_INSTANCE_NAME' found in INTEGRATION_STAGING_INSTANCE_KEYS"
197-
exit 1
198-
}
199-
sk=$(echo "$INTEGRATION_STAGING_INSTANCE_KEYS" | jq -er ".[\"$EXPO_INSTANCE_NAME\"].sk")
200-
echo "::add-mask::$sk"
201-
echo "pk=$pk" >> "$GITHUB_OUTPUT"
202-
echo "sk=$sk" >> "$GITHUB_OUTPUT"
178+
run: node scripts/resolve-instance-keys.mjs INTEGRATION_STAGING_INSTANCE_KEYS "$EXPO_INSTANCE_NAME"
203179

204180
- name: Write quickstart .env
205181
working-directory: clerk-expo-quickstart/NativeComponentQuickstart

scripts/resolve-instance-keys.mjs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Resolves Clerk pk/sk for a named test instance from a JSON-encoded env var
5+
* (e.g. INTEGRATION_INSTANCE_KEYS / INTEGRATION_STAGING_INSTANCE_KEYS).
6+
*
7+
* Usage:
8+
* node scripts/resolve-instance-keys.mjs <SECRET_ENV_VAR> <INSTANCE_NAME>
9+
*
10+
* Writes pk and sk as GitHub Actions step outputs to $GITHUB_OUTPUT and masks
11+
* sk in the runner logs. Exits non-zero with a ::error:: annotation if the
12+
* env var is missing, malformed, or doesn't contain the requested instance.
13+
*/
14+
15+
import { appendFileSync } from 'node:fs';
16+
17+
const fail = msg => {
18+
console.error(`::error::${msg}`);
19+
process.exit(1);
20+
};
21+
22+
const [, , secretVar, instanceName] = process.argv;
23+
if (!secretVar || !instanceName) {
24+
fail('Usage: resolve-instance-keys.mjs <SECRET_ENV_VAR> <INSTANCE_NAME>');
25+
}
26+
27+
const raw = process.env[secretVar];
28+
if (!raw) fail(`${secretVar} secret is not set`);
29+
30+
let parsed;
31+
try {
32+
parsed = JSON.parse(raw);
33+
} catch (err) {
34+
fail(`Failed to parse ${secretVar} as JSON: ${err.message}`);
35+
}
36+
37+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
38+
fail(`Expected ${secretVar} to be a JSON object of instance entries`);
39+
}
40+
41+
const entry = parsed[instanceName];
42+
if (!entry) fail(`No entry '${instanceName}' found in ${secretVar}`);
43+
44+
const { pk, sk } = entry;
45+
if (!pk) fail(`Entry '${instanceName}' in ${secretVar} is missing 'pk'`);
46+
if (!sk) fail(`Entry '${instanceName}' in ${secretVar} is missing 'sk'`);
47+
48+
console.log(`::add-mask::${sk}`);
49+
50+
const out = process.env.GITHUB_OUTPUT;
51+
if (out) appendFileSync(out, `pk=${pk}\nsk=${sk}\n`);

0 commit comments

Comments
 (0)