This commit is contained in:
REDMOND\acoates 2019-06-13 13:04:00 -07:00
Родитель c47d0723c8 0a39cfc107
Коммит 93b1fbe15b
4 изменённых файлов: 58 добавлений и 29 удалений

3
.ado/bumpFileVersions.js Normal file
Просмотреть файл

@ -0,0 +1,3 @@
// @ts-check
const {updateVersionsInFiles} = require('./versionUtils');
updateVersionsInFiles();

Просмотреть файл

@ -1,9 +1,11 @@
// @ts-check
// Used to publish this fork of react-native // Used to publish this fork of react-native
// Publish it as an attached tar asset to the GitHub release for general consumption, since we can't publish this to the npmjs npm feed // Publish it as an attached tar asset to the GitHub release for general consumption, since we can't publish this to the npmjs npm feed
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const execSync = require("child_process").execSync; const execSync = require("child_process").execSync;
const {pkgJsonPath, publishBranchName, gatherVersionInfo} = require('./versionUtils');
function exec(command) { function exec(command) {
try { try {
@ -19,38 +21,11 @@ function exec(command) {
} }
function doPublish() { function doPublish() {
const publishBranchName = process.env.BUILD_SOURCEBRANCH.match(/refs\/heads\/(.*)/)[1];
console.log(`Target branch to publish to: ${publishBranchName}`); console.log(`Target branch to publish to: ${publishBranchName}`);
const {releaseVersion, branchVersionSuffix} = gatherVersionInfo()
const tempPublishBranch = `publish-temp-${Date.now()}`; const tempPublishBranch = `publish-temp-${Date.now()}`;
const pkgJsonPath = path.resolve(__dirname, "../package.json");
let pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
let releaseVersion = pkgJson.version;
console.log(`Using ${`(.*-microsoft)(-${publishBranchName})?\\.([0-9]*)`} to match version`);
const branchVersionSuffix = (publishBranchName.match(/(fb.*merge)|(fabric)/) ? `-${publishBranchName}` : '');
const onlyTagSource = !!branchVersionSuffix;
versionStringRegEx = new RegExp(`(.*-microsoft)(-${publishBranchName})?\\.([0-9]*)`);
const versionGroups = versionStringRegEx.exec(releaseVersion);
if (versionGroups) {
releaseVersion = versionGroups[1] + branchVersionSuffix + '.' + (parseInt(versionGroups[3]) + 1);
} else {
if (releaseVersion.indexOf("-") === -1) {
releaseVersion = releaseVersion + `-microsoft${branchVersionSuffix}.0`;
} else {
console.log("Invalid version to publish");
exit(1);
}
}
pkgJson.version = releaseVersion;
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
console.log(`Updating package.json to version ${releaseVersion}`);
exec(`git checkout -b ${tempPublishBranch}`); exec(`git checkout -b ${tempPublishBranch}`);
exec(`git add ${pkgJsonPath}`); exec(`git add ${pkgJsonPath}`);
@ -59,6 +34,7 @@ function doPublish() {
exec(`git push origin HEAD:${tempPublishBranch} --follow-tags --verbose`); exec(`git push origin HEAD:${tempPublishBranch} --follow-tags --verbose`);
exec(`git push origin tag v${releaseVersion}`); exec(`git push origin tag v${releaseVersion}`);
const onlyTagSource = !!branchVersionSuffix;
if (!onlyTagSource) { if (!onlyTagSource) {
// -------- Generating Android Artifacts with JavaDoc // -------- Generating Android Artifacts with JavaDoc
exec("gradlew installArchives"); exec("gradlew installArchives");

Просмотреть файл

@ -35,6 +35,11 @@ jobs:
inputs: inputs:
script: npm install script: npm install
- task: CmdLine@2
displayName: Bump package version
inputs:
script: node .ado/bumpFileVersions.js
- task: NuGetCommand@2 - task: NuGetCommand@2
displayName: NuGet restore displayName: NuGet restore
inputs: inputs:

45
.ado/versionUtils.js Normal file
Просмотреть файл

@ -0,0 +1,45 @@
// @ts-check
const fs = require("fs");
const path = require("path");
const pkgJsonPath = path.resolve(__dirname, "../package.json");
const publishBranchName = process.env.BUILD_SOURCEBRANCH.match(/refs\/heads\/(.*)/)[1];
function gatherVersionInfo() {
let pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
let releaseVersion = pkgJson.version;
const branchVersionSuffix = (publishBranchName.match(/(fb.*merge)|(fabric)/) ? `-${publishBranchName}` : '');
return {pkgJson, releaseVersion, branchVersionSuffix};
}
function updateVersionsInFiles() {
let {pkgJson, releaseVersion, branchVersionSuffix} = gatherVersionInfo();
const versionStringRegEx = new RegExp(`(.*-microsoft)(-${publishBranchName})?\\.([0-9]*)`);
const versionGroups = versionStringRegEx.exec(releaseVersion);
if (versionGroups) {
releaseVersion = versionGroups[1] + branchVersionSuffix + '.' + (parseInt(versionGroups[3]) + 1);
} else {
if (releaseVersion.indexOf("-") === -1) {
releaseVersion = releaseVersion + `-microsoft${branchVersionSuffix}.0`;
} else {
console.log("Invalid version to publish");
process.exit(1);
}
}
pkgJson.version = releaseVersion;
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
console.log(`Updating package.json to version ${releaseVersion}`);
return {releaseVersion, branchVersionSuffix};
}
module.exports = {
gatherVersionInfo,
publishBranchName,
pkgJsonPath,
updateVersionsInFiles
}