Skip to content

Commit 12c7ae9

Browse files
committed
feat: update awaitLatestBuild.ts script
Requires getting process.env.BUILD_ID from previous script in workflow (triggerBuild.ts)
1 parent 546ce9b commit 12c7ae9

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

src/scripts/crowdin/translations/awaitLatestBuild.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,50 @@
11
import crowdin from "../api-client/crowdinClient"
22

3-
async function awaitLatestBuild() {
4-
const FINISHED = "finished"
5-
const TIMEOUT = 2 * 60 * 60 * 1000 // 2 hours in milliseconds
3+
const FINISHED = "finished"
4+
const TIMEOUT = 2 * 60 * 60 * 1000 // Timeout after 2 hours
5+
const INTERVAL = 10 * 1000 // 10 seconds between checks
66

7+
async function awaitLatestBuild() {
78
const projectId = Number(process.env.CROWDIN_PROJECT_ID) || 363359
89

9-
const initialResponse = await crowdin.translationsApi.listProjectBuilds(
10-
projectId
11-
)
10+
// BUILD_ID is provided by the triggerBuild script run in the same workflow prior to this script
11+
const buildId = process.env.BUILD_ID
1212

13+
console.log("Build ID provided:", buildId)
14+
const initialResponse = await crowdin.translationsApi.checkBuildStatus(
15+
projectId,
16+
Number(buildId)
17+
)
1318
let data = initialResponse.data
14-
let isFinished = data[0].data.status === FINISHED
19+
20+
let isFinished = data.status === FINISHED
1521

1622
const timeoutTime = Date.now() + TIMEOUT
23+
let tryAgainTime = Date.now() - 1
1724
while (!isFinished && Date.now() < timeoutTime) {
18-
const repeatCheck = await crowdin.translationsApi.listProjectBuilds(
19-
projectId
25+
if (Date.now() < tryAgainTime) continue
26+
tryAgainTime = Date.now() + INTERVAL
27+
28+
const repeatCheck = await crowdin.translationsApi.checkBuildStatus(
29+
projectId,
30+
Number(buildId)
2031
)
2132
data = repeatCheck.data
22-
isFinished = data[0].data.status === FINISHED
33+
isFinished = data.status === FINISHED
34+
console.log(
35+
`id: ${buildId}, status: ${data.status}, progress ${data.progress}`
36+
)
2337
}
24-
const latestBuildData = data[0].data
25-
if (latestBuildData.status !== FINISHED)
38+
39+
if (data.status !== FINISHED) {
40+
console.error(`::set-output name=buildSuccess::false`)
2641
throw new Error(
2742
`Timeout: Build did not finish in ${TIMEOUT / 1000 / 60} minutes`
2843
)
44+
}
45+
46+
console.log("Latest build data:", data)
47+
console.error(`::set-output name=buildSuccess::true`)
2948
}
3049

3150
awaitLatestBuild()

0 commit comments

Comments
 (0)