-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathget-version.js
More file actions
38 lines (36 loc) · 1.29 KB
/
get-version.js
File metadata and controls
38 lines (36 loc) · 1.29 KB
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
34
35
36
37
38
#!/usr/bin/env node
/**
* Outputs the next or current version of the SDK package based on the latest
* published version and provided version increment type.
*
* Usage:
*
* node scripts/get-version.js [current|current-prerelease|latest|prerelease|unstable]
*
* Outputs the version to stdout.
*/
import { execSync } from "child_process";
import * as semver from "semver";
import { calculateVersion } from "./calculate-version.js";
async function getLatestVersion(tag) {
try {
const result = execSync(
`npm view @github/copilot-sdk@${tag} version --registry=https://registry.npmjs.org`,
{ encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }
);
const version = result.trim();
if (!semver.valid(version)) {
console.error(`Invalid version returned from npm for tag "${tag}": "${version}"`);
process.exit(1);
}
return version;
} catch {
// Tag doesn't exist yet
return null;
}
}
const command = process.argv[2];
const latest = await getLatestVersion("latest");
const prerelease = await getLatestVersion("prerelease");
const unstable = command === "unstable" ? await getLatestVersion("unstable") : undefined;
console.log(calculateVersion(command, { latest, prerelease, unstable }));