diff --git a/.changeset/happy-pumpkins-rescue.md b/.changeset/happy-pumpkins-rescue.md new file mode 100644 index 0000000000..c43a157511 --- /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 827558c7af..e83e407905 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 655cbbf380..1dfbc4e03d 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 2c75e37230..e1c33bf736 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