aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/turbo-ignore/src/getComparison.ts
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
commitdd84b9d64fb98746a230cd24233ff50a562c39c9 (patch)
treeb583261ef00b3afe72ec4d6dacb31e57779a6faf /packages/turbo-ignore/src/getComparison.ts
parent0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff)
downloadHydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz
HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip
Diffstat (limited to 'packages/turbo-ignore/src/getComparison.ts')
-rw-r--r--packages/turbo-ignore/src/getComparison.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/packages/turbo-ignore/src/getComparison.ts b/packages/turbo-ignore/src/getComparison.ts
new file mode 100644
index 0000000..a2ad61a
--- /dev/null
+++ b/packages/turbo-ignore/src/getComparison.ts
@@ -0,0 +1,39 @@
+import { info } from "./logger";
+import { TurboIgnoreArgs } from "./types";
+
+export interface GetComparisonArgs extends TurboIgnoreArgs {
+ // the workspace to check for changes
+ workspace: string;
+ // A ref/head to compare against if no previously deployed SHA is available
+ fallback?: string;
+}
+
+export function getComparison(args: GetComparisonArgs): {
+ ref: string;
+ type: "previousDeploy" | "headRelative" | "customFallback";
+} | null {
+ const { fallback, workspace } = args;
+ if (process.env.VERCEL === "1") {
+ if (process.env.VERCEL_GIT_PREVIOUS_SHA) {
+ // use the commit SHA of the last successful deployment for this project / branch
+ info(
+ `Found previous deployment ("${process.env.VERCEL_GIT_PREVIOUS_SHA}") for "${workspace}" on branch "${process.env.VERCEL_GIT_COMMIT_REF}"`
+ );
+ return {
+ ref: process.env.VERCEL_GIT_PREVIOUS_SHA,
+ type: "previousDeploy",
+ };
+ } else {
+ info(
+ `No previous deployments found for "${workspace}" on branch "${process.env.VERCEL_GIT_COMMIT_REF}".`
+ );
+ if (fallback) {
+ info(`Falling back to ref ${fallback}`);
+ return { ref: fallback, type: "customFallback" };
+ }
+
+ return null;
+ }
+ }
+ return { ref: "HEAD^", type: "headRelative" };
+}