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

Add Github Action tip to README #368

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
18 changes: 18 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,21 @@ Note that this plugin requires Git 1.9 or higher (because it uses the `--exit-co
The `gh-pages` module writes temporary files to a `node_modules/.cache/gh-pages` directory. The location of this directory can be customized by setting the `CACHE_DIR` environemnt variable.

If `gh-pages` fails, you may find that you need to manually clean up the cache directory. To remove the cache directory, run `node_modules/gh-pages/bin/gh-pages-clean` or remove `node_modules/.cache/gh-pages`.

### Deploying with Github Actions

In order to deploy with Github Actions, you will need to define a user and set the git repository for the process. See the example step below

```
# REPLACE "tschaub/gh-pages" IN THE GIT URL BELOW WITH YOUR REPOSITORY'S INFORMATION
- name: Deploy with gh-pages
run: |
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/tschaub/gh-pages.git
Comment on lines +396 to +399
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the instruction to replace the repository name in the git url is actually not necessary if you use the GITHUB_REPOSITORY environment variable 😉
https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables

git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git

npx gh-pages -d build -u "github-actions-bot <[email protected]>"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came across gh-pages via the example in the create-react-app docs: https://create-react-app.dev/docs/deployment/#step-2-install-gh-pages-and-add-deploy-to-scripts-in-packagejson

If gh-pages is executed via a named script, the command needs to be modified slightly (note the -- to pass the additional argument to the wrapped gh-pages call). Maybe this should be included as another example.

"scripts": {
   "deploy": "gh-pages -d build"
}
npm run deploy -- -u "github-actions-bot <[email protected]>"

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

The `secrets.GITHUB_TOKEN` is provided automatically as part of the Github Action and does not require any further configuration, but simply needs to be passed in as an environmental variable to the step.

See [Issue #345](https://github.com/tschaub/gh-pages/issues/345) for more information