Skip to content

Commit 90e2414

Browse files
authored
switch all-green to custom script with less api calls (#7539)
1 parent b6f7a69 commit 90e2414

File tree

4 files changed

+211
-37
lines changed

4 files changed

+211
-37
lines changed

.github/workflows/all-green.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@ jobs:
1818
checks: read
1919
contents: read
2020
steps:
21-
- uses: wechuli/allcheckspassed@1d00cf0c34c4b0805db8866d8913f22e7125301e # v2.3.0
21+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2222
with:
23-
delay: ${{ github.run_attempt == 1 && '7' || '0' }} # 7 minutes on first attempt, no delay on reruns
24-
retries: 15
25-
polling_interval: 2 # Once every 2 minutes
26-
checks_exclude: devflow.*
27-
fail_fast: false
28-
verbose: true # What checks are still waited for?
23+
sparse-checkout-cone-mode: false
24+
sparse-checkout: |
25+
.github
26+
scripts
27+
- uses: ./.github/actions/node
28+
with:
29+
version: active
30+
- run: yarn add @actions/core @actions/github octokit
31+
- run: node scripts/all-green.mjs
32+
env:
33+
DELAY: ${{ github.run_attempt == 1 && '7' || '0' }} # 7 minutes on first attempt, no delay on reruns
34+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
35+
GITHUB_TOKEN: ${{ github.token }}
36+
POLLING_INTERVAL: 1
37+
RETRIES: 15
2938
- name: Require vendor validation when vendor/ changes
3039
if: github.event_name == 'pull_request'
3140
env:

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@
148148
"oxc-parser": "^0.115.0"
149149
},
150150
"devDependencies": {
151+
"@actions/core": "^3.0.0",
152+
"@actions/github": "^9.0.0",
151153
"@babel/helpers": "^7.28.6",
152154
"@eslint/eslintrc": "^3.3.1",
153155
"@eslint/js": "^9.39.2",

scripts/all-green.mjs

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { setTimeout } from 'timers/promises'
2+
import { Octokit } from 'octokit'
3+
import { summary } from '@actions/core'
4+
import { context } from '@actions/github'
5+
6+
/* eslint-disable no-console */
7+
8+
const {
9+
DELAY,
10+
GITHUB_SHA,
11+
GITHUB_TOKEN,
12+
POLLING_INTERVAL,
13+
RETRIES,
14+
} = process.env
15+
16+
const octokit = new Octokit({ auth: GITHUB_TOKEN })
17+
const owner = 'DataDog'
18+
const repo = 'dd-trace-js'
19+
const ref = context.payload.pull_request?.head.sha || GITHUB_SHA
20+
const params = { owner, repo, ref }
21+
const checkConclusionEmojis = {
22+
action_required: '🔶',
23+
cancelled: '🚫',
24+
failure: '❌',
25+
neutral: '⚪',
26+
success: '✅',
27+
skipped: '⏭️',
28+
stale: '🔄',
29+
timed_out: '⌛',
30+
}
31+
32+
let retries = 0
33+
34+
async function hasCompleted () {
35+
const { data: inProgressRuns } = await octokit.rest.checks.listForRef({
36+
...params,
37+
per_page: 1, // Minimum is 1 but we don't need any pages.
38+
status: 'in_progress',
39+
})
40+
41+
// If there are any in progress runs it means we're not ready to check
42+
// statuses. We will always have minimum 1 for the All Green job.
43+
if (inProgressRuns.total_count > 1) return false
44+
45+
const { data: queuedRuns } = await octokit.rest.checks.listForRef({
46+
...params,
47+
per_page: 1, // Minimum is 1 but we don't need any pages.
48+
status: 'queued',
49+
})
50+
51+
// Same as above, but jobs that are queued are not even in progress yet.
52+
if (queuedRuns.total_count > 0) return false
53+
54+
return true
55+
}
56+
57+
async function checkCompleted () {
58+
if (RETRIES && retries > RETRIES) {
59+
throw new Error(`State is still pending after ${RETRIES} retries.`)
60+
}
61+
62+
if (!await hasCompleted()) {
63+
console.log(`Status is still pending, waiting for ${POLLING_INTERVAL} minutes before retrying.`)
64+
await setTimeout(POLLING_INTERVAL * 60_000)
65+
console.log('Retrying.')
66+
retries++
67+
await checkCompleted()
68+
}
69+
}
70+
71+
async function checkAllGreen () {
72+
let checkRuns
73+
74+
try {
75+
await checkCompleted()
76+
} finally {
77+
checkRuns = await octokit.paginate(
78+
'GET /repos/:owner/:repo/commits/:ref/check-runs',
79+
{
80+
...params,
81+
per_page: 100,
82+
}
83+
)
84+
85+
printSummary(checkRuns)
86+
}
87+
88+
const allGreen = !checkRuns.some(run => (
89+
run.conclusion === 'failure' || run.conclusion === 'timed_out'
90+
))
91+
92+
if (allGreen) {
93+
console.log('All jobs were successful.')
94+
} else {
95+
throw new Error('One or more jobs failed.')
96+
}
97+
}
98+
99+
async function printSummary (checkRuns) {
100+
const header = [
101+
{ data: 'name', header: true },
102+
{ data: 'status', header: true },
103+
{ data: 'conclusion', header: true },
104+
{ data: 'started_at', header: true },
105+
{ data: 'completed_at', header: true },
106+
]
107+
108+
const body = checkRuns.map(run => [
109+
run.name,
110+
run.status,
111+
run.conclusion ? `${run.conclusion} ${checkConclusionEmojis[run.conclusion]}` : ' ',
112+
run.started_at,
113+
run.completed_at ?? ' ',
114+
])
115+
116+
await summary
117+
.addHeading('Checks Summary')
118+
.addTable([header, ...body])
119+
.write()
120+
}
121+
122+
console.log(`Polling status for ref: ${ref}.`)
123+
124+
if (DELAY) {
125+
console.log(`Waiting for ${DELAY} minutes before starting.`)
126+
await setTimeout(DELAY * 60_000)
127+
}
128+
129+
await checkAllGreen()

yarn.lock

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,55 @@
22
# yarn lockfile v1
33

44

5+
"@actions/core@^3.0.0":
6+
version "3.0.0"
7+
resolved "https://registry.yarnpkg.com/@actions/core/-/core-3.0.0.tgz#89cb07c119e9b46a649ad5f355e77de9b3108cf8"
8+
integrity sha512-zYt6cz+ivnTmiT/ksRVriMBOiuoUpDCJJlZ5KPl2/FRdvwU3f7MPh9qftvbkXJThragzUZieit2nyHUyw53Seg==
9+
dependencies:
10+
"@actions/exec" "^3.0.0"
11+
"@actions/http-client" "^4.0.0"
12+
13+
"@actions/exec@^3.0.0":
14+
version "3.0.0"
15+
resolved "https://registry.yarnpkg.com/@actions/exec/-/exec-3.0.0.tgz#8c3464d20f0aa4068707757021d7e3c01a7ee203"
16+
integrity sha512-6xH/puSoNBXb72VPlZVm7vQ+svQpFyA96qdDBvhB8eNZOE8LtPf9L4oAsfzK/crCL8YZ+19fKYVnM63Sl+Xzlw==
17+
dependencies:
18+
"@actions/io" "^3.0.2"
19+
20+
"@actions/github@^9.0.0":
21+
version "9.0.0"
22+
resolved "https://registry.yarnpkg.com/@actions/github/-/github-9.0.0.tgz#c86dae4128b2a6987271e2663bee9e766464840a"
23+
integrity sha512-yJ0RoswsAaKcvkmpCE4XxBRiy/whH2SdTBHWzs0gi4wkqTDhXMChjSdqBz/F4AeiDlP28rQqL33iHb+kjAMX6w==
24+
dependencies:
25+
"@actions/http-client" "^3.0.2"
26+
"@octokit/core" "^7.0.6"
27+
"@octokit/plugin-paginate-rest" "^14.0.0"
28+
"@octokit/plugin-rest-endpoint-methods" "^17.0.0"
29+
"@octokit/request" "^10.0.7"
30+
"@octokit/request-error" "^7.1.0"
31+
undici "^6.23.0"
32+
33+
"@actions/http-client@^3.0.2":
34+
version "3.0.2"
35+
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-3.0.2.tgz#3db9c83af9d29d51ac8c30b45bc17f7014beb1b2"
36+
integrity sha512-JP38FYYpyqvUsz+Igqlc/JG6YO9PaKuvqjM3iGvaLqFnJ7TFmcLyy2IDrY0bI0qCQug8E9K+elv5ZNfw62ZJzA==
37+
dependencies:
38+
tunnel "^0.0.6"
39+
undici "^6.23.0"
40+
41+
"@actions/http-client@^4.0.0":
42+
version "4.0.0"
43+
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-4.0.0.tgz#f9754133c22802466482bf96321d42f2dba1fc82"
44+
integrity sha512-QuwPsgVMsD6qaPD57GLZi9sqzAZCtiJT8kVBCDpLtxhL5MydQ4gS+DrejtZZPdIYyB1e95uCK9Luyds7ybHI3g==
45+
dependencies:
46+
tunnel "^0.0.6"
47+
undici "^6.23.0"
48+
49+
"@actions/io@^3.0.2":
50+
version "3.0.2"
51+
resolved "https://registry.yarnpkg.com/@actions/io/-/io-3.0.2.tgz#6f89b27a159d109836d983efa283997c23b92284"
52+
integrity sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==
53+
554
"@babel/code-frame@^7.28.6", "@babel/code-frame@^7.29.0":
655
version "7.29.0"
756
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.29.0.tgz#7cd7a59f15b3cc0dcd803038f7792712a7d0b15c"
@@ -585,14 +634,14 @@
585634
"@octokit/types" "^16.0.0"
586635
bottleneck "^2.15.3"
587636

588-
"@octokit/request-error@^7.0.0", "@octokit/request-error@^7.0.2":
637+
"@octokit/request-error@^7.0.0", "@octokit/request-error@^7.0.2", "@octokit/request-error@^7.1.0":
589638
version "7.1.0"
590639
resolved "https://registry.yarnpkg.com/@octokit/request-error/-/request-error-7.1.0.tgz#440fa3cae310466889778f5a222b47a580743638"
591640
integrity sha512-KMQIfq5sOPpkQYajXHwnhjCC0slzCNScLHs9JafXc4RAJI+9f+jNDlBNaIMTvazOPLgb4BnlhGJOTbnN0wIjPw==
592641
dependencies:
593642
"@octokit/types" "^16.0.0"
594643

595-
"@octokit/request@^10.0.6":
644+
"@octokit/request@^10.0.6", "@octokit/request@^10.0.7":
596645
version "10.0.8"
597646
resolved "https://registry.yarnpkg.com/@octokit/request/-/request-10.0.8.tgz#6609a5a38ad6f8ee203d9eb8ac9361d906a4414e"
598647
integrity sha512-SJZNwY9pur9Agf7l87ywFi14W+Hd9Jg6Ifivsd33+/bGUQIjNujdFiXII2/qSlN2ybqUHfp5xpekMEjIBTjlSw==
@@ -4031,16 +4080,7 @@ streamsearch@^1.1.0:
40314080
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
40324081
integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==
40334082

4034-
"string-width-cjs@npm:string-width@^4.2.0":
4035-
version "4.2.3"
4036-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
4037-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
4038-
dependencies:
4039-
emoji-regex "^8.0.0"
4040-
is-fullwidth-code-point "^3.0.0"
4041-
strip-ansi "^6.0.1"
4042-
4043-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
4083+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
40444084
version "4.2.3"
40454085
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
40464086
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -4104,14 +4144,7 @@ string_decoder@~1.1.1:
41044144
dependencies:
41054145
safe-buffer "~5.1.0"
41064146

4107-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
4108-
version "6.0.1"
4109-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
4110-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
4111-
dependencies:
4112-
ansi-regex "^5.0.1"
4113-
4114-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
4147+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
41154148
version "6.0.1"
41164149
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
41174150
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -4223,6 +4256,11 @@ tslib@^2.4.0, tslib@^2.5.0:
42234256
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
42244257
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==
42254258

4259+
tunnel@^0.0.6:
4260+
version "0.0.6"
4261+
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c"
4262+
integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==
4263+
42264264
type-check@^0.4.0, type-check@~0.4.0:
42274265
version "0.4.0"
42284266
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"
@@ -4339,6 +4377,11 @@ undici-types@~5.26.4:
43394377
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
43404378
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
43414379

4380+
undici@^6.23.0:
4381+
version "6.23.0"
4382+
resolved "https://registry.yarnpkg.com/undici/-/undici-6.23.0.tgz#7953087744d9095a96f115de3140ca3828aff3a4"
4383+
integrity sha512-VfQPToRA5FZs/qJxLIinmU59u0r7LXqoJkCzinq3ckNJp3vKEh7jTWN589YQ5+aoAC/TGRLyJLCPKcLQbM8r9g==
4384+
43424385
universal-github-app-jwt@^2.2.0:
43434386
version "2.2.2"
43444387
resolved "https://registry.yarnpkg.com/universal-github-app-jwt/-/universal-github-app-jwt-2.2.2.tgz#38537e5a7d154085a35f97601a5e30e9e17717df"
@@ -4464,7 +4507,7 @@ workerpool@^9.2.0:
44644507
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-9.3.4.tgz#f6c92395b2141afd78e2a889e80cb338fe9fca41"
44654508
integrity sha512-TmPRQYYSAnnDiEB0P/Ytip7bFGvqnSU6I2BcuSw7Hx+JSg/DsUi5ebYfc8GYaSdpuvOcEs6dXxPurOYpe9QFwg==
44664509

4467-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
4510+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
44684511
version "7.0.0"
44694512
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
44704513
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -4482,15 +4525,6 @@ wrap-ansi@^6.2.0:
44824525
string-width "^4.1.0"
44834526
strip-ansi "^6.0.0"
44844527

4485-
wrap-ansi@^7.0.0:
4486-
version "7.0.0"
4487-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
4488-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
4489-
dependencies:
4490-
ansi-styles "^4.0.0"
4491-
string-width "^4.1.0"
4492-
strip-ansi "^6.0.0"
4493-
44944528
wrap-ansi@^8.1.0:
44954529
version "8.1.0"
44964530
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)