This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
const RELEASE_VERSION_PATTERN = /^\d+(?:\.\d+)*$/;
|
||||
|
||||
export function normalizeReleaseVersionTag(value) {
|
||||
if (typeof value !== "string") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const normalized = value.trim().replace(/^v/i, "");
|
||||
if (!RELEASE_VERSION_PATTERN.test(normalized)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function resolveReleaseVersion(
|
||||
env = process.env,
|
||||
fallbackVersion = "0.2.0421.2"
|
||||
) {
|
||||
const candidates = [env.EXTENSION_VERSION, env.DRONE_TAG, fallbackVersion];
|
||||
|
||||
for (const candidate of candidates) {
|
||||
const normalized = normalizeReleaseVersionTag(candidate);
|
||||
if (normalized) {
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("unable to resolve a valid release version");
|
||||
}
|
||||
Reference in New Issue
Block a user