-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathfind-latest-release.js
33 lines (29 loc) · 1.1 KB
/
find-latest-release.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Find the latest CDK release on GitHub matching a particular semver range
//
// The range can be something like '<1.2.3' to find the latest release before a given version,
// or '2' to find the latest v2 release.
//
// Only searches the most recent 100 GitHub releases, so only use this to query fairly recent versions.
const cp = require('child_process');
const semver = require('semver');
async function main(matchRange) {
if (matchRange === undefined) {
throw new Error('Usage: find-latest-release.js RANGE');
}
const range = semver.validRange(matchRange);
if (!range) {
throw new Error(`Not a valid range: ${matchRange}`);
}
const { stdout, error } = cp.spawnSync('npm', ['view', 'aws-cdk', 'versions', '--json'], { maxBuffer: 10_000_000 });
if (error) { throw error; }
const versions = JSON.parse(stdout.toString('utf-8'));
const sat = semver.maxSatisfying(versions, range);
if (!sat) {
throw new Error(`No range satisfied ${range} (on the first page of GitHub releases)`);
}
console.log(sat);
}
main(process.argv[2]).catch(e => {
console.error(e);
process.exitCode = 1;
});