Fix website deploys on master

Summary:
Use newer CircleCI 2.0 environment variable names, being consistent with CircleCI config.
Closes https://github.com/facebook/react-native/pull/16778

Differential Revision: D6288751

Pulled By: hramos

fbshipit-source-id: 079ffaaea1ed3b715a12b07ed7738750672eee4e
This commit is contained in:
Héctor Ramos 2017-11-09 13:18:53 -08:00 committed by Facebook Github Bot
parent 1f40c95076
commit e04f82ce2b
1 changed files with 104 additions and 93 deletions

View File

@ -25,6 +25,7 @@ const {
const CIRCLE_BRANCH = process.env.CIRCLE_BRANCH;
const CIRCLE_PROJECT_USERNAME = process.env.CIRCLE_PROJECT_USERNAME;
const CI_PULL_REQUEST = process.env.CI_PULL_REQUEST;
const CIRCLE_PR_USERNAME = process.env.CIRCLE_PR_USERNAME;
const GIT_USER = process.env.GIT_USER;
const remoteBranch = `https://${GIT_USER}@github.com/facebook/react-native.git`;
@ -33,6 +34,16 @@ if (!which('git')) {
exit(1);
}
if (CIRCLE_PR_USERNAME) {
echo('Skipping website deployment, this build was triggered from a commit in a pull request.');
exit(0);
}
if (CIRCLE_PROJECT_USERNAME !== 'facebook') {
echo('Skipping website deployment, this build was not triggered by a commit on the Facebook org.');
exit(0);
}
let version;
let areVersionlessSectionsToBeDeployed = false;
if (CIRCLE_BRANCH.indexOf('-stable') !== -1) {
@ -45,47 +56,49 @@ if (CIRCLE_BRANCH.indexOf('-stable') !== -1) {
rm('-rf', 'build');
mkdir('-p', 'build');
// if current commit is tagged "latest" we do a release to gh-pages root
echo('Current commit:');
const currentCommit = exec('git rev-parse HEAD').stdout.trim();
echo('Searching for commit tagged "latest"...');
const latestTagCommit = exec('git ls-remote origin latest').stdout.split(/\s/)[0];
// pass along which branch contains latest version so that gh-pages root could mark it as latest
echo(`Searching for branch that contains commit ${latestTagCommit}...`);
const branchWithLatestTag = exec(`git branch -r --contains ${latestTagCommit}`).stdout.split('/')[1];
let latestVersion = '';
if (branchWithLatestTag.indexOf('-stable') !== -1) {
latestVersion = branchWithLatestTag.slice(0, branchWithLatestTag.indexOf('-stable'));
}
if (!CI_PULL_REQUEST && CIRCLE_PROJECT_USERNAME === 'facebook') {
echo(`Building branch ${version}, preparing to push to gh-pages`);
// if code is running in a branch in CI, commit changes to gh-pages branch
cd('build');
rm('-rf', 'react-native-gh-pages');
echo(`Building static website based on the ${version === 'next' ? 'master' : version} branch, preparing to push assets to GitHub Pages via the 'gh-pages' branch)...`);
// if code is running in a branch in CI, commit changes to gh-pages branch
cd('build');
rm('-rf', 'react-native-gh-pages');
if (exec(`git clone ${remoteBranch} react-native-gh-pages`).code !== 0) {
if (exec(`git clone ${remoteBranch} react-native-gh-pages`).code !== 0) {
echo('Error: Git clone failed');
exit(1);
}
}
cd('react-native-gh-pages');
cd('react-native-gh-pages');
if (exec('git checkout origin/gh-pages').code +
if (exec('git checkout origin/gh-pages').code +
exec('git checkout -b gh-pages').code +
exec('git branch --set-upstream-to=origin/gh-pages').code !== 0
) {
echo('Error: Git checkout gh-pages failed');
exit(1);
}
cd('releases');
let releasesFolders = ls('-d', '*');
cd('..');
let versions = releasesFolders.filter(name => name !== 'next');
if (version !== 'next' && versions.indexOf(version) === -1) {
}
cd('releases');
let releasesFolders = ls('-d', '*');
cd('..');
let versions = releasesFolders.filter(name => name !== 'next');
if (version !== 'next' && versions.indexOf(version) === -1) {
versions.push(version);
}
}
versions.sort(semverCmp).reverse();
versions.sort(semverCmp).reverse();
// generate to releases/XX when branch name indicates that it is some sort of release
if (version) {
// generate to releases/XX when branch name indicates that it is some sort of release
if (version) {
echo(`------------ DEPLOYING /releases/${version}`);
rm('-rf', `releases/${version}`);
mkdir('-p', `releases/${version}`);
@ -103,9 +116,9 @@ if (!CI_PULL_REQUEST && CIRCLE_PROJECT_USERNAME === 'facebook') {
cp('-R', toCopy, `releases/${version}`);
// versions.html is located in root of website and updated with every release
cp('../react-native/versions.html', '.');
}
// generate to root folder when commit is tagged as latest, i.e. stable and needs to be shown at the root of repo
if (currentCommit === latestTagCommit) {
}
// generate to root folder when commit is tagged as latest, i.e. stable and needs to be shown at the root of repo
if (currentCommit === latestTagCommit) {
echo('------------ DEPLOYING latest');
// leave only releases and blog folder
rm('-rf', ls('*').filter(name => (name !== 'releases') && (name !== 'blog') && (name !== 'showcase.html') && (name !== 'support.html')));
@ -121,9 +134,9 @@ if (!CI_PULL_REQUEST && CIRCLE_PROJECT_USERNAME === 'facebook') {
.filter(file => (file !== 'blog') && (file !== 'showcase.html') && (file !== 'support.html'))
.map(file => `../react-native/${file}`);
cp('-R', toCopy, '.');
}
// blog, showcase, support are versionless, we always build them in root file
if (areVersionlessSectionsToBeDeployed) {
}
// blog, showcase, support are versionless, we always build them in root file
if (areVersionlessSectionsToBeDeployed) {
echo('------------ COPYING blog');
rm('-rf', 'blog');
cp('-R', '../react-native/blog', '.');
@ -131,8 +144,8 @@ if (!CI_PULL_REQUEST && CIRCLE_PROJECT_USERNAME === 'facebook') {
cp('../react-native/showcase.html', '.');
echo('------------ COPYING support');
cp('../react-native/support.html', '.');
}
if (currentCommit === latestTagCommit || version) {
}
if (currentCommit === latestTagCommit || version) {
exec('git status');
exec('git add -A .');
if (exec('git diff-index --quiet HEAD --').code !== 0) {
@ -146,6 +159,4 @@ if (!CI_PULL_REQUEST && CIRCLE_PROJECT_USERNAME === 'facebook') {
}
}
echo('------------ gh-pages updated');
}
}