Skip to content

Commit a2d7484

Browse files
author
Conner Aldrich
committed
revert: remove DEPLOY_VERSION_SUFFIX and version-suffix handling
The version-suffix work (DEPLOY_VERSION_SUFFIX env var, suffix-aware ordering in calculateNextBuildVersion / compareDeploymentVersions, SQL ORDER BY rewrites in DeploymentListPresenter / TestPresenter, suffix-aware comparisons in devQueueConsumer, test setup duplication in run-engine) is no longer needed. For our self-hosted deployment: - upstream's default version scheme (YYYYMMDD.N) is fine for tracking deployments - custom image tagging is handled by DEPLOY_IMAGE_OVERRIDE (separate feature, kept) Restore the affected files to upstream main. Drop the related test files and the suffix-fix commit's coverage.
1 parent 223f298 commit a2d7484

11 files changed

Lines changed: 34 additions & 196 deletions

apps/webapp/app/env.server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ const EnvironmentSchema = z
344344
COMPUTE_TEMPLATE_SHADOW_ROLLOUT_PCT: z.string().optional(),
345345

346346
DEPLOY_IMAGE_PLATFORM: z.string().default("linux/amd64"),
347-
DEPLOY_VERSION_SUFFIX: z.string().optional(),
348347
/**
349348
* Full image reference override - bypasses auto-generation of image tags.
350349
* When set, every deployment uses this exact image reference instead of

apps/webapp/app/presenters/v3/DeploymentListPresenter.server.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,7 @@ WHERE
202202
wd."projectId" = ${project.id}
203203
AND wd."environmentId" = ${environment.id}
204204
ORDER BY
205-
string_to_array(split_part(wd."version", '-', 1), '.')::int[] DESC,
206-
-- Capture the full suffix (everything after the first hyphen) so multi-hyphen
207-
-- suffixes like "20260101.1-pre-rc.1" sort correctly. split_part(..., 2)
208-
-- would drop everything after the second hyphen and tie-break incorrectly.
209-
COALESCE(substring(wd."version" from '-(.*)$'), '') DESC
205+
string_to_array(wd."version", '.')::int[] DESC
210206
LIMIT ${pageSize} OFFSET ${pageSize * (page - 1)};`;
211207

212208
const { connectedGithubRepository } = project;
@@ -323,16 +319,7 @@ LIMIT ${pageSize} OFFSET ${pageSize * (page - 1)};`;
323319
FROM ${sqlDatabaseSchema}."WorkerDeployment"
324320
WHERE "projectId" = ${project.id}
325321
AND "environmentId" = ${environment.id}
326-
AND (
327-
string_to_array(split_part(version, '-', 1), '.')::int[] > string_to_array(split_part(${version}, '-', 1), '.')::int[]
328-
OR (
329-
string_to_array(split_part(version, '-', 1), '.')::int[] = string_to_array(split_part(${version}, '-', 1), '.')::int[]
330-
-- Compare the full suffix (everything after the first hyphen) so
331-
-- multi-hyphen suffixes like "1-pre-rc.1" vs "1-pre-rc.2" don't
332-
-- tie. split_part(..., 2) only returns the second segment.
333-
AND COALESCE(substring(version from '-(.*)$'), '') > COALESCE(substring(${version} from '-(.*)$'), '')
334-
)
335-
)
322+
AND string_to_array(version, '.')::int[] > string_to_array(${version}, '.')::int[]
336323
`;
337324

338325
const count = Number(deploymentsSinceVersion[0].count);

apps/webapp/app/presenters/v3/TestPresenter.server.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ export class TestPresenter extends BasePresenter {
4545
>`WITH workers AS (
4646
SELECT
4747
bw.*,
48-
ROW_NUMBER() OVER(
49-
ORDER BY
50-
string_to_array(split_part(bw.version, '-', 1), '.')::int[] DESC,
51-
-- Capture the full suffix (everything after the first hyphen) so
52-
-- multi-hyphen suffixes like "1-pre-rc.1" sort correctly.
53-
COALESCE(substring(bw.version from '-(.*)$'), '') DESC
54-
) AS rn
48+
ROW_NUMBER() OVER(ORDER BY string_to_array(bw.version, '.')::int[] DESC) AS rn
5549
FROM
5650
${sqlDatabaseSchema}."BackgroundWorker" bw
5751
WHERE "runtimeEnvironmentId" = ${envId}

apps/webapp/app/v3/marqs/devQueueConsumer.server.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { FailedTaskRunService } from "../failedTaskRun.server";
2222
import { CancelDevSessionRunsService } from "../services/cancelDevSessionRuns.server";
2323
import { CompleteAttemptService } from "../services/completeAttempt.server";
2424
import { attributesFromAuthenticatedEnv, tracer } from "../tracer.server";
25-
import { compareDeploymentVersions } from "../utils/deploymentVersions";
2625
import { DevSubscriber, devPubSub } from "./devPubSub.server";
2726

2827
const MessageBody = z.discriminatedUnion("type", [
@@ -591,7 +590,7 @@ export class DevQueueConsumer {
591590
}
592591

593592
// Get the latest background worker based on the version.
594-
// Versions are in the format of YYYYMMDD.N (e.g., 20240101.1) with optional suffix (e.g., 20240101.1-hardened)
593+
// Versions are in the format of 20240101.1 and 20240101.2, or even 20240101.10, 20240101.11, etc.
595594
#getLatestBackgroundWorker() {
596595
const workers = Array.from(this._backgroundWorkers.values());
597596

@@ -600,10 +599,22 @@ export class DevQueueConsumer {
600599
}
601600

602601
return workers.reduce((acc, curr) => {
603-
// Use compareDeploymentVersions to properly handle versions with suffixes
604-
const comparison = compareDeploymentVersions(acc.version, curr.version);
605-
// If curr is newer (comparison returns -1), use curr, otherwise use acc
606-
return comparison < 0 ? curr : acc;
602+
const accParts = acc.version.split(".").map(Number);
603+
const currParts = curr.version.split(".").map(Number);
604+
605+
// Compare the major part
606+
if (accParts[0] < currParts[0]) {
607+
return curr;
608+
} else if (accParts[0] > currParts[0]) {
609+
return acc;
610+
}
611+
612+
// Compare the minor part (assuming all versions have two parts)
613+
if (accParts[1] < currParts[1]) {
614+
return curr;
615+
} else {
616+
return acc;
617+
}
607618
});
608619
}
609620
}

apps/webapp/app/v3/services/createBackgroundWorker.server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { BackgroundWorkerId, stringifyDuration } from "@trigger.dev/core/v3/isom
1010
import type { BackgroundWorker, TaskQueue, TaskQueueType } from "@trigger.dev/database";
1111
import cronstrue from "cronstrue";
1212
import { $transaction, Prisma, PrismaClientOrTransaction } from "~/db.server";
13-
import { env } from "~/env.server";
1413
import { sanitizeQueueName } from "~/models/taskQueue.server";
1514
import { AuthenticatedEnvironment } from "~/services/apiAuth.server";
1615
import { logger } from "~/services/logger.server";
@@ -67,7 +66,7 @@ export class CreateBackgroundWorkerService extends BaseService {
6766
return latestBackgroundWorker;
6867
}
6968

70-
const nextVersion = calculateNextBuildVersion(project.backgroundWorkers[0]?.version, env.DEPLOY_VERSION_SUFFIX);
69+
const nextVersion = calculateNextBuildVersion(project.backgroundWorkers[0]?.version);
7170

7271
logger.debug(`Creating background worker`, {
7372
nextVersion,

apps/webapp/app/v3/services/initializeDeployment.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class InitializeDeploymentService extends BaseService {
107107
take: 1,
108108
});
109109

110-
const nextVersion = calculateNextBuildVersion(latestDeployment?.version, env.DEPLOY_VERSION_SUFFIX);
110+
const nextVersion = calculateNextBuildVersion(latestDeployment?.version);
111111

112112
if (payload.selfHosted && remoteBuildsEnabled()) {
113113
throw new ServiceValidationError(
Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
11
// Calculate next build version based on the previous version
22
// Version formats are YYYYMMDD.1, YYYYMMDD.2, etc.
3-
// With optional suffix: YYYYMMDD.1-suffix
43
// If there is no previous version, start at Todays date and .1
5-
export function calculateNextBuildVersion(latestVersion?: string | null, suffix?: string): string {
4+
export function calculateNextBuildVersion(latestVersion?: string | null): string {
65
const today = new Date();
76
const year = today.getFullYear();
87
const month = today.getMonth() + 1;
98
const day = today.getDate();
109
const todayFormatted = `${year}${month < 10 ? "0" : ""}${month}${day < 10 ? "0" : ""}${day}`;
1110

1211
if (!latestVersion) {
13-
const baseVersion = `${todayFormatted}.1`;
14-
return suffix ? `${baseVersion}-${suffix}` : baseVersion;
12+
return `${todayFormatted}.1`;
1513
}
1614

17-
// Extract base version (everything before the first hyphen) — any existing
18-
// suffix is intentionally discarded; the new version takes the suffix passed
19-
// by the caller, which may differ. Avoid `split("-")` indexed destructuring
20-
// here so multi-hyphen suffixes don't read confusingly.
21-
const hyphenIndex = latestVersion.indexOf("-");
22-
const baseVersion =
23-
hyphenIndex === -1 ? latestVersion : latestVersion.slice(0, hyphenIndex);
24-
const [date, buildNumber] = baseVersion.split(".");
15+
const [date, buildNumber] = latestVersion.split(".");
2516

2617
if (date === todayFormatted) {
2718
const nextBuildNumber = parseInt(buildNumber, 10) + 1;
28-
const newBaseVersion = `${date}.${nextBuildNumber}`;
29-
return suffix ? `${newBaseVersion}-${suffix}` : newBaseVersion;
19+
return `${date}.${nextBuildNumber}`;
3020
}
3121

32-
const newBaseVersion = `${todayFormatted}.1`;
33-
return suffix ? `${newBaseVersion}-${suffix}` : newBaseVersion;
22+
return `${todayFormatted}.1`;
3423
}
Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
11
// Compares two versions of a deployment, like 20250208.1 and 20250208.2
2-
// Also handles versions with suffixes like 20250208.1-hardened
32
// Returns -1 if versionA is older than versionB, 0 if they are the same, and 1 if versionA is newer than versionB
4-
5-
const splitDeploymentVersion = (version: string): { base: string; suffix: string } => {
6-
const hyphenIndex = version.indexOf("-");
7-
if (hyphenIndex === -1) {
8-
return { base: version, suffix: "" };
9-
}
10-
return {
11-
base: version.slice(0, hyphenIndex),
12-
// Capture everything after the first hyphen so multi-hyphen suffixes
13-
// (e.g. "20250208.1-pre-rc.1") are preserved intact.
14-
suffix: version.slice(hyphenIndex + 1),
15-
};
16-
};
17-
183
export function compareDeploymentVersions(versionA: string, versionB: string) {
19-
const { base: baseVersionA, suffix: suffixA } = splitDeploymentVersion(versionA);
20-
const { base: baseVersionB, suffix: suffixB } = splitDeploymentVersion(versionB);
21-
22-
const [dateA, numberA] = baseVersionA.split(".");
23-
const [dateB, numberB] = baseVersionB.split(".");
4+
const [dateA, numberA] = versionA.split(".");
5+
const [dateB, numberB] = versionB.split(".");
246

257
if (dateA < dateB) {
268
return -1;
@@ -42,20 +24,5 @@ export function compareDeploymentVersions(versionA: string, versionB: string) {
4224
return 1;
4325
}
4426

45-
// Base versions are equal, compare suffixes alphabetically
46-
// Versions without suffixes should come before versions with suffixes
47-
if (suffixA === "" && suffixB !== "") {
48-
return -1;
49-
}
50-
if (suffixA !== "" && suffixB === "") {
51-
return 1;
52-
}
53-
if (suffixA < suffixB) {
54-
return -1;
55-
}
56-
if (suffixA > suffixB) {
57-
return 1;
58-
}
59-
6027
return 0;
6128
}

apps/webapp/test/calculateNextBuildVersion.test.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

apps/webapp/test/deploymentVersions.test.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)