Skip to content

Commit 153a813

Browse files
authored
add release status checks (#5674)
1 parent db66b0a commit 153a813

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

.github/workflows/release-latest.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ jobs:
3535
git push origin v${{ fromJson(steps.pkg.outputs.json).version }}
3636
- run: node scripts/release/notes --latest
3737

38+
status:
39+
needs: ['publish']
40+
runs-on: ubuntu-latest
41+
permissions:
42+
id-token: write
43+
contents: read
44+
pull-requests: read
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
steps:
48+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
49+
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
50+
- run: node scripts/release/status
51+
3852
docs:
3953
runs-on: ubuntu-latest
4054
permissions:

scripts/release/status.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
'use strict'
2+
3+
/* eslint-disable no-console */
4+
5+
const util = require('util')
6+
7+
const { GITHUB_REF, GITHUB_TOKEN } = process.env
8+
9+
const TIMEOUT = 10 * 1000
10+
const MAX_ATTEMPTS = 30
11+
12+
let attempts = 0
13+
14+
async function checkStatuses (contexts) {
15+
const url = `https://api.github.com/repos/DataDog/dd-trace-js/commits/${GITHUB_REF}/status`
16+
const response = await fetch(url, {
17+
headers: {
18+
Accept: 'application/vnd.github+json',
19+
Authorization: `Bearer ${GITHUB_TOKEN}`,
20+
'X-GitHub-Api-Version': '2022-11-28'
21+
}
22+
})
23+
24+
if (response.status !== 200) {
25+
console.log(response)
26+
console.log(response.text())
27+
28+
throw new Error(
29+
util.format('Could not get status from GitHub.\n\n%o\n\n%s', response, response.text?.())
30+
)
31+
}
32+
33+
const { statuses } = JSON.parse(await response.text())
34+
35+
for (const status of statuses) {
36+
if (!contexts.has(status.context)) continue
37+
38+
switch (status.state) {
39+
case 'success':
40+
contexts.delete(status.context)
41+
break
42+
case 'cancelled':
43+
case 'failure':
44+
case 'stale':
45+
case 'timed_out':
46+
throw new Error(`Job was not successful: ${status.context}.`)
47+
}
48+
}
49+
50+
if (contexts.size === 0) return
51+
52+
attempts++
53+
54+
if (attempts >= MAX_ATTEMPTS) {
55+
throw new Error(`Jobs did not finish before timeout: ${contexts.join(', ')}.`)
56+
}
57+
58+
setTimeout(() => checkStatuses(contexts), TIMEOUT)
59+
}
60+
61+
checkStatuses(new Set([
62+
'dd-gitlab/promote-oci-to-prod',
63+
'dd-gitlab/publish-lib-init-ghcr-tags'
64+
]))

0 commit comments

Comments
 (0)