Skip to content

Commit cdec6d9

Browse files
ci: report a crash of the cloud-deploy-action check as a check that could not run
An unexpected error exited with Node's default code 1, which this script uses for an incompatible CLI, so the dev-build alert would have blamed the action. The docs now also name the version output the action's test relies on, and link the follow-up issue. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io>
1 parent 1cb7dc8 commit cdec6d9

4 files changed

Lines changed: 41 additions & 8 deletions

File tree

‎docs/oss/release-automation.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The pull request check is part of the `Test` job because that check is already r
3838

3939
- The test is `tests/prisma-cli.test.mjs`, and it needs no install: it imports only `../cli.mjs` and Node built-ins.
4040
- The test reads the executable to test from the `PRISMA_CLI_BINS` environment variable.
41+
- The test reads the CLI's version from the output of `prisma --version`, which must start with the version number.
4142
- The script finds the two deploy cases by their titles (`... accepts the deploy arguments for production` and for a named environment) and exits 2 unless both ran. Without an executable the test runs no cases and passes, so a renamed variable or renamed titles would otherwise go unnoticed. Any failed case makes it exit 1. The destroy case may be skipped, because CLIs without a `destroy` command skip it.
4243
- The test reads this CLI's error codes: `CLI.INVALID_ARGUMENTS`, `CLI.COMMAND_MOVED` or `CLI.UNKNOWN_COMMAND` for rejected arguments, and `CLI.CREDENTIALS_REQUIRED` or `CLI.CONFIG_SECTION_INVALID` as the first check after the arguments are parsed.
4344

@@ -55,7 +56,7 @@ When a product changes the arguments:
5556

5657
When the change is made in this repository itself, the pull request's CLI reports the last release's version, so the action sends it the old arguments and the check fails. Release the action first with a rule for the next version, and bump the version (`pnpm bump-version`) in the same pull request.
5758

58-
Making the action detect the arguments without relying on the version number is tracked as follow-up in `prisma/cloud-deploy-action`.
59+
Making the action detect the arguments without relying on the version number is tracked in [prisma/cloud-deploy-action#27](https://github.com/prisma/cloud-deploy-action/issues/27).
5960

6061
## The shared secret: `DEPLOY_GITHUB_TOKEN`
6162

‎scripts/check-cloud-deploy-action-utils.mjs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,20 @@ export function judgeRun(results) {
3838
if (problems.length > 0) return { verdict: "incompatible", problems };
3939
return { verdict: "pass", problems };
4040
}
41+
42+
/**
43+
* A crash of the check is not a verdict on the CLI, so it must not exit
44+
* with Node's default 1, which means "incompatible" here.
45+
*
46+
* @param {() => Promise<number>} main
47+
*/
48+
export async function exitCodeOf(main) {
49+
try {
50+
return await main();
51+
} catch (error) {
52+
console.error(
53+
`::error::The check could not run: ${error instanceof Error ? error.stack : error}`,
54+
);
55+
return EXIT_NOT_RUN;
56+
}
57+
}

‎scripts/check-cloud-deploy-action.mjs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { spec } from "node:test/reporters";
1717
import {
1818
EXIT_INCOMPATIBLE,
1919
EXIT_NOT_RUN,
20+
exitCodeOf,
2021
judgeRun,
2122
} from "./check-cloud-deploy-action-utils.mjs";
2223

@@ -37,21 +38,21 @@ async function main() {
3738
console.error(
3839
"Usage: node scripts/check-cloud-deploy-action.mjs <action-checkout> <prisma-executable>",
3940
);
40-
process.exit(EXIT_NOT_RUN);
41+
return EXIT_NOT_RUN;
4142
}
4243
const testFile = resolve(actionDir, TEST_FILE);
4344
if (!existsSync(testFile)) {
4445
console.error(
4546
`::error::${join(actionDir, TEST_FILE)} does not exist. prisma/cloud-deploy-action must keep its CLI test at this path. The check could not run.`,
4647
);
47-
process.exit(EXIT_NOT_RUN);
48+
return EXIT_NOT_RUN;
4849
}
4950
const executable = resolve(bin);
5051
if (!isExecutableFile(executable)) {
5152
console.error(
5253
`::error::The prisma executable ${executable} is missing or not executable. The check could not run.`,
5354
);
54-
process.exit(EXIT_NOT_RUN);
55+
return EXIT_NOT_RUN;
5556
}
5657

5758
process.env.PRISMA_CLI_BINS = executable;
@@ -76,17 +77,18 @@ async function main() {
7677
console.error(
7778
`::error::The check could not run: prisma/cloud-deploy-action's deploy cases did not run against ${executable}.`,
7879
);
79-
process.exit(EXIT_NOT_RUN);
80+
return EXIT_NOT_RUN;
8081
}
8182
if (verdict === "incompatible") {
8283
console.error(
8384
`::error::prisma/cloud-deploy-action cannot drive ${executable}: its test failed.`,
8485
);
85-
process.exit(EXIT_INCOMPATIBLE);
86+
return EXIT_INCOMPATIBLE;
8687
}
8788
console.log(
8889
`prisma/cloud-deploy-action's test passes against ${executable}.`,
8990
);
91+
return 0;
9092
}
9193

92-
await main();
94+
process.exit(await exitCodeOf(main));

‎scripts/check-cloud-deploy-action.test.mjs‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
55
import { dirname, join } from "node:path";
66
import { after, describe, it } from "node:test";
77
import { fileURLToPath } from "node:url";
8-
import { judgeRun } from "./check-cloud-deploy-action-utils.mjs";
8+
import { exitCodeOf, judgeRun } from "./check-cloud-deploy-action-utils.mjs";
99

1010
const production = "prisma 8.0.0 accepts the deploy arguments for production";
1111
const named = "prisma 8.0.0 accepts the deploy arguments for pr-7";
@@ -66,6 +66,19 @@ describe("judgeRun", () => {
6666
});
6767
});
6868

69+
describe("exitCodeOf", () => {
70+
it("returns what the check returns", async () => {
71+
assert.equal(await exitCodeOf(async () => 1), 1);
72+
});
73+
74+
it("reports a crash as a check that could not run", async () => {
75+
const crash = async () => {
76+
throw new Error("boom");
77+
};
78+
assert.equal(await exitCodeOf(crash), 2);
79+
});
80+
});
81+
6982
describe("check-cloud-deploy-action.mjs", () => {
7083
const scripts = dirname(fileURLToPath(import.meta.url));
7184
const actionDir = join(scripts, "fixtures/cloud-deploy-action");

0 commit comments

Comments
 (0)