Skip to content

Commit f98e274

Browse files
authored
feat(webapp): allow version downgrades via promote API (#3214)
1 parent cf0e1ff commit f98e274

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: feature
4+
---
5+
6+
Add allowRollbacks query param to the promote deployment API to enable version downgrades

apps/webapp/app/routes/api.v1.deployments.$deploymentVersion.promote.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
3232

3333
const authenticatedEnv = authenticationResult.environment;
3434

35+
const url = new URL(request.url);
36+
const allowRollbacks = url.searchParams.get("allowRollbacks") === "true";
37+
3538
const { deploymentVersion } = parsedParams.data;
3639

3740
const deployment = await prisma.workerDeployment.findFirst({
@@ -47,7 +50,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
4750

4851
try {
4952
const service = new ChangeCurrentDeploymentService();
50-
await service.call(deployment, "promote");
53+
await service.call(deployment, "promote", allowRollbacks);
5154

5255
return json(
5356
{

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

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import { CURRENT_DEPLOYMENT_LABEL } from "@trigger.dev/core/v3/isomorphic";
77
export type ChangeCurrentDeploymentDirection = "promote" | "rollback";
88

99
export class ChangeCurrentDeploymentService extends BaseService {
10-
public async call(deployment: WorkerDeployment, direction: ChangeCurrentDeploymentDirection) {
10+
public async call(
11+
deployment: WorkerDeployment,
12+
direction: ChangeCurrentDeploymentDirection,
13+
disableVersionCheck?: boolean
14+
) {
1115
if (!deployment.workerId) {
1216
throw new ServiceValidationError(
1317
direction === "promote"
@@ -42,26 +46,34 @@ export class ChangeCurrentDeploymentService extends BaseService {
4246
}
4347

4448
// if there is a current promotion, we have to validate we are moving in the right direction based on the deployment versions
45-
switch (direction) {
46-
case "promote": {
47-
if (
48-
compareDeploymentVersions(currentPromotion.deployment.version, deployment.version) >= 0
49-
) {
50-
throw new ServiceValidationError(
51-
"Cannot promote a deployment that is older than the current deployment."
52-
);
49+
if (!disableVersionCheck) {
50+
switch (direction) {
51+
case "promote": {
52+
if (
53+
compareDeploymentVersions(
54+
currentPromotion.deployment.version,
55+
deployment.version
56+
) >= 0
57+
) {
58+
throw new ServiceValidationError(
59+
"Cannot promote a deployment that is older than the current deployment."
60+
);
61+
}
62+
break;
5363
}
54-
break;
55-
}
56-
case "rollback": {
57-
if (
58-
compareDeploymentVersions(currentPromotion.deployment.version, deployment.version) <= 0
59-
) {
60-
throw new ServiceValidationError(
61-
"Cannot rollback to a deployment that is newer than the current deployment."
62-
);
64+
case "rollback": {
65+
if (
66+
compareDeploymentVersions(
67+
currentPromotion.deployment.version,
68+
deployment.version
69+
) <= 0
70+
) {
71+
throw new ServiceValidationError(
72+
"Cannot rollback to a deployment that is newer than the current deployment."
73+
);
74+
}
75+
break;
6376
}
64-
break;
6577
}
6678
}
6779
}

0 commit comments

Comments
 (0)