mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 14:06:59 +02:00
Cross repo publishing (#764)
This commit is contained in:
parent
23bda1b9ce
commit
fd9a3ffb6d
2 changed files with 30 additions and 16 deletions
|
@ -66,9 +66,15 @@ if (IS_PULL_REQUEST) {
|
|||
shell.exit(0);
|
||||
}
|
||||
|
||||
// When we want to do a cross repo publish (#717), we can allow publishing to the same branch.
|
||||
const currentRepoUrl = shell.exec('git remote get-url origin').stdout.trim();
|
||||
const crossRepoPublish = !currentRepoUrl.endsWith(
|
||||
`${ORGANIZATION_NAME}/${PROJECT_NAME}.git`
|
||||
);
|
||||
|
||||
// build static html files, then push to DEPLOYMENT_BRANCH branch of specified repo
|
||||
|
||||
if (CURRENT_BRANCH === DEPLOYMENT_BRANCH) {
|
||||
if (CURRENT_BRANCH === DEPLOYMENT_BRANCH && !crossRepoPublish) {
|
||||
shell.echo(`Cannot deploy from a ${DEPLOYMENT_BRANCH} branch. Only to it`);
|
||||
shell.exit(1);
|
||||
}
|
||||
|
@ -91,20 +97,27 @@ if (
|
|||
|
||||
shell.cd(`${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
|
||||
|
||||
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 ${DEPLOYMENT_BRANCH}`).code +
|
||||
shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`)
|
||||
.code !==
|
||||
0
|
||||
) {
|
||||
shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
|
||||
shell.exit(1);
|
||||
// If the default branch is the one we're deploying to, then we'll fail to create it.
|
||||
// This is the case of a cross-repo publish, where we clone a github.io repo with a default master branch.
|
||||
const defaultBranch = shell
|
||||
.exec('git rev-parse --abbrev-ref HEAD')
|
||||
.stdout.trim();
|
||||
if (defaultBranch !== DEPLOYMENT_BRANCH) {
|
||||
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 ${DEPLOYMENT_BRANCH}`).code +
|
||||
shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`)
|
||||
.code !==
|
||||
0
|
||||
) {
|
||||
shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
|
||||
shell.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue