Skip to content

Commit d42dfe1

Browse files
committed
use local supabase in github test
1 parent 4340713 commit d42dfe1

4 files changed

Lines changed: 34 additions & 17 deletions

File tree

.github/workflows/test-database.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: "functions-tests"
22
on:
33
pull_request:
4+
env:
5+
SUPABASE_USE_DB: local
6+
SUPABASE_PROJECT_ID: test
7+
GITHUB_TEST: test
48

59
jobs:
610
build:

packages/database/scripts/createEnv.mts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ const getVercelToken = () => {
2929
};
3030

3131
const makeFnEnv = (envTxt: string): string => {
32-
return envTxt.split('\n').filter(l=>l.match(/^SUPABASE_\w+_KEY/)).map((l)=> l.replace('SUPABASE_', 'SB_')).join('\n');
33-
}
32+
return envTxt
33+
.split("\n")
34+
.filter((l) => l.match(/^SUPABASE_\w+_KEY/))
35+
.map((l) => l.replace("SUPABASE_", "SB_"))
36+
.join("\n");
37+
};
3438

3539
const makeLocalEnv = () => {
3640
execSync("supabase start", {
37-
cwd: projectRoot, stdio: "inherit"
41+
cwd: projectRoot,
42+
stdio: "inherit",
3843
});
3944
const stdout = execSync("supabase status -o env", {
4045
encoding: "utf8",
@@ -54,8 +59,8 @@ const makeLocalEnv = () => {
5459
);
5560
writeFileSync(
5661
join(projectRoot, "supabase/functions/.env"),
57-
makeFnEnv(prefixed)
58-
)
62+
makeFnEnv(prefixed),
63+
);
5964
};
6065

6166
const makeBranchEnv = async (vercel: Vercel, vercelToken: string) => {
@@ -94,11 +99,11 @@ const makeBranchEnv = async (vercel: Vercel, vercelToken: string) => {
9499
throw err;
95100
}
96101
appendFileSync(".env.branch", `NEXT_API_ROOT="https://${url}/api"\n`);
97-
const fromVercel = readFileSync('.env.branch').toString();
102+
const fromVercel = readFileSync(".env.branch").toString();
98103
writeFileSync(
99104
join(projectRoot, "supabase/functions/.env"),
100-
makeFnEnv(fromVercel)
101-
)
105+
makeFnEnv(fromVercel),
106+
);
102107
};
103108

104109
const makeProductionEnv = async (vercel: Vercel, vercelToken: string) => {
@@ -117,33 +122,37 @@ const makeProductionEnv = async (vercel: Vercel, vercelToken: string) => {
117122
`vercel -t ${vercelToken} env pull --environment production .env.production`,
118123
);
119124
appendFileSync(".env.production", `NEXT_API_ROOT="https://${url}/api"\n`);
120-
const fromVercel = readFileSync('.env.production').toString();
125+
const fromVercel = readFileSync(".env.production").toString();
121126
writeFileSync(
122127
join(projectRoot, "supabase/functions/.env"),
123-
makeFnEnv(fromVercel)
124-
)
128+
makeFnEnv(fromVercel),
129+
);
125130
};
126131

127132
const main = async (variant: Variant) => {
128133
if (process.env.ROAM_BUILD_SCRIPT) {
129134
// special case: production build
130135
try {
131-
const response = execSync('curl https://discoursegraphs.com/api/supabase/env');
136+
const response = execSync(
137+
"curl https://discoursegraphs.com/api/supabase/env",
138+
);
132139
const asJson = JSON.parse(response.toString()) as Record<string, string>;
133140
writeFileSync(
134141
join(projectRoot, ".env"),
135-
Object.entries(asJson).map(([k,v])=>`${k}=${v}`).join('\n')
142+
Object.entries(asJson)
143+
.map(([k, v]) => `${k}=${v}`)
144+
.join("\n"),
136145
);
137146
return;
138147
} catch (e) {
139148
if (process.env.SUPABASE_URL && process.env.SUPABASE_PUBLISHABLE_KEY)
140149
return;
141150
throw new Error("Could not get environment from site");
142151
}
143-
}
144-
else if (
152+
} else if (
145153
process.env.HOME === "/vercel" ||
146-
process.env.GITHUB_ACTIONS !== undefined
154+
(process.env.GITHUB_ACTIONS !== undefined &&
155+
process.env.GITHUB_TEST !== "test")
147156
)
148157
// Do not execute in deployment or github action.
149158
return;

packages/database/scripts/migrate.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { getVariant } from "@repo/database/dbDotEnv";
66
const __dirname = dirname(__filename);
77
const projectRoot = join(__dirname, "..");
88

9-
if (process.env.HOME === "/vercel" || process.env.GITHUB_ACTIONS === "true") {
9+
if (
10+
process.env.HOME === "/vercel" ||
11+
(process.env.GITHUB_ACTIONS === "true" && process.env.GITHUB_TEST !== "test")
12+
) {
1013
console.log("Skipping in production environment");
1114
process.exit(0);
1215
}

turbo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"GEMINI_API_KEY",
3030
"GH_CLIENT_SECRET_PROD",
3131
"GITHUB_ACTIONS",
32+
"GITHUB_TEST",
3233
"HOME",
3334
"OPENAI_API_KEY",
3435
"POSTGRES_PASSWORD",

0 commit comments

Comments
 (0)