From dd84b9d64fb98746a230cd24233ff50a562c39c9 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Fri, 28 Apr 2023 01:36:44 +0800 Subject: --- packages/turbo-ignore/src/getComparison.ts | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 packages/turbo-ignore/src/getComparison.ts (limited to 'packages/turbo-ignore/src/getComparison.ts') 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" }; +} -- cgit v1.2.3-70-g09d2