diff --git a/.ado/bumpFileVersions.js b/.ado/bumpFileVersions.js new file mode 100644 index 0000000000..11a520ff5f --- /dev/null +++ b/.ado/bumpFileVersions.js @@ -0,0 +1,3 @@ +// @ts-check +const {updateVersionsInFiles} = require('./versionUtils'); +updateVersionsInFiles(); \ No newline at end of file diff --git a/.ado/publish.js b/.ado/publish.js index 0b3e637c0c..eaaecbbb7b 100644 --- a/.ado/publish.js +++ b/.ado/publish.js @@ -1,9 +1,11 @@ +// @ts-check // 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 const fs = require("fs"); const path = require("path"); const execSync = require("child_process").execSync; +const {pkgJsonPath, publishBranchName, gatherVersionInfo} = require('./versionUtils'); function exec(command) { try { @@ -19,38 +21,11 @@ function exec(command) { } function doPublish() { - const publishBranchName = process.env.BUILD_SOURCEBRANCH.match(/refs\/heads\/(.*)/)[1]; console.log(`Target branch to publish to: ${publishBranchName}`); + const {releaseVersion, branchVersionSuffix} = gatherVersionInfo() + 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 add ${pkgJsonPath}`); @@ -59,6 +34,7 @@ function doPublish() { exec(`git push origin HEAD:${tempPublishBranch} --follow-tags --verbose`); exec(`git push origin tag v${releaseVersion}`); + const onlyTagSource = !!branchVersionSuffix; if (!onlyTagSource) { // -------- Generating Android Artifacts with JavaDoc exec("gradlew installArchives"); diff --git a/.ado/publish.yml b/.ado/publish.yml index 9094733849..87b459179f 100644 --- a/.ado/publish.yml +++ b/.ado/publish.yml @@ -35,6 +35,11 @@ jobs: inputs: script: npm install + - task: CmdLine@2 + displayName: Bump package version + inputs: + script: node .ado/bumpFileVersions.js + - task: NuGetCommand@2 displayName: NuGet restore inputs: diff --git a/.ado/versionUtils.js b/.ado/versionUtils.js new file mode 100644 index 0000000000..9a74e62b02 --- /dev/null +++ b/.ado/versionUtils.js @@ -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 +} \ No newline at end of file