Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 don't leave buildkite hanging for skipped builds #2844

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions baker/BuildkiteTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import {
BUILDKITE_BRANCH,
} from "../settings/serverSettings.js"

type BuildState =
| "running"
| "scheduled"
| "passed"
| "failing"
| "failed"
| "blocked"
| "canceled"
| "canceling"
| "skipped"
| "not_run"
| "finished"

export class BuildkiteTrigger {
private organizationSlug = "our-world-in-data"
private pipelineSlug = BUILDKITE_DEPLOY_CONTENT_PIPELINE_SLUG
Expand Down Expand Up @@ -59,10 +72,14 @@ export class BuildkiteTrigger {
Authorization: `Bearer ${BUILDKITE_API_ACCESS_TOKEN}`,
}

let status = ""
let state: BuildState = "scheduled"

while (
["running", "scheduled", "canceling", "failing"].includes(state)
) {
// Wait for 10 seconds
await new Promise((res) => setTimeout(res, 10000))

// Poll the status every 10 seconds (or your preferred interval)
while (status !== "passed" && status !== "failed") {
const response = await fetch(url, {
method: "GET",
headers: headers,
Expand All @@ -73,18 +90,14 @@ export class BuildkiteTrigger {
}

const buildData = await response.json()
status = buildData.state

if (status !== "passed" && status !== "failed") {
await new Promise((res) => setTimeout(res, 10000)) // Wait for 10 seconds
}
state = buildData.state
}

if (status === "passed") {
if (["passed", "skipped", "canceled", "finished"].includes(state)) {
return
} else {
throw new Error(
`Build failed with status "${status}". See Buildkite for details.`
`Build ${buildNumber} failed with state "${state}". See Buildkite for details.`
)
}
}
Expand Down
Loading