Skip to content

Commit a6d830e

Browse files
authored
chore: timeouts on PR builds by querying against npm (#20409)
As part of AWS CDK builds, we run a script that checks that the API does not introduce any breaking changes with respect to the latest published version of AWS CDK. To do so, this currently queries against the GitHub API to check what the latest releases were. However, this can fail because without using specific GitHub credentials, we are limited to 60 API calls per minute. Even [with retries](#19336), this can still timeout, in which case the build fails suddenly without an error message: ``` <thousands of lines of logs omitted> lerna success - @aws-cdk/prlint lerna success - @aws-cdk/ubergen lerna success - @aws-cdk/yarn-cling real 21m40.119s user 353m7.607s sys 27m49.086s Listing jsii packages... lerna notice cli v4.0.0 lerna info ci enabled lerna success found 254 packages Filtering on existing packages on NPM... Determining baseline version... Build version: 1.156.1. ``` To avoid this failure mode entire, this PR updates the script to check for the latest AWS CDK version by querying against npm. Both npm and GitHub should be accurate sources of truth AFAIK, and npm does not impose as stringent rate limits on its callers. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 07cc506 commit a6d830e

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

scripts/find-latest-release.js

+3-31
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,9 @@ async function main(matchRange) {
1616
throw new Error(`Not a valid range: ${matchRange}`);
1717
}
1818

19-
let releases;
20-
for (let attempt = 0; attempt < 10; attempt++) {
21-
const { stdout, error } = cp.spawnSync('curl', ['https://api.github.com/repos/aws/aws-cdk/releases?per_page=100'], { maxBuffer: 10_000_000 });
22-
if (error) { throw error; }
23-
24-
const response = JSON.parse(stdout);
25-
if (response.message) {
26-
// This is actually an error response. Only recover from throttling errors.
27-
if (!response.message.includes('API rate limit')) {
28-
throw new Error(response.message);
29-
}
30-
31-
// 60 requests/hour, so we need to sleep for a full minute to get any kind of response
32-
const sleepTime = Math.floor(Math.random() * 60 * Math.pow(2, attempt));
33-
await sleep(sleepTime * 1000);
34-
continue;
35-
}
36-
37-
releases = response;
38-
break;
39-
}
40-
if (!releases) {
41-
throw new Error('Retries exhaused');
42-
}
43-
44-
45-
const versions = releases.map(r => r.name.replace(/^v/, '')); // v1.2.3 -> 1.2.3
19+
const { stdout, error } = cp.spawnSync('npm', ['view', 'aws-cdk', 'versions', '--json'], { maxBuffer: 10_000_000 });
20+
if (error) { throw error; }
21+
const versions = JSON.parse(stdout.toString('utf-8'));
4622

4723
const sat = semver.maxSatisfying(versions, range);
4824
if (!sat) {
@@ -51,10 +27,6 @@ async function main(matchRange) {
5127
console.log(sat);
5228
}
5329

54-
function sleep(ms) {
55-
return new Promise(ok => setTimeout(ok, ms));
56-
}
57-
5830
main(process.argv[2]).catch(e => {
5931
console.error(e);
6032
process.exitCode = 1;

0 commit comments

Comments
 (0)