@temps-sdk/cli 0.1.32 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +103 -53
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -86878,6 +86878,50 @@ async function watchDeployment(options) {
|
|
|
86878
86878
|
});
|
|
86879
86879
|
}
|
|
86880
86880
|
|
|
86881
|
+
// src/lib/find-triggered-deployment.ts
|
|
86882
|
+
function commitMatches(deploymentHash, requested) {
|
|
86883
|
+
const want = requested?.trim();
|
|
86884
|
+
if (!want)
|
|
86885
|
+
return true;
|
|
86886
|
+
if (!deploymentHash)
|
|
86887
|
+
return false;
|
|
86888
|
+
const have = deploymentHash.toLowerCase();
|
|
86889
|
+
const needle = want.toLowerCase();
|
|
86890
|
+
return have.startsWith(needle) || needle.startsWith(have);
|
|
86891
|
+
}
|
|
86892
|
+
function selectTriggeredDeployment(deployments, options) {
|
|
86893
|
+
for (const deployment of deployments) {
|
|
86894
|
+
if (deployment.id <= options.afterId)
|
|
86895
|
+
continue;
|
|
86896
|
+
if (!commitMatches(deployment.commit_hash, options.commit))
|
|
86897
|
+
continue;
|
|
86898
|
+
return deployment;
|
|
86899
|
+
}
|
|
86900
|
+
return null;
|
|
86901
|
+
}
|
|
86902
|
+
async function waitForTriggeredDeployment(fetchDeployments, options) {
|
|
86903
|
+
const maxAttempts = options.maxAttempts ?? 15;
|
|
86904
|
+
const intervalMs = options.intervalMs ?? 2000;
|
|
86905
|
+
const sleep2 = options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
86906
|
+
for (let attempt2 = 0;attempt2 < maxAttempts; attempt2++) {
|
|
86907
|
+
const { deployments, error: error3 } = await fetchDeployments();
|
|
86908
|
+
if (error3) {
|
|
86909
|
+
return { ok: false, error: "fetch_failed", cause: error3 };
|
|
86910
|
+
}
|
|
86911
|
+
const match = selectTriggeredDeployment(deployments ?? [], {
|
|
86912
|
+
afterId: options.afterId,
|
|
86913
|
+
commit: options.commit
|
|
86914
|
+
});
|
|
86915
|
+
if (match) {
|
|
86916
|
+
return { ok: true, deploymentId: match.id };
|
|
86917
|
+
}
|
|
86918
|
+
if (attempt2 < maxAttempts - 1) {
|
|
86919
|
+
await sleep2(intervalMs);
|
|
86920
|
+
}
|
|
86921
|
+
}
|
|
86922
|
+
return { ok: false, error: "not_found" };
|
|
86923
|
+
}
|
|
86924
|
+
|
|
86881
86925
|
// src/commands/deploy/deploy-local-image.ts
|
|
86882
86926
|
init_sdk_gen();
|
|
86883
86927
|
init_prompts();
|
|
@@ -88022,6 +88066,15 @@ async function deploy(options) {
|
|
|
88022
88066
|
].filter(Boolean).join(`
|
|
88023
88067
|
`), `${icons.rocket} Deployment Preview`);
|
|
88024
88068
|
newline();
|
|
88069
|
+
const { data: baselineList } = await getProjectDeployments({
|
|
88070
|
+
client,
|
|
88071
|
+
path: { id: project.id },
|
|
88072
|
+
query: {
|
|
88073
|
+
per_page: 1,
|
|
88074
|
+
...environmentId ? { environment_id: environmentId } : {}
|
|
88075
|
+
}
|
|
88076
|
+
});
|
|
88077
|
+
const afterId = baselineList?.deployments?.[0]?.id ?? 0;
|
|
88025
88078
|
startSpinner("Starting deployment...");
|
|
88026
88079
|
try {
|
|
88027
88080
|
const { data, error: error3 } = await triggerProjectPipeline({
|
|
@@ -88049,43 +88102,37 @@ async function deploy(options) {
|
|
|
88049
88102
|
return;
|
|
88050
88103
|
}
|
|
88051
88104
|
startSpinner("Waiting for deployment to start...");
|
|
88052
|
-
|
|
88053
|
-
for (let attempt2 = 0;attempt2 < 15; attempt2++) {
|
|
88105
|
+
const waitResult = await waitForTriggeredDeployment(async () => {
|
|
88054
88106
|
const { data: deployList, error: deployError } = await getProjectDeployments({
|
|
88055
88107
|
client,
|
|
88056
88108
|
path: { id: project.id },
|
|
88057
88109
|
query: {
|
|
88058
|
-
per_page:
|
|
88110
|
+
per_page: 10,
|
|
88059
88111
|
...environmentId ? { environment_id: environmentId } : {}
|
|
88060
88112
|
}
|
|
88061
88113
|
});
|
|
88062
|
-
|
|
88063
|
-
|
|
88064
|
-
|
|
88065
|
-
|
|
88066
|
-
|
|
88067
|
-
}
|
|
88068
|
-
|
|
88069
|
-
if (latest?.id) {
|
|
88070
|
-
deploymentId = latest.id;
|
|
88071
|
-
break;
|
|
88072
|
-
}
|
|
88073
|
-
await new Promise((r) => setTimeout(r, 2000));
|
|
88114
|
+
return { deployments: deployList?.deployments, error: deployError };
|
|
88115
|
+
}, { afterId, commit });
|
|
88116
|
+
if (!waitResult.ok && waitResult.error === "fetch_failed") {
|
|
88117
|
+
failSpinner("Failed to fetch deployment status");
|
|
88118
|
+
info2(`Error: ${getErrorMessage(waitResult.cause)}`);
|
|
88119
|
+
info2(`Dashboard: ${colors.primary(`${webUrl}/projects/${projectName}/deployments`)}`);
|
|
88120
|
+
return;
|
|
88074
88121
|
}
|
|
88075
|
-
if (
|
|
88076
|
-
succeedSpinner(`Deployment #${deploymentId} found`);
|
|
88077
|
-
const result2 = await watchDeployment({
|
|
88078
|
-
projectId: project.id,
|
|
88079
|
-
deploymentId,
|
|
88080
|
-
timeoutSecs: 600,
|
|
88081
|
-
projectName
|
|
88082
|
-
});
|
|
88083
|
-
if (!result2.success) {
|
|
88084
|
-
process.exitCode = 1;
|
|
88085
|
-
}
|
|
88086
|
-
} else {
|
|
88122
|
+
if (!waitResult.ok) {
|
|
88087
88123
|
failSpinner("Could not locate the deployment to track");
|
|
88088
88124
|
info2(`Dashboard: ${colors.primary(`${webUrl}/projects/${projectName}/deployments`)}`);
|
|
88125
|
+
return;
|
|
88126
|
+
}
|
|
88127
|
+
succeedSpinner(`Deployment #${waitResult.deploymentId} found`);
|
|
88128
|
+
const result2 = await watchDeployment({
|
|
88129
|
+
projectId: project.id,
|
|
88130
|
+
deploymentId: waitResult.deploymentId,
|
|
88131
|
+
timeoutSecs: 600,
|
|
88132
|
+
projectName
|
|
88133
|
+
});
|
|
88134
|
+
if (!result2.success) {
|
|
88135
|
+
process.exitCode = 1;
|
|
88089
88136
|
}
|
|
88090
88137
|
} catch (err) {
|
|
88091
88138
|
failSpinner("Deployment failed");
|
|
@@ -113277,6 +113324,15 @@ async function up(projectArg, options) {
|
|
|
113277
113324
|
].filter(Boolean).join(`
|
|
113278
113325
|
`), `${icons.rocket} Deployment Preview`);
|
|
113279
113326
|
newline();
|
|
113327
|
+
const { data: baselineList } = await getProjectDeployments({
|
|
113328
|
+
client,
|
|
113329
|
+
path: { id: project.id },
|
|
113330
|
+
query: {
|
|
113331
|
+
per_page: 1,
|
|
113332
|
+
...environmentId ? { environment_id: environmentId } : {}
|
|
113333
|
+
}
|
|
113334
|
+
});
|
|
113335
|
+
const afterId = baselineList?.deployments?.[0]?.id ?? 0;
|
|
113280
113336
|
startSpinner("Starting deployment...");
|
|
113281
113337
|
try {
|
|
113282
113338
|
const { data: pipelineData, error: pipelineError } = await triggerProjectPipeline({
|
|
@@ -113304,42 +113360,36 @@ async function up(projectArg, options) {
|
|
|
113304
113360
|
return;
|
|
113305
113361
|
}
|
|
113306
113362
|
startSpinner("Waiting for deployment to start...");
|
|
113307
|
-
|
|
113308
|
-
for (let attempt2 = 0;attempt2 < 15; attempt2++) {
|
|
113363
|
+
const waitResult = await waitForTriggeredDeployment(async () => {
|
|
113309
113364
|
const { data: deployList, error: deployError } = await getProjectDeployments({
|
|
113310
113365
|
client,
|
|
113311
113366
|
path: { id: project.id },
|
|
113312
113367
|
query: {
|
|
113313
|
-
per_page:
|
|
113368
|
+
per_page: 10,
|
|
113314
113369
|
...environmentId ? { environment_id: environmentId } : {}
|
|
113315
113370
|
}
|
|
113316
113371
|
});
|
|
113317
|
-
|
|
113318
|
-
|
|
113319
|
-
|
|
113320
|
-
|
|
113321
|
-
}
|
|
113322
|
-
|
|
113323
|
-
if (latest?.id) {
|
|
113324
|
-
deploymentId = latest.id;
|
|
113325
|
-
break;
|
|
113326
|
-
}
|
|
113327
|
-
await new Promise((r) => setTimeout(r, 2000));
|
|
113372
|
+
return { deployments: deployList?.deployments, error: deployError };
|
|
113373
|
+
}, { afterId });
|
|
113374
|
+
if (!waitResult.ok && waitResult.error === "fetch_failed") {
|
|
113375
|
+
failSpinner("Failed to fetch deployment status");
|
|
113376
|
+
info2(`Error: ${getErrorMessage(waitResult.cause)}`);
|
|
113377
|
+
return;
|
|
113328
113378
|
}
|
|
113329
|
-
if (
|
|
113330
|
-
succeedSpinner(`Deployment #${deploymentId} found`);
|
|
113331
|
-
const result2 = await watchDeployment({
|
|
113332
|
-
projectId: project.id,
|
|
113333
|
-
deploymentId,
|
|
113334
|
-
timeoutSecs: 600,
|
|
113335
|
-
projectName: resolved.slug
|
|
113336
|
-
});
|
|
113337
|
-
if (!result2.success) {
|
|
113338
|
-
process.exitCode = 1;
|
|
113339
|
-
}
|
|
113340
|
-
} else {
|
|
113379
|
+
if (!waitResult.ok) {
|
|
113341
113380
|
failSpinner("Could not locate the deployment to track");
|
|
113342
113381
|
info2(`Check status: ${colors.muted("bunx @temps-sdk/cli status")}`);
|
|
113382
|
+
return;
|
|
113383
|
+
}
|
|
113384
|
+
succeedSpinner(`Deployment #${waitResult.deploymentId} found`);
|
|
113385
|
+
const result2 = await watchDeployment({
|
|
113386
|
+
projectId: project.id,
|
|
113387
|
+
deploymentId: waitResult.deploymentId,
|
|
113388
|
+
timeoutSecs: 600,
|
|
113389
|
+
projectName: resolved.slug
|
|
113390
|
+
});
|
|
113391
|
+
if (!result2.success) {
|
|
113392
|
+
process.exitCode = 1;
|
|
113343
113393
|
}
|
|
113344
113394
|
} catch (err) {
|
|
113345
113395
|
failSpinner("Deployment failed");
|