Skip to content

Commit 90773f7

Browse files
committed
refactor(showcase): use shared railway token resolver and SSOT IDs in deploy-to-railway
Replace the divergent getToken with resolveRailwayToken; source project/env IDs from the railway-envs SSOT; read the GHCR username from env (trimmed, fail-loud) instead of a hardcoded handle.
1 parent 722e411 commit 90773f7

1 file changed

Lines changed: 34 additions & 18 deletions

File tree

showcase/scripts/deploy-to-railway.ts

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import path from "path";
1919
import yaml from "yaml";
2020
import { fileURLToPath } from "url";
2121
import { RAILWAY_GRAPHQL_ENDPOINT } from "./lib/railway-graphql";
22+
import { RailwayTokenError, resolveRailwayToken } from "./lib/railway-token";
23+
import { PROJECT_ID, PRODUCTION_ENV_ID } from "./railway-envs";
2224

2325
const __dirname = path.dirname(fileURLToPath(import.meta.url));
2426
const ROOT = path.resolve(__dirname, "..");
@@ -27,27 +29,27 @@ const PACKAGES_DIR = path.join(ROOT, "integrations");
2729
const RAILWAY_API = RAILWAY_GRAPHQL_ENDPOINT;
2830

2931
const SHOWCASE = {
30-
projectId: "6f8c6bff-a80d-4f8f-b78d-50b32bcf4479",
31-
environmentId: "b14919f4-6417-429f-848d-c6ae2201e04f",
32+
projectId: PROJECT_ID,
33+
environmentId: PRODUCTION_ENV_ID,
3234
};
3335

36+
/**
37+
* Resolve the Railway bearer token for this run. Wraps the shared
38+
* `resolveRailwayToken` envelope and maps any RailwayTokenError onto
39+
* the script's exit-1 contract for operator/config errors. The shared
40+
* helper never calls process.exit — exit-code mapping lives HERE so the
41+
* helper stays unit-testable.
42+
*/
3443
function getToken(): string {
35-
if (process.env.RAILWAY_TOKEN) return process.env.RAILWAY_TOKEN;
36-
37-
const configPath = path.join(
38-
process.env.HOME || "~",
39-
".railway",
40-
"config.json",
41-
);
42-
if (fs.existsSync(configPath)) {
43-
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
44-
if (config?.user?.token) return config.user.token;
44+
try {
45+
return resolveRailwayToken().token;
46+
} catch (e) {
47+
if (e instanceof RailwayTokenError) {
48+
console.error(e.message);
49+
process.exit(1);
50+
}
51+
throw e;
4552
}
46-
47-
console.error(
48-
"No Railway token found. Set RAILWAY_TOKEN or run `railway login`.",
49-
);
50-
process.exit(1);
5153
}
5254

5355
async function railwayGql<T = unknown>(
@@ -200,8 +202,22 @@ async function createService(slug: string): Promise<void> {
200202
region: "us-west1",
201203
};
202204
if (githubToken) {
205+
// GHCR registry username: read from env (GHCR_USERNAME preferred, then
206+
// GITHUB_ACTOR for CI contexts). Fail loud rather than baking a
207+
// personal handle into the script.
208+
const ghcrUser = (
209+
process.env.GHCR_USERNAME ??
210+
process.env.GITHUB_ACTOR ??
211+
""
212+
).trim();
213+
if (!ghcrUser) {
214+
console.error(
215+
"GITHUB_TOKEN is set but no GHCR username is available. Set GHCR_USERNAME (or GITHUB_ACTOR in CI) to the username the token is issued to.",
216+
);
217+
process.exit(1);
218+
}
203219
instanceInput.registryCredentials = {
204-
username: "jpr5",
220+
username: ghcrUser,
205221
password: githubToken,
206222
};
207223
}

0 commit comments

Comments
 (0)