From 0cead4b6f9495e95b300aa017d0649748400ca37 Mon Sep 17 00:00:00 2001 From: Ricky Vetter Date: Mon, 4 Dec 2017 09:59:49 -0800 Subject: [PATCH] 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 --- lib/publish-gh-pages.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/publish-gh-pages.js b/lib/publish-gh-pages.js index d153dcace9..0c7503ea46 100755 --- a/lib/publish-gh-pages.js +++ b/lib/publish-gh-pages.js @@ -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 {