-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-681 Automate database testing #957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maparent
wants to merge
7
commits into
main
Choose a base branch
from
eng-681-automate-database-testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c270f6b
ENG-681 first trial
maparent 5b2a911
replace outdated cache library
maparent 2ae0701
require appropriate vars
maparent 031640a
lint corrections
maparent 222f86b
AI corrections
maparent a28e59d
disable docker cache
maparent 536026a
Devin corrections
maparent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: Database tests | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "packages/database/**" | ||
| env: | ||
| SUPABASE_USE_DB: local | ||
| SUPABASE_PROJECT_ID: test | ||
| GITHUB_TEST: test | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 10.15.1 | ||
| run_install: false | ||
| - name: Setup node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "20" | ||
| cache: "pnpm" | ||
| - name: Install Dependencies | ||
| run: pnpm install --frozen-lockfile | ||
| # - name: Get supabase version | ||
| # working-directory: ./packages/database | ||
| # run: echo "SUPABASE_VERSION=$(./node_modules/.bin/supabase --version)" >> $GITHUB_ENV | ||
| # - name: Cache Docker images. | ||
| # uses: AndreKurait/docker-cache@0.6.0 | ||
| # with: | ||
| # key: docker-${{ runner.os }}-${{ env.SUPABASE_VERSION }} | ||
| - name: Setup database | ||
| working-directory: ./packages/database | ||
| run: pnpm run setup | ||
| - name: Serve and run tests | ||
| working-directory: ./packages/database | ||
| run: pnpm run test:withserve |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { spawn, execSync } from "node:child_process"; | ||
| import { join, dirname } from "path"; | ||
|
|
||
| const scriptDir = dirname(__filename); | ||
| const projectRoot = join(scriptDir, ".."); | ||
|
|
||
| if ( | ||
| process.env.GITHUB_ACTIONS === "true" && | ||
| process.env.GITHUB_TEST !== "test" | ||
| ) { | ||
| console.error("Please set the GITHUB_TEST variable to 'test'"); | ||
| process.exit(2); | ||
| } | ||
| if (process.env.SUPABASE_PROJECT_ID !== "test") { | ||
| console.error("Please set the SUPABASE_PROJECT_ID variable to 'test'"); | ||
| process.exit(2); | ||
| } | ||
|
|
||
| const serve = spawn("supabase", ["functions", "serve"], { | ||
| cwd: projectRoot, | ||
| detached: true, | ||
| stdio: ["ignore", "pipe", "inherit"], | ||
| }); | ||
|
maparent marked this conversation as resolved.
|
||
|
|
||
| let resolveCallback: ((value: unknown) => void) | undefined = undefined; | ||
| let rejectCallback: ((reason: unknown) => void) | undefined = undefined; | ||
| let serveSuccess = false; | ||
| let timeoutClear: NodeJS.Timeout | undefined = undefined; | ||
|
|
||
| const servingReady = new Promise((rsc, rjc) => { | ||
| resolveCallback = rsc; | ||
| rejectCallback = rjc; | ||
|
|
||
| // Add timeout | ||
| timeoutClear = setTimeout(() => { | ||
| rjc(new Error("Timeout waiting for functions to serve")); | ||
| }, 30000); // 30 second timeout | ||
| }); | ||
|
|
||
| serve.stdout.on("data", (data: Buffer) => { | ||
| const output = data.toString(); | ||
| console.log(`stdout: ${output}`); | ||
| if (output.includes("Serving functions ")) { | ||
| console.log("Found serving functions"); | ||
| serveSuccess = true; | ||
| clearTimeout(timeoutClear); | ||
| if (resolveCallback === undefined) throw new Error("did not get callback"); | ||
| resolveCallback(null); | ||
| } | ||
| }); | ||
| serve.on("close", () => { | ||
| if (!serveSuccess && rejectCallback) | ||
| rejectCallback(new Error("serve closed without being ready")); | ||
| }); | ||
| serve.on("error", (err) => { | ||
| if (rejectCallback) rejectCallback(err); | ||
| }); | ||
|
|
||
| const doTest = async () => { | ||
| try { | ||
| await servingReady; | ||
| execSync("cucumber-js", { | ||
| cwd: projectRoot, | ||
| stdio: "inherit", | ||
| }); | ||
| // will throw on failure | ||
| } finally { | ||
| if (serve.pid) | ||
| try { | ||
| process.kill(-serve.pid); | ||
| } catch (e) { | ||
| console.error("Could not kill the process"); | ||
| // maybe it just ended on its own. | ||
| } | ||
| } | ||
| }; | ||
|
maparent marked this conversation as resolved.
|
||
|
|
||
| doTest() | ||
| .then(() => { | ||
| console.log("success"); | ||
| clearTimeout(timeoutClear); | ||
| }) | ||
| .catch((err) => { | ||
| console.error(err); | ||
| clearTimeout(timeoutClear); | ||
| process.exit(1); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Inconsistent
GITHUB_ACTIONScheck increateEnv.mtsvs all other filesThe PR adds a
GITHUB_TESTguard to four files, butcreateEnv.mts:154usesprocess.env.GITHUB_ACTIONS !== undefinedwhile the other three files (migrate.ts:11,dbDotEnv.mjs:44,serve_and_test.ts:8) all useprocess.env.GITHUB_ACTIONS === "true". The!== undefinedcheck is strictly more permissive — it would match any truthy or falsy string value (e.g.,"false"or""), not just"true". In practice this difference is unlikely to cause issues since GitHub Actions always sets the variable to"true", but since all four sites were modified in this PR and the three sibling files consistently use=== "true", the inconsistency should be fixed for maintainability.Was this helpful? React with 👍 or 👎 to provide feedback.