Skip to content

Commit

Permalink
Return errors from script if deployment fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclarke committed Feb 8, 2025
1 parent df9985b commit 381feec
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion .github/scripts/docs/preview-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = async ({ github, context }) => {
c.body?.startsWith(commentHeader)
);

let deploymentError = null;
let deployment;
try {
deployment = await vercelFetch("https://api.vercel.com/v13/deployments", {
Expand All @@ -50,6 +51,7 @@ module.exports = async ({ github, context }) => {

commentMessage += `\n🔄 Deploying docs preview for commit ${shortCommitSHA}:\n\n<https://${deployment.url}>`;
} catch (e) {
deploymentError = e;
commentMessage += `\n❌ Failed to deploy docs preview for commit ${shortCommitSHA}:\n\n\`\`\`\n${e.message}\n\`\`\``;
}

Expand All @@ -73,6 +75,10 @@ module.exports = async ({ github, context }) => {
).data;
}

if (deploymentError) {
throw new Error(`Docs preview deployment failed: ${e.message}`);
}

let i = 0;
while (i < 40) {
await sleep(15_000);
Expand Down Expand Up @@ -110,10 +116,25 @@ module.exports = async ({ github, context }) => {
new Date()
)})`,
});
if (status !== "READY") {
throw new Error(
`Docs preview deployment failed with status ${status}: https://${deployment.url}`
);
}
return;
}
}
throw new Error("timed out waiting for deployment status to succeed or fail");

await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: updateComment.id,
body: `${commentHeader}
❌ Timed out waiting for deployment status to succeed or fail for commit ${shortCommitSHA}:\n\n<https://${
deployment.url
}>\n\n(Last updated: ${formatDatetime(new Date())})`,
});
throw new Error("Timed out waiting for deployment status to succeed or fail");
};

async function vercelFetch(url, body) {
Expand Down

0 comments on commit 381feec

Please sign in to comment.