Skip to content

Commit

Permalink
Provide a better error for when the app token is missing in CI (#10918)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored Apr 30, 2024
1 parent fd7a9ed commit ca605f4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-pumpkins-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---

Provide a better error message when app token is missing in CI
1 change: 1 addition & 0 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/db/src/core/errors.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 10 additions & 4 deletions packages/db/src/core/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ca605f4

Please sign in to comment.