diff options
-rw-r--r-- | .changeset/happy-pumpkins-rescue.md | 5 | ||||
-rw-r--r-- | packages/db/package.json | 1 | ||||
-rw-r--r-- | packages/db/src/core/errors.ts | 4 | ||||
-rw-r--r-- | packages/db/src/core/tokens.ts | 14 | ||||
-rw-r--r-- | pnpm-lock.yaml | 3 |
5 files changed, 23 insertions, 4 deletions
diff --git a/.changeset/happy-pumpkins-rescue.md b/.changeset/happy-pumpkins-rescue.md new file mode 100644 index 000000000..c43a15751 --- /dev/null +++ b/.changeset/happy-pumpkins-rescue.md @@ -0,0 +1,5 @@ +--- +"@astrojs/db": patch +--- + +Provide a better error message when app token is missing in CI diff --git a/packages/db/package.json b/packages/db/package.json index 827558c7a..e83e40790 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -72,6 +72,7 @@ "dependencies": { "@libsql/client": "^0.6.0", "async-listen": "^3.0.1", + "ci-info": "^4.0.0", "deep-diff": "^1.0.2", "drizzle-orm": "^0.30.9", "github-slugger": "^2.0.0", diff --git a/packages/db/src/core/errors.ts b/packages/db/src/core/errors.ts index 655cbbf38..1dfbc4e03 100644 --- a/packages/db/src/core/errors.ts +++ b/packages/db/src/core/errors.ts @@ -1,5 +1,9 @@ import { bold, cyan, red } from 'kleur/colors'; +export const MISSING_SESSION_ID_CI_ERROR = `${red('▶ ASTRO_STUDIO_APP_TOKEN required')} + + To authenticate with Astro Studio add the token to your CI's environment variables.\n`; + export const MISSING_SESSION_ID_ERROR = `${red('▶ Login required!')} To authenticate with Astro Studio, run diff --git a/packages/db/src/core/tokens.ts b/packages/db/src/core/tokens.ts index 2c75e3723..e1c33bf73 100644 --- a/packages/db/src/core/tokens.ts +++ b/packages/db/src/core/tokens.ts @@ -5,8 +5,9 @@ import { pathToFileURL } from 'node:url'; import { green } from 'kleur/colors'; import ora from 'ora'; import { safeFetch } from '../runtime/utils.js'; -import { MISSING_PROJECT_ID_ERROR, MISSING_SESSION_ID_ERROR } from './errors.js'; +import { MISSING_PROJECT_ID_ERROR, MISSING_SESSION_ID_CI_ERROR, MISSING_SESSION_ID_ERROR } from './errors.js'; import { getAstroStudioEnv, getAstroStudioUrl } from './utils.js'; +import ci from 'ci-info'; export const SESSION_LOGIN_FILE = pathToFileURL(join(homedir(), '.astro', 'session-token')); export const PROJECT_ID_FILE = pathToFileURL(join(process.cwd(), '.astro', 'link')); @@ -182,12 +183,17 @@ export async function getManagedAppTokenOrExit(token?: string): Promise<ManagedA } const sessionToken = await getSessionIdFromFile(); if (!sessionToken) { - // eslint-disable-next-line no-console - console.error(MISSING_SESSION_ID_ERROR); + if(ci.isCI) { + // eslint-disable-next-line no-console + console.error(MISSING_SESSION_ID_CI_ERROR); + } else { + // eslint-disable-next-line no-console + console.error(MISSING_SESSION_ID_ERROR); + } process.exit(1); } const projectId = await getProjectIdFromFile(); - if (!sessionToken || !projectId) { + if (!projectId) { // eslint-disable-next-line no-console console.error(MISSING_PROJECT_ID_ERROR); process.exit(1); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aac8da8c9..ce5f061d9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3874,6 +3874,9 @@ importers: async-listen: specifier: ^3.0.1 version: 3.0.1 + ci-info: + specifier: ^4.0.0 + version: 4.0.0 deep-diff: specifier: ^1.0.2 version: 1.0.2 |