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
|
@ -45,7 +45,8 @@ Two of the required parameters are set in the [`siteConfig.js`](api-site-config.
|
||||||
| `organizationName` | The GitHub user or organization that owns the repository. In the case of Docusaurus, that would be the "facebook" GitHub organization. |
|
| `organizationName` | The GitHub user or organization that owns the repository. In the case of Docusaurus, that would be the "facebook" GitHub organization. |
|
||||||
| `projectName` | The name of the GitHub repository for your project. For example, Docusaurus is hosted at https://github.com/facebook/docusaurus, so our project name in this case would be "docusaurus". |
|
| `projectName` | The name of the GitHub repository for your project. For example, Docusaurus is hosted at https://github.com/facebook/docusaurus, so our project name in this case would be "docusaurus". |
|
||||||
|
|
||||||
> Docusaurus also supports deploying [user or organization sites](https://help.github.com/articles/user-organization-and-project-pages/#user--organization-pages). These sites will be served from the `master` branch of the repo. So, you will want to have the Docusaurus infra, your docs, etc. in another branch (e.g., maybe call it `source`). To do this, just set `projectName` to "_username_.github.io" (where _username_ is your username or organization name on GitHub) and `organizationName` to "_username_". The publish script will automatically deploy your site to the root of the `master` branch to be served.
|
> Docusaurus also supports deploying [user or organization sites](https://help.github.com/articles/user-organization-and-project-pages/#user--organization-pages). To do this, just set `projectName` to "_username_.github.io" (where _username_ is your username or organization name on GitHub) and `organizationName` to "_username_".
|
||||||
|
> For user or org sites, the publish script will deploy these sites to the root of the `master` branch of the _username_.github.io repo. In this case, note that you will want to have the Docusaurus infra, your docs, etc. either in another branch of the _username_.github.io repo (e.g., maybe call it `source`), or in another, separated repo (e.g. in the same as the documented source code).
|
||||||
|
|
||||||
> While we recommend setting the `projectName` and `organizationName` in `siteConfig.js`, you can also use environment variables `ORGANIZATION_NAME` and `PROJECT_NAME`.
|
> While we recommend setting the `projectName` and `organizationName` in `siteConfig.js`, you can also use environment variables `ORGANIZATION_NAME` and `PROJECT_NAME`.
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,15 @@ if (IS_PULL_REQUEST) {
|
||||||
shell.exit(0);
|
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
|
// 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.echo(`Cannot deploy from a ${DEPLOYMENT_BRANCH} branch. Only to it`);
|
||||||
shell.exit(1);
|
shell.exit(1);
|
||||||
}
|
}
|
||||||
|
@ -91,20 +97,27 @@ if (
|
||||||
|
|
||||||
shell.cd(`${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
|
shell.cd(`${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`);
|
||||||
|
|
||||||
if (shell.exec(`git checkout origin/${DEPLOYMENT_BRANCH}`).code !== 0) {
|
// If the default branch is the one we're deploying to, then we'll fail to create it.
|
||||||
if (shell.exec(`git checkout --orphan ${DEPLOYMENT_BRANCH}`).code !== 0) {
|
// This is the case of a cross-repo publish, where we clone a github.io repo with a default master branch.
|
||||||
shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
|
const defaultBranch = shell
|
||||||
shell.exit(1);
|
.exec('git rev-parse --abbrev-ref HEAD')
|
||||||
}
|
.stdout.trim();
|
||||||
} else {
|
if (defaultBranch !== DEPLOYMENT_BRANCH) {
|
||||||
if (
|
if (shell.exec(`git checkout origin/${DEPLOYMENT_BRANCH}`).code !== 0) {
|
||||||
shell.exec(`git checkout -b ${DEPLOYMENT_BRANCH}`).code +
|
if (shell.exec(`git checkout --orphan ${DEPLOYMENT_BRANCH}`).code !== 0) {
|
||||||
shell.exec(`git branch --set-upstream-to=origin/${DEPLOYMENT_BRANCH}`)
|
shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
|
||||||
.code !==
|
shell.exit(1);
|
||||||
0
|
}
|
||||||
) {
|
} else {
|
||||||
shell.echo(`Error: Git checkout ${DEPLOYMENT_BRANCH} failed`);
|
if (
|
||||||
shell.exit(1);
|
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