react-native-macos/.ado/publish.js

134 строки
4.1 KiB
JavaScript
Исходник Обычный вид История

// @ts-check
2019-03-08 01:57:21 +03:00
// 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');
2019-03-08 01:57:21 +03:00
function exec(command) {
try {
console.log(`Running command: ${command}`);
return execSync(command, {
stdio: "inherit"
});
} catch (err) {
process.exitCode = 1;
console.log(`Failure running: ${command}`);
throw err;
}
}
function doPublish() {
2019-05-01 20:17:27 +03:00
console.log(`Target branch to publish to: ${publishBranchName}`);
2019-03-08 01:57:21 +03:00
const {releaseVersion, branchVersionSuffix} = gatherVersionInfo()
2019-03-08 01:57:21 +03:00
const tempPublishBranch = `publish-temp-${Date.now()}`;
2019-03-08 01:57:21 +03:00
exec(`git checkout -b ${tempPublishBranch}`);
2019-07-30 23:03:00 +03:00
exec(`git config --global user.email "30809111+acoates-ms@users.noreply.github.com"`);
exec(`git config --global user.name "React-Native Build"`);
2019-03-08 01:57:21 +03:00
exec(`git add ${pkgJsonPath}`);
exec(`git commit -m "Applying package update to ${releaseVersion}`);
exec(`git tag v${releaseVersion}`);
exec(`git push origin HEAD:${tempPublishBranch} --follow-tags --verbose`);
exec(`git push origin tag v${releaseVersion}`);
const onlyTagSource = !!branchVersionSuffix;
2019-05-03 01:59:22 +03:00
if (!onlyTagSource) {
// -------- Generating Android Artifacts with JavaDoc
exec("gradlew installArchives");
2019-03-08 01:57:21 +03:00
2019-05-03 01:59:22 +03:00
// undo uncommenting javadoc setting
exec("git checkout ReactAndroid/gradle.properties");
}
2019-03-08 01:57:21 +03:00
// Push tar to GitHub releases
exec(`npm pack`);
2019-07-31 02:16:54 +03:00
const npmTarFileName = `../react-native-${releaseVersion}.tgz`;
const npmTarPath = path.resolve(__dirname, npmTarFileName);
fs.copyFileSync(npmTarPath, path.join(process.env.SYSTEM_DEFAULTWORKINGDIRECTORY, 'final', npmTarFileName));
2019-05-21 21:29:56 +03:00
const assetUpdateUrl = `https://uploads.github.com/repos/microsoft/react-native/releases/{id}/assets?name=react-native-${releaseVersion}.tgz`;
2019-03-08 01:57:21 +03:00
const authHeader =
"Basic " + new Buffer(":" + process.env.githubToken).toString("base64");
const userAgent = "Microsoft-React-Native-Release-Agent";
let uploadReleaseAssetUrl = "";
exec("npm install request@^2.69.0 --no-save");
const request = require("request");
const uploadTarBallToRelease = function() {
request.post(
{
url: uploadReleaseAssetUrl,
headers: {
"User-Agent": userAgent,
Authorization: authHeader,
"Content-Type": "application/octet-stream"
},
formData: {
file: fs.createReadStream(npmTarPath)
}
},
function(err, res, body) {
if (err) {
console.error(err);
process.exitCode = 1;
throw err;
}
2019-04-04 06:37:18 +03:00
console.log('Response: ' + body);
2019-03-08 01:57:21 +03:00
exec(`del ${npmTarPath}`);
exec(`git checkout ${publishBranchName}`);
exec(`git pull origin ${publishBranchName}`);
exec(`git merge ${tempPublishBranch} --no-edit`);
exec(
`git push origin HEAD:${publishBranchName} --follow-tags --verbose`
);
exec(`git branch -d ${tempPublishBranch}`);
exec(`git push origin --delete -d ${tempPublishBranch}`);
}
);
};
const createReleaseRequestBody = {
tag_name: `v${releaseVersion}`,
target_commitish: tempPublishBranch,
name: `v${releaseVersion}`,
body: `v${releaseVersion}`,
draft: false,
prerelease: true
};
console.log('createReleaseRequestBody: ' + JSON.stringify(createReleaseRequestBody, null, 2));
request.post(
{
2019-05-21 21:29:56 +03:00
url: "https://api.github.com/repos/microsoft/react-native/releases",
2019-03-08 01:57:21 +03:00
headers: {
"User-Agent": userAgent,
Authorization: authHeader
},
json: true,
body: createReleaseRequestBody
},
function(err, res, body) {
if (err) {
console.log(err);
throw new Error("Error fetching release id.");
}
console.log("Created GitHub Release: " + JSON.stringify(body, null, 2));
uploadReleaseAssetUrl = assetUpdateUrl.replace(/{id}/, body.id);
uploadTarBallToRelease();
}
);
}
doPublish();