Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow GIT_USER env var to be unset if SSH is used #5840

Merged
merged 17 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion examples/classic-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ This command generates static content into the `build` directory and can be serv

### Deployment

Using SSH:
Josh-Cena marked this conversation as resolved.
Show resolved Hide resolved

```
$ USE_SSH=true yarn deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
$ GIT_USER=<Your GitHub username> yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
10 changes: 9 additions & 1 deletion examples/classic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ This command generates static content into the `build` directory and can be serv

### Deployment

Using SSH:

```
$ USE_SSH=true yarn deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
$ GIT_USER=<Your GitHub username> yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
10 changes: 9 additions & 1 deletion examples/facebook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ This command generates static content into the `build` directory and can be serv

### Deployment

Using SSH:

```
$ USE_SSH=true yarn deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
$ GIT_USER=<Your GitHub username> yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
Expand Down
10 changes: 9 additions & 1 deletion packages/create-docusaurus/templates/facebook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ This command generates static content into the `build` directory and can be serv

### Deployment

Using SSH:

```
$ USE_SSH=true yarn deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
$ GIT_USER=<Your GitHub username> yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
Expand Down
10 changes: 9 additions & 1 deletion packages/create-docusaurus/templates/shared/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ This command generates static content into the `build` directory and can be serv

### Deployment

Using SSH:

```
$ USE_SSH=true yarn deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
$ GIT_USER=<Your GitHub username> yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
22 changes: 16 additions & 6 deletions packages/docusaurus/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,22 @@ This behavior can have SEO impacts and create relative link issues.
throw new Error('Git not installed or on the PATH!');
}

const currentRepoUrl = shell
.exec('git config --get remote.origin.url')
.stdout.trim();

const repoUrlUseSSH =
currentRepoUrl.match(/^ssh:\/\//) !== null ||
currentRepoUrl.match(/^([\w\-]+@)?[\w.\-]+:[\w.\-\/_]+(\.git)?/) !== null;
wpyoga marked this conversation as resolved.
Show resolved Hide resolved

const envUseSSH =
process.env.USE_SSH !== undefined &&
process.env.USE_SSH.toLowerCase() === 'true';

const useSSH = envUseSSH || repoUrlUseSSH;

const gitUser = process.env.GIT_USER;
if (!gitUser) {
if (!gitUser && !useSSH) {
throw new Error('Please set the GIT_USER environment variable!');
}

Expand Down Expand Up @@ -128,24 +142,20 @@ Try using DEPLOYMENT_BRANCH=main or DEPLOYMENT_BRANCH=master`);
gitCredentials = `${gitCredentials}:${gitPass}`;
}

const useSSH = process.env.USE_SSH;
const remoteBranch = buildUrl(
githubHost,
githubPort,
gitCredentials,
organizationName,
projectName,
useSSH !== undefined && useSSH.toLowerCase() === 'true',
useSSH,
);

console.log(
`${chalk.cyan('Remote branch:')} ${obfuscateGitPass(remoteBranch)}`,
);

// Check if this is a cross-repo publish.
const currentRepoUrl = shell
.exec('git config --get remote.origin.url')
.stdout.trim();
const crossRepoPublish = !currentRepoUrl.endsWith(
`${organizationName}/${projectName}.git`,
);
Expand Down
13 changes: 3 additions & 10 deletions website/docs/deployment.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,15 @@ By default, GitHub Pages runs published files through [Jekyll](https://jekyllrb.

### Environment settings {#environment-settings}

Specify the Git user as an environment variable.

| Name | Description |
| --- | --- |
| `GIT_USER` | The username for a GitHub account that has commit access to this repo. For your own repositories, this will usually be your GitHub username. The specified `GIT_USER` must have push access to the repository specified in the combination of `organizationName` and `projectName`. |

Optional parameters, also set as environment variables:
Optional parameters, set as environment variables:

| Name | Description |
| --- | --- |
| `USE_SSH` | Set to `true` to use SSH instead of the default HTTPS for the connection to the GitHub repo. |
| `GIT_USER` | The username for a GitHub account that has commit access to this repo. For your own repositories, this will usually be your GitHub username. The specified `GIT_USER` must have push access to the repository specified in the combination of `organizationName` and `projectName`. If SSH is not used, this env variable is required. Otherwise, it is ignored. |
| `GIT_PASS` | Password (or token) of the `git` user (specified by `GIT_USER`). For example, to facilitate non-interactive deployment (e.g. continuous deployment) |
| `DEPLOYMENT_BRANCH` | The branch that the website will be deployed to, defaults to `gh-pages`. For GitHub Pages Organization repos (`config.projectName` ending in `github.io`), this env variable is required. |
| `CURRENT_BRANCH` | The branch that contains the latest docs changes that will be deployed. Usually, the branch will be `main`, but it could be any branch (default or otherwise) except for `gh-pages`. If nothing is set for this variable, then the current branch will be used. |
| `GIT_PASS` | Password (or token) of the `git` user (specified by `GIT_USER`). For example, to facilitate non-interactive deployment (e.g. continuous deployment) |

GitHub enterprise installations should work in the same manner as github.com; you only need to set the organization's GitHub Enterprise host as an environment variable:

Expand Down Expand Up @@ -229,7 +224,6 @@ jobs:
- name: Release to GitHub Pages
env:
USE_SSH: true
GIT_USER: git
run: |
git config --global user.email "actions@github.com"
git config --global user.name "gh-actions"
Expand Down Expand Up @@ -361,7 +355,6 @@ trigger:
- npm run deploy
environment:
USE_SSH: true
GIT_USER: $DRONE_COMMIT_AUTHOR
GITHUB_PRIVATE_KEY:
from_secret: "git_deploy_private_key"
```
Expand Down