2021-11-06 01:07:02 +03:00
|
|
|
/**
|
2021-12-31 02:08:43 +03:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2021-11-06 01:07:02 +03:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
2021-12-01 03:48:47 +03:00
|
|
|
const {exec} = require('shelljs');
|
|
|
|
|
2021-12-04 00:15:38 +03:00
|
|
|
const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/;
|
|
|
|
|
2021-11-06 01:07:02 +03:00
|
|
|
function parseVersion(versionStr) {
|
2021-12-04 00:15:38 +03:00
|
|
|
const match = versionStr.match(VERSION_REGEX);
|
2021-11-06 01:07:02 +03:00
|
|
|
if (!match) {
|
|
|
|
throw new Error(
|
2021-11-06 01:07:02 +03:00
|
|
|
`You must pass a correctly formatted version; couldn't parse ${versionStr}`,
|
2021-11-06 01:07:02 +03:00
|
|
|
);
|
|
|
|
}
|
2021-11-06 01:07:02 +03:00
|
|
|
const [, version, major, minor, patch, prerelease] = match;
|
2021-11-06 01:07:02 +03:00
|
|
|
return {
|
2021-11-06 01:07:02 +03:00
|
|
|
version,
|
2021-11-06 01:07:02 +03:00
|
|
|
major,
|
|
|
|
minor,
|
|
|
|
patch,
|
|
|
|
prerelease,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-12-01 03:48:47 +03:00
|
|
|
function isReleaseBranch(branch) {
|
|
|
|
return branch.endsWith('-stable');
|
|
|
|
}
|
|
|
|
|
2021-12-18 05:35:48 +03:00
|
|
|
function getBranchName() {
|
|
|
|
return exec('git rev-parse --abbrev-ref HEAD', {
|
|
|
|
silent: true,
|
|
|
|
}).stdout.trim();
|
|
|
|
}
|
|
|
|
|
2021-12-01 03:48:47 +03:00
|
|
|
function isTaggedLatest(commitSha) {
|
|
|
|
return (
|
|
|
|
exec(`git rev-list -1 latest | grep ${commitSha}`, {
|
|
|
|
silent: true,
|
|
|
|
}).stdout.trim() === commitSha
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-06 01:07:02 +03:00
|
|
|
module.exports = {
|
2021-12-18 05:35:48 +03:00
|
|
|
getBranchName,
|
2021-12-01 03:48:47 +03:00
|
|
|
isTaggedLatest,
|
2021-11-06 01:07:02 +03:00
|
|
|
parseVersion,
|
2021-12-01 03:48:47 +03:00
|
|
|
isReleaseBranch,
|
2021-11-06 01:07:02 +03:00
|
|
|
};
|