mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 05:57:05 +02:00
Update deployment script to work on github.io repos as well (#256)
* Update deployment script to work on github.io repos as well * remember how index of works * CURRENT_BRANCH
This commit is contained in:
parent
76e423fba3
commit
0cead4b6f9
1 changed files with 23 additions and 15 deletions
|
@ -28,8 +28,9 @@ const PROJECT_NAME =
|
|||
process.env.CIRCLE_PROJECT_REPONAME;
|
||||
const IS_PULL_REQUEST =
|
||||
process.env.CI_PULL_REQUEST || process.env.CIRCLE_PULL_REQUEST;
|
||||
|
||||
const USE_SSH = process.env.USE_SSH;
|
||||
// github.io indicates organization repos that deploy via master. All others use gh-pages.
|
||||
const DEPLOYMENT_BRANCH = PROJECT_NAME.indexOf(".github.io") !== -1 ? "master" : "gh-pages";
|
||||
|
||||
if (!ORGANIZATION_NAME) {
|
||||
shell.echo(
|
||||
|
@ -52,14 +53,15 @@ if (USE_SSH === "true") {
|
|||
remoteBranch = `https://${GIT_USER}@github.com/${ORGANIZATION_NAME}/${PROJECT_NAME}.git`;
|
||||
}
|
||||
|
||||
// build static html files, then push to gh-pages branch of specified repo
|
||||
if (IS_PULL_REQUEST) {
|
||||
shell.echo("Skipping deploy on a pull request");
|
||||
shell.exit(0);
|
||||
}
|
||||
|
||||
if (CURRENT_BRANCH === "gh-pages") {
|
||||
shell.echo("Cannot deploy from a gh-pages branch. Only to it");
|
||||
// build static html files, then push to DEPLOYMENT_BRANCH branch of specified repo
|
||||
|
||||
if (CURRENT_BRANCH === DEPLOYMENT_BRANCH) {
|
||||
shell.echo(`Cannot deploy from a ${DEPLOYMENT_BRANCH} branch. Only to it`);
|
||||
shell.exit(1);
|
||||
}
|
||||
|
||||
|
@ -72,26 +74,27 @@ shell.cd(process.cwd());
|
|||
shell.cd("build");
|
||||
|
||||
if (
|
||||
shell.exec(`git clone ${remoteBranch} ${PROJECT_NAME}-gh-pages`).code !== 0
|
||||
shell.exec(`git clone ${remoteBranch} ${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`)
|
||||
.code !== 0
|
||||
) {
|
||||
shell.echo("Error: git clone failed");
|
||||
shell.exit(1);
|
||||
}
|
||||
|
||||
shell.cd(`${PROJECT_NAME}-gh-pages`);
|
||||
shell.cd(`${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
|
||||
|
||||
if (shell.exec("git checkout origin/gh-pages").code !== 0) {
|
||||
if (shell.exec("git checkout --orphan gh-pages").code !== 0) {
|
||||
shell.echo("Error: Git checkout gh-pages failed");
|
||||
if (shell.exec(`git checkout origin/${DEPLOYMENT_BRANCH}`).code !== 0) {
|
||||
if (shell.exec(`git checkout --orphan ${DEPLOYMENT_BRANCH}`).code !== 0) {
|
||||
shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
|
||||
shell.exit(1);
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
shell.exec("git checkout -b gh-pages").code +
|
||||
shell.exec("git branch --set-upstream-to=origin/gh-pages").code !==
|
||||
shell.exec(`git checkout -b ${DEPLOYMENT_BRANCH}`).code +
|
||||
shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`).code !==
|
||||
0
|
||||
) {
|
||||
shell.echo("Error: Git checkout gh-pages failed");
|
||||
shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
|
||||
shell.exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -100,16 +103,21 @@ shell.exec("git rm -rf .");
|
|||
|
||||
shell.cd("../..");
|
||||
|
||||
shell.cp("-R", `build/${PROJECT_NAME}/*`, `build/${PROJECT_NAME}-gh-pages/`);
|
||||
shell.cd(`build/${PROJECT_NAME}-gh-pages`);
|
||||
shell.cp(
|
||||
"-R",
|
||||
`build/${PROJECT_NAME}/*`,
|
||||
`build/${PROJECT_NAME}-${DEPLOYMENT_BRANCH}/`
|
||||
);
|
||||
shell.cd(`build/${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
|
||||
|
||||
const currentCommit = shell.exec("git rev-parse HEAD").stdout.trim();
|
||||
|
||||
shell.exec("git add --all");
|
||||
|
||||
shell.exec(
|
||||
`git commit -m "Deploy website" -m "Deploy website version based on ${currentCommit}"`
|
||||
);
|
||||
if (shell.exec("git push origin gh-pages").code !== 0) {
|
||||
if (shell.exec(`git push origin ${DEPLOYMENT_BRANCH}`).code !== 0) {
|
||||
shell.echo("Error: Git push failed");
|
||||
shell.exit(1);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue