Skip to content

Commit 9c4dc77

Browse files
authored
Merge pull request #156 from AztecProtocol/jc/fix-ci
update fetchrelease.js script
2 parents a70afb7 + 5a18674 commit 9c4dc77

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

.github/scripts/fetchRelease.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
async function main() {
2-
const fetchOpts = { headers: {} };
2+
const headers = {
3+
'Accept': 'application/vnd.github+json',
4+
'X-GitHub-Api-Version': '2022-11-28',
5+
'User-Agent': 'aztec-starter-ci'
6+
};
37
if (process.env.GITHUB_TOKEN) {
4-
fetchOpts.headers.Authorization = `token ${process.env.GITHUB_TOKEN}`;
8+
headers.Authorization = `Bearer ${process.env.GITHUB_TOKEN}`;
59
}
610

7-
const res = await fetch('https://api.github.com/repos/AztecProtocol/aztec-packages/releases', fetchOpts);
8-
const data = await res.json();
11+
const url = 'https://api.github.com/repos/AztecProtocol/aztec-packages/releases?per_page=100';
12+
const res = await fetch(url, { headers });
13+
14+
if (!res.ok) {
15+
const body = await res.text().catch(() => '');
16+
console.error(`GitHub API error ${res.status} ${res.statusText}: ${body}`);
17+
process.exit(1);
18+
}
19+
20+
let data;
21+
try {
22+
data = await res.json();
23+
} catch (err) {
24+
console.error('Failed to parse GitHub API response as JSON', err);
25+
process.exit(1);
26+
}
27+
28+
if (!Array.isArray(data)) {
29+
console.error(`Unexpected GitHub API response (expected array): ${JSON.stringify(data, null, 2)}`);
30+
process.exit(1);
31+
}
932

1033
const release = data.find(r => !r.draft && !/nightly/i.test(r.tag_name) && !/staging/i.test(r.tag_name));
1134
if (!release) {

0 commit comments

Comments
 (0)