From f67964df0dfc205bc490365d9c5abcbd96d1f23f Mon Sep 17 00:00:00 2001 From: Michael Mickelson Date: Mon, 17 Aug 2020 09:29:38 -0600 Subject: [PATCH 1/4] Add a tip for deploying with Github Actions The tip should lay out how to correctly configure a step to deploy an application via Github Actions. See issue #345 for more details --- readme.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/readme.md b/readme.md index 3e168725..69d80ba1 100644 --- a/readme.md +++ b/readme.md @@ -387,3 +387,19 @@ 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 + npx gh-pages -d build -u "github-actions-bot " + 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. From 41efe3805a4551849a421290ce27455f46d1ab81 Mon Sep 17 00:00:00 2001 From: Michael Mickelson Date: Mon, 17 Aug 2020 09:31:44 -0600 Subject: [PATCH 2/4] Add link to #345 to deploy tip --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 69d80ba1..3767d00d 100644 --- a/readme.md +++ b/readme.md @@ -403,3 +403,5 @@ In order to deploy with Github Actions, you will need to define a user and set t ``` 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 From 057903e1af61fc569b7ed8aae066fa33e799f5ce Mon Sep 17 00:00:00 2001 From: Michael Mickelson Date: Sun, 28 Feb 2021 08:41:22 -0700 Subject: [PATCH 3/4] Add GITHUB_REPOSITORY env to GitHub Action tip The hard-coded repository name can be replaced with the use of the GITHUB_REPOSITORY environmental variable available to the runner by default. The GitHub Actions tip has been updated to reflect this feature. --- readme.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 3767d00d..da4ae8ca 100644 --- a/readme.md +++ b/readme.md @@ -393,15 +393,14 @@ If `gh-pages` fails, you may find that you need to manually clean up the cache d 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 + git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git npx gh-pages -d build -u "github-actions-bot " 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. +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. `GITHUB_REPOSITORY` is the owner and repository name and is also passed in automatically, but does not need to be added to the `env` list. See [Issue #345](https://github.com/tschaub/gh-pages/issues/345) for more information From b089ca81e2d4573348be9f0b1d79c90cbc3ea625 Mon Sep 17 00:00:00 2001 From: Michael Mickelson Date: Sun, 28 Feb 2021 08:52:01 -0700 Subject: [PATCH 4/4] Add named script example for GitHub Actions When executing the gh-pages command via a script defined inside the packages.json file, it requires the addition of an `--` parameter to properly pass the user information into the `gh-pages` command. A new example has been added reflecting that advice. This commit also includes minor formatting fixes and improvements the the existing GitHub Actions example. --- readme.md | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/readme.md b/readme.md index da4ae8ca..8aee748a 100644 --- a/readme.md +++ b/readme.md @@ -388,19 +388,42 @@ The `gh-pages` module writes temporary files to a `node_modules/.cache/gh-pages` 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 +### 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 +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 -``` - - name: Deploy with gh-pages - run: | - git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git - npx gh-pages -d build -u "github-actions-bot " - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +```yaml +- name: Deploy with gh-pages + run: | + git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git + npx gh-pages -d build -u "github-actions-bot " + 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. `GITHUB_REPOSITORY` is the owner and repository name and is also passed in automatically, but does not need to be added to the `env` list. +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. `GITHUB_REPOSITORY` is the owner and repository name and is also passed in automatically, but does not need to be added to the `env` list. See [Issue #345](https://github.com/tschaub/gh-pages/issues/345) for more information + +#### Deploying with GitHub Actions and a named script + +If you are using a named script in the `package.json` file to deploy, you will need to ensure you pass the variables properly to the wrapped `gh-pages` script. Given the `package.json` script below: + +```json +"scripts": { + "deploy": "gh-pages -d build" +} +``` + +You will need to utilize the `--` option to pass any additional arguments: + +```yaml +- name: Deploy with gh-pages + run: | + git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git + npm run deploy -- -u "github-actions-bot " + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + +See [Pull Request #368](https://github.com/tschaub/gh-pages/pull/368) for more information.