Compare commits

..

22 Commits

Author SHA1 Message Date
peaceiris
a65bea57e7 chore(release): 3.4.1
Some checks failed
Release / release (push) Has been cancelled
2020-03-07 00:50:03 +09:00
peaceiris
9fd8cd10e7 chore(release): Add build assets 2020-03-07 00:50:02 +09:00
Shohei Ueda
fd6e5fc7ce test: Add testing for set-tokens.ts (#126)
* test: remove main
* test: add getPublishRepo()
* test: Add setPersonalToken()
* test: Add setGithubToken()
* test: add showInputs()
* test: .nojekyll already exists
* test: ignore jest/expect-expect
* refactor: squash inputs log
* fix: throw error message
2020-03-07 00:41:30 +09:00
dependabot-preview[bot]
acd0462710 deps: bump eslint-plugin-jest from 23.8.1 to 23.8.2 (#141) 2020-03-06 09:57:10 +00:00
dependabot-preview[bot]
9faed51ce9 deps: bump @typescript-eslint/eslint-plugin from 2.21.0 to 2.22.0 (#139) 2020-03-03 04:23:53 +00:00
dependabot-preview[bot]
7c45cb42ca deps: bump @typescript-eslint/parser from 2.21.0 to 2.22.0 (#138) 2020-03-03 04:16:02 +00:00
dependabot-preview[bot]
ac39f89062 deps: bump @actions/core from 1.2.2 to 1.2.3 (#140) 2020-03-03 04:08:48 +00:00
dependabot-preview[bot]
dd0b5dfc69 deps: bump @types/node from 12.12.28 to 12.12.29 (#136) 2020-03-02 12:11:32 +00:00
dependabot-preview[bot]
140391da91 deps: bump typescript from 3.8.2 to 3.8.3 (#135)
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.8.2 to 3.8.3.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v3.8.2...v3.8.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-03-02 12:10:37 +09:00
dependabot-preview[bot]
50988c17ae deps: bump eslint-plugin-jest from 23.8.0 to 23.8.1 (#134) 2020-03-02 02:57:40 +00:00
Nikos Katirtzis
a4da635d8c docs: Add Docusaurus example (#131) 2020-02-29 01:21:36 +09:00
dependabot-preview[bot]
56fe697825 deps: bump lint-staged from 10.0.7 to 10.0.8 (#129) 2020-02-26 06:24:18 +00:00
dependabot-preview[bot]
bc18026d43 deps: bump @typescript-eslint/parser from 2.20.0 to 2.21.0 (#127) 2020-02-25 03:17:48 +00:00
dependabot-preview[bot]
ce61f4bf52 deps: bump @typescript-eslint/eslint-plugin from 2.20.0 to 2.21.0 (#128) 2020-02-25 03:07:20 +00:00
Shohei Ueda
b81e21a3dc ci: Add deployment status check workflow (#125) 2020-02-24 20:35:46 +09:00
peaceiris
79cc24d126 chore(release): Remove build assets [skip ci] 2020-02-24 19:56:53 +09:00
peaceiris
364c31d33b chore(release): 3.4.0
Some checks failed
Release / release (push) Has been cancelled
2020-02-24 19:56:52 +09:00
peaceiris
3c65337a25 chore(release): Add build assets 2020-02-24 19:56:51 +09:00
peaceiris
7b12ca9aeb docs: update 2020-02-24 19:48:18 +09:00
Shohei Ueda
62e7849d7a docs: Put github_token as first example (#115)
* docs: Put github_token as first example
* docs: move Create SSH Deploy Key
* docs: remove github_token section
* docs: remove badge
* docs: remove How to add CNAME
* docs: remove Deployment completed but you cannot read
2020-02-24 19:35:55 +09:00
dependabot-preview[bot]
e0af1f7de0 deps: bump eslint-plugin-jest from 23.7.0 to 23.8.0 (#124)
Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 23.7.0 to 23.8.0.
- [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases)
- [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v23.7.0...v23.8.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-24 19:04:41 +09:00
peaceiris
67f77416c9 chore(release): Remove build assets [skip ci] 2020-02-24 18:50:44 +09:00
15 changed files with 611 additions and 358 deletions

View File

@@ -0,0 +1,14 @@
name: Check Pages Status
on: page_build
jobs:
pages-status-check:
runs-on: ubuntu-18.04
steps:
- name: check status
run: |
status = '${{ github.event.build.status }}'
errormsg = '${{ github.event.build.error.message }}'
assert status == 'built', 'Status: {status}\nError: {errormsg}'.format(status, errormsg)
shell: python

View File

@@ -2,6 +2,50 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [3.4.1](https://github.com/peaceiris/actions-gh-pages/compare/v3.4.0...v3.4.1) (2020-03-06)
### ci
* Add deployment status check workflow (#125) ([b81e21a](https://github.com/peaceiris/actions-gh-pages/commit/b81e21a3dc037a4037bef6bd44bc1bee36d3626f)), closes [#125](https://github.com/peaceiris/actions-gh-pages/issues/125)
### deps
* bump @actions/core from 1.2.2 to 1.2.3 (#140) ([ac39f89](https://github.com/peaceiris/actions-gh-pages/commit/ac39f890622b7f6950b6eb9cc43666c033277fb1)), closes [#140](https://github.com/peaceiris/actions-gh-pages/issues/140)
* bump @types/node from 12.12.28 to 12.12.29 (#136) ([dd0b5df](https://github.com/peaceiris/actions-gh-pages/commit/dd0b5dfc6981e11137b2a1fad785d5342c0b5bc0)), closes [#136](https://github.com/peaceiris/actions-gh-pages/issues/136)
* bump @typescript-eslint/eslint-plugin from 2.20.0 to 2.21.0 (#128) ([ce61f4b](https://github.com/peaceiris/actions-gh-pages/commit/ce61f4bf52b32c725cd5837e7b56d7a587a32af6)), closes [#128](https://github.com/peaceiris/actions-gh-pages/issues/128)
* bump @typescript-eslint/eslint-plugin from 2.21.0 to 2.22.0 (#139) ([9faed51](https://github.com/peaceiris/actions-gh-pages/commit/9faed51ce97835a66741dc3d9368dc3402c12174)), closes [#139](https://github.com/peaceiris/actions-gh-pages/issues/139)
* bump @typescript-eslint/parser from 2.20.0 to 2.21.0 (#127) ([bc18026](https://github.com/peaceiris/actions-gh-pages/commit/bc18026d43cd46451191723b7502ac0057177f5c)), closes [#127](https://github.com/peaceiris/actions-gh-pages/issues/127)
* bump @typescript-eslint/parser from 2.21.0 to 2.22.0 (#138) ([7c45cb4](https://github.com/peaceiris/actions-gh-pages/commit/7c45cb42cade3f3bc0dab3c894044809b8ed4b4a)), closes [#138](https://github.com/peaceiris/actions-gh-pages/issues/138)
* bump eslint-plugin-jest from 23.8.0 to 23.8.1 (#134) ([50988c1](https://github.com/peaceiris/actions-gh-pages/commit/50988c17ae540cf540cac254aeae22e8f1cbad46)), closes [#134](https://github.com/peaceiris/actions-gh-pages/issues/134)
* bump eslint-plugin-jest from 23.8.1 to 23.8.2 (#141) ([acd0462](https://github.com/peaceiris/actions-gh-pages/commit/acd04627103a2d4d7620edca1bb74897a8180a84)), closes [#141](https://github.com/peaceiris/actions-gh-pages/issues/141)
* bump lint-staged from 10.0.7 to 10.0.8 (#129) ([56fe697](https://github.com/peaceiris/actions-gh-pages/commit/56fe6978255c0fb44f70c59879daca5984de7ac4)), closes [#129](https://github.com/peaceiris/actions-gh-pages/issues/129)
* bump typescript from 3.8.2 to 3.8.3 (#135) ([140391d](https://github.com/peaceiris/actions-gh-pages/commit/140391da91a8b458871e276b87abbfe7c0557c8c)), closes [#135](https://github.com/peaceiris/actions-gh-pages/issues/135)
### docs
* Add Docusaurus example (#131) ([a4da635](https://github.com/peaceiris/actions-gh-pages/commit/a4da635d8c553a327144267b3826e838aefb1561)), closes [#131](https://github.com/peaceiris/actions-gh-pages/issues/131)
### test
* Add testing for set-tokens.ts (#126) ([fd6e5fc](https://github.com/peaceiris/actions-gh-pages/commit/fd6e5fc7ce07cfd94a2311f7ac112bd797c3aee7)), closes [#126](https://github.com/peaceiris/actions-gh-pages/issues/126)
# [3.4.0](https://github.com/peaceiris/actions-gh-pages/compare/v3.3.0...v3.4.0) (2020-02-24)
### deps
* bump eslint-plugin-jest from 23.7.0 to 23.8.0 (#124) ([e0af1f7](https://github.com/peaceiris/actions-gh-pages/commit/e0af1f7de04642a5e810c38b24abd507d81b86be)), closes [#124](https://github.com/peaceiris/actions-gh-pages/issues/124)
### docs
* Put github_token as first example (#115) ([62e7849](https://github.com/peaceiris/actions-gh-pages/commit/62e7849d7ab5a2167baf529dc8fd9034fcf41c43)), closes [#115](https://github.com/peaceiris/actions-gh-pages/issues/115)
* update ([7b12ca9](https://github.com/peaceiris/actions-gh-pages/commit/7b12ca9aebe1ddcf25dc1c6fd793308e703b4ec7))
# [3.3.0](https://github.com/peaceiris/actions-gh-pages/compare/v3.2.0...v3.3.0) (2020-02-24) # [3.3.0](https://github.com/peaceiris/actions-gh-pages/compare/v3.2.0...v3.3.0) (2020-02-24)

272
README.md
View File

@@ -28,9 +28,7 @@ The next example step will deploy `./public` directory to the remote `gh-pages`
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
# github_token: ${{ secrets.GITHUB_TOKEN }}
# personal_token: ${{ secrets.PERSONAL_TOKEN }}
publish_dir: ./public publish_dir: ./public
``` ```
@@ -40,19 +38,17 @@ Three tokens are supported.
| Token | Private repo | Public repo | Protocol | Setup | | Token | Private repo | Public repo | Protocol | Setup |
|---|:---:|:---:|---|---| |---|:---:|:---:|---|---|
| `github_token` | ✅️ | (1) | HTTPS | Unnecessary | | `github_token` | ✅️ | ✅️ | HTTPS | Unnecessary |
| `personal_token` | ✅️ | ✅️ | HTTPS | Necessary |
| `deploy_key` | ✅️ | ✅️ | SSH | Necessary | | `deploy_key` | ✅️ | ✅️ | SSH | Necessary |
| `personal_token` | ✅️ | ✅️ | HTTPS | Necessary |
1. ~~Currently, GitHub Actions does not support to trigger a GitHub Pages build event using GITHUB_TOKEN on a public repository.~~ Maybe, we can use it but there is no official announcement by GitHub.
### Supported Platforms ### Supported Platforms
| runs-on | `deploy_key` | `github_token` | `personal_token` | | runs-on | `github_token` | `deploy_key` | `personal_token` |
|---|:---:|:---:|:---:| |---|:---:|:---:|:---:|
| ubuntu-18.04 | ✅️ | ✅️ | ✅️ | | ubuntu-18.04 | ✅️ | ✅️ | ✅️ |
| macos-latest | ✅️ | ✅️ | ✅️ | | macos-latest | ✅️ | ✅️ | ✅️ |
| windows-latest | (2) | ✅️ | ✅️ | | windows-latest | ✅️ | (2) | ✅️ |
2. WIP, See [Issue #87](https://github.com/peaceiris/actions-gh-pages/issues/87) 2. WIP, See [Issue #87](https://github.com/peaceiris/actions-gh-pages/issues/87)
@@ -65,13 +61,11 @@ Three tokens are supported.
- [Getting started](#getting-started) - [Getting started](#getting-started)
- [(1) Add SSH deploy key](#1-add-ssh-deploy-key) - [⭐️ Repository type - Project](#%EF%B8%8F-repository-type---project)
- [(2) Create your workflow](#2-create-your-workflow) - [⭐️ Repository type - User and Organization](#%EF%B8%8F-repository-type---user-and-organization)
- [⭐️ Repository type - Project](#%EF%B8%8F-repository-type---project)
- [⭐️ Repository type - User and Organization](#%EF%B8%8F-repository-type---user-and-organization)
- [Options](#options) - [Options](#options)
- [⭐️ `deploy_key`](#%EF%B8%8F-deploy_key)
- [⭐️ `personal_token`](#%EF%B8%8F-personal_token) - [⭐️ `personal_token`](#%EF%B8%8F-personal_token)
- [⭐️ `github_token`](#%EF%B8%8F-github_token)
- [⭐️ CNAME](#%EF%B8%8F-cname) - [⭐️ CNAME](#%EF%B8%8F-cname)
- [⭐️ Disable `.nojekyll`](#%EF%B8%8F-disable-nojekyll) - [⭐️ Disable `.nojekyll`](#%EF%B8%8F-disable-nojekyll)
- [⭐️ Allow empty commits](#%EF%B8%8F-allow-empty-commits) - [⭐️ Allow empty commits](#%EF%B8%8F-allow-empty-commits)
@@ -82,14 +76,14 @@ Three tokens are supported.
- [⭐️ Set custom commit message](#%EF%B8%8F-set-custom-commit-message) - [⭐️ Set custom commit message](#%EF%B8%8F-set-custom-commit-message)
- [⭐️ Create Git tag](#%EF%B8%8F-create-git-tag) - [⭐️ Create Git tag](#%EF%B8%8F-create-git-tag)
- [Tips and FAQ](#tips-and-faq) - [Tips and FAQ](#tips-and-faq)
- [⭐️ Create SSH Deploy Key](#%EF%B8%8F-create-ssh-deploy-key)
- [⭐️ Use the latest and specific release](#%EF%B8%8F-use-the-latest-and-specific-release) - [⭐️ Use the latest and specific release](#%EF%B8%8F-use-the-latest-and-specific-release)
- [⭐️ How to add `CNAME`](#%EF%B8%8F-how-to-add-cname)
- [⭐️ Deployment completed but you cannot read](#%EF%B8%8F-deployment-completed-but-you-cannot-read)
- [Examples](#examples) - [Examples](#examples)
- [⭐️ Static Site Generators with Node.js](#%EF%B8%8F-static-site-generators-with-nodejs) - [⭐️ Static Site Generators with Node.js](#%EF%B8%8F-static-site-generators-with-nodejs)
- [⭐️ Gatsby](#%EF%B8%8F-gatsby) - [⭐️ Gatsby](#%EF%B8%8F-gatsby)
- [⭐️ React and Next](#%EF%B8%8F-react-and-next) - [⭐️ React and Next](#%EF%B8%8F-react-and-next)
- [⭐️ Vue and Nuxt](#%EF%B8%8F-vue-and-nuxt) - [⭐️ Vue and Nuxt](#%EF%B8%8F-vue-and-nuxt)
- [⭐️ Docusaurus](#%EF%B8%8F-docusaurus)
- [⭐️ Static Site Generators with Python](#%EF%B8%8F-static-site-generators-with-python) - [⭐️ Static Site Generators with Python](#%EF%B8%8F-static-site-generators-with-python)
- [⭐️ mdBook (Rust)](#%EF%B8%8F-mdbook-rust) - [⭐️ mdBook (Rust)](#%EF%B8%8F-mdbook-rust)
- [⭐️ Flutter Web](#%EF%B8%8F-flutter-web) - [⭐️ Flutter Web](#%EF%B8%8F-flutter-web)
@@ -103,35 +97,9 @@ Three tokens are supported.
## Getting started ## Getting started
### (1) Add SSH deploy key ### ⭐️ Repository type - Project
Generate your deploy key with the following command. Add your workflow file `.github/workflows/gh-pages.yml` and push to the remote master branch.
```sh
ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""
# You will get 2 files:
# gh-pages.pub (public key)
# gh-pages (private key)
```
Next, Go to **Repository Settings**
- Go to **Deploy Keys** and add your public key with the **Allow write access**
- Go to **Secrets** and add your private key as `ACTIONS_DEPLOY_KEY`
| Add your public key | Success |
|---|---|
| ![](./images/deploy-keys-1.jpg) | ![](./images/deploy-keys-2.jpg) |
| Add your private key | Success |
|---|---|
| ![](./images/secrets-1.jpg) | ![](./images/secrets-2.jpg) |
### (2) Create your workflow
Add your workflow setting YAML file `.github/workflows/gh-pages.yml` and push to the default branch.
#### ⭐️ Repository type - Project
An example workflow for Hugo. An example workflow for Hugo.
@@ -139,9 +107,6 @@ An example workflow for Hugo.
[![peaceiris/actions-hugo - GitHub](https://gh-card.dev/repos/peaceiris/actions-hugo.svg?fullname)](https://github.com/peaceiris/actions-hugo) [![peaceiris/actions-hugo - GitHub](https://gh-card.dev/repos/peaceiris/actions-hugo.svg?fullname)](https://github.com/peaceiris/actions-hugo)
![peaceiris/actions-hugo latest version](https://img.shields.io/github/release/peaceiris/actions-hugo.svg?label=peaceiris%2Factions-hugo)
![peaceiris/actions-gh-pages latest version](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg?label=peaceiris%2Factions-gh-pages)
```yaml ```yaml
name: github pages name: github pages
@@ -169,7 +134,7 @@ jobs:
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
``` ```
@@ -183,7 +148,7 @@ The above example is for [Project Pages sites]. (`<username>/<project_name>` rep
|---|---| |---|---|
| ![](./images/log3.jpg) | ![](./images/log4.jpg) | | ![](./images/log3.jpg) | ![](./images/log4.jpg) |
#### ⭐️ Repository type - User and Organization ### ⭐️ Repository type - User and Organization
For [User and Organization Pages sites] (`<username>/<username>.github.io` repository), For [User and Organization Pages sites] (`<username>/<username>.github.io` repository),
we have to set `master` branch to `publish_branch`. we have to set `master` branch to `publish_branch`.
@@ -207,7 +172,7 @@ jobs:
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
publish_branch: master # deploying branch publish_branch: master # deploying branch
``` ```
@@ -226,26 +191,29 @@ jobs:
## Options ## Options
### ⭐️ `deploy_key`
Read [⭐️ Create SSH Deploy Key](#%EF%B8%8F-create-ssh-deploy-key), create your SSH deploy key, and set the `deploy_key` option like the following.
```yaml
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./public
```
### ⭐️ `personal_token` ### ⭐️ `personal_token`
[Generate a personal access token (`repo`)](https://github.com/settings/tokens) and add it to Secrets as `PERSONAL_TOKEN`, it works as well as `ACTIONS_DEPLOY_KEY`. [Generate a personal access token (`repo`)](https://github.com/settings/tokens) and add it to Secrets as `PERSONAL_TOKEN`, it works as well as `ACTIONS_DEPLOY_KEY`.
```diff
- deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
+ personal_token: ${{ secrets.PERSONAL_TOKEN }}
```
### ⭐️ `github_token` ```yaml
- name: Deploy
> ⚠️ **NOTES**: `github_token` works only on a **private** repository. uses: peaceiris/actions-gh-pages@v3
> with:
> This action supports `GITHUB_TOKEN` but it has some problems to deploy to GitHub Pages. GitHub team is investigating that. See [Issue #9] personal_token: ${{ secrets.PERSONAL_TOKEN }}
publish_dir: ./public
[Issue #9]: https://github.com/peaceiris/actions-gh-pages/issues/9
```diff
- deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
+ github_token: ${{ secrets.GITHUB_TOKEN }}
``` ```
### ⭐️ CNAME ### ⭐️ CNAME
@@ -258,7 +226,7 @@ For more details about `CNAME`, read the official documentation: [Managing a cus
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
cname: github.com cname: github.com
``` ```
@@ -273,11 +241,13 @@ To disable this behavior, we can set the `disable_nojekyll` option to `true`.
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
disable_nojekyll: true disable_nojekyll: true
``` ```
For more details about `.nojekyll`: [Bypassing Jekyll on GitHub Pages - The GitHub Blog](https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/)
### ⭐️ Allow empty commits ### ⭐️ Allow empty commits
By default, a commit will not be generated when no file changes. If you want to allow an empty commit, set the optional parameter `allow_empty_commit` to `true`. By default, a commit will not be generated when no file changes. If you want to allow an empty commit, set the optional parameter `allow_empty_commit` to `true`.
@@ -288,7 +258,7 @@ For example:
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
allow_empty_commit: true allow_empty_commit: true
``` ```
@@ -303,7 +273,7 @@ For example:
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
keep_files: true keep_files: true
``` ```
@@ -321,7 +291,7 @@ For example:
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
external_repository: username/external-repository external_repository: username/external-repository
publish_branch: gh-pages publish_branch: master
publish_dir: ./public publish_dir: ./public
``` ```
@@ -339,7 +309,7 @@ This allows you to make your publish branch with only the latest commit.
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
force_orphan: true force_orphan: true
``` ```
@@ -353,7 +323,7 @@ A commit is always created with the same user.
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
user_name: iris user_name: iris
user_email: iris@peaceiris.com user_email: iris@peaceiris.com
@@ -368,7 +338,7 @@ When we create a commit with a message `docs: Update some post`, a deployment co
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
commit_message: ${{ github.event.head_commit.message }} commit_message: ${{ github.event.head_commit.message }}
``` ```
@@ -406,7 +376,7 @@ jobs:
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
tag_name: ${{ steps.prepare_tag.outputs.deploy_tag_name }} tag_name: ${{ steps.prepare_tag.outputs.deploy_tag_name }}
tag_message: 'Deployment ${{ steps.prepare_tag.outputs.tag_name }}' tag_message: 'Deployment ${{ steps.prepare_tag.outputs.tag_name }}'
@@ -434,6 +404,30 @@ v1.2.3 # Tag on the master branch
## Tips and FAQ ## Tips and FAQ
### ⭐️ Create SSH Deploy Key
Generate your deploy key with the following command.
```sh
ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""
# You will get 2 files:
# gh-pages.pub (public key)
# gh-pages (private key)
```
Next, Go to **Repository Settings**
- Go to **Deploy Keys** and add your public key with the **Allow write access**
- Go to **Secrets** and add your private key as `ACTIONS_DEPLOY_KEY`
| Add your public key | Success |
|---|---|
| ![](./images/deploy-keys-1.jpg) | ![](./images/deploy-keys-2.jpg) |
| Add your private key | Success |
|---|---|
| ![](./images/secrets-1.jpg) | ![](./images/secrets-2.jpg) |
### ⭐️ Use the latest and specific release ### ⭐️ Use the latest and specific release
We recommend you to use the latest and specific release of this action for stable CI/CD. We recommend you to use the latest and specific release of this action for stable CI/CD.
@@ -441,47 +435,6 @@ It is useful to watch this repository (release only) to check the [latest releas
[latest release]: https://github.com/peaceiris/actions-gh-pages/releases [latest release]: https://github.com/peaceiris/actions-gh-pages/releases
### ⭐️ How to add `CNAME`
Most of the Static Site Generators support `CNAME` as a static file.
- [Use a Custom Domain | Hugo](https://gohugo.io/hosting-and-deployment/hosting-on-github/#use-a-custom-domain)
- [Using the Static folder | GatsbyJS](https://www.gatsbyjs.org/docs/static-folder/)
The same may be said of other files (`.nojekyll`, `BingSiteAuth.xml`, `robots.txt`, etc.). It is better to manage those files by Static Site Generators.
Does not your static site generator deal with the static files? No problem, you can add the file like the following.
```yaml
- name: Build
run: |
buildcommand
cp ./path/to/CNAME ./public/CNAME
- name: Deploy
```
### ⭐️ Deployment completed but you cannot read
Does your `publish_dir` contain files or directories that name starts with an underscore? (`_modules`, `_sources` and `_next`, etc.)
GitHub Pages does not read those by default.
Please add `.nojekyll` file to `publish_dir`.
- [Bypassing Jekyll on GitHub Pages - The GitHub Blog](https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/)
> It is now possible to completely bypass Jekyll processing on GitHub Pages by creating a file named `.nojekyll` in the root of your pages repo and pushing it to GitHub. This should only be necessary if your site uses files or directories that start with underscores since Jekyll considers these to be special resources and does not copy them to the final site.
Does not your static site generator deal with the static files? No problem, you can add the file like the following.
```yaml
- name: Build
run: |
buildcommand
touch ./public/.nojekyll
- name: Deploy
```
<div align="right"> <div align="right">
<a href="#table-of-contents">Back to TOC ☝️</a> <a href="#table-of-contents">Back to TOC ☝️</a>
</div> </div>
@@ -502,8 +455,6 @@ Does not your static site generator deal with the static files? No problem, you
Premise: Dependencies are managed by `package.json` and `package-lock.json` Premise: Dependencies are managed by `package.json` and `package-lock.json`
![peaceiris/actions-gh-pages latest version](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg?label=peaceiris%2Factions-gh-pages)
```yaml ```yaml
name: github pages name: github pages
@@ -532,13 +483,12 @@ jobs:
${{ runner.os }}-node- ${{ runner.os }}-node-
- run: npm ci - run: npm ci
- run: npm run build - run: npm run build
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
``` ```
@@ -549,8 +499,6 @@ An example for [Gatsby] (Gatsby.js) project with [gatsby-starter-blog]
[Gatsby]: https://github.com/gatsbyjs/gatsby [Gatsby]: https://github.com/gatsbyjs/gatsby
[gatsby-starter-blog]: https://github.com/gatsbyjs/gatsby-starter-blog [gatsby-starter-blog]: https://github.com/gatsbyjs/gatsby-starter-blog
![peaceiris/actions-gh-pages latest version](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg?label=peaceiris%2Factions-gh-pages)
```yaml ```yaml
name: github pages name: github pages
@@ -579,17 +527,14 @@ jobs:
${{ runner.os }}-node- ${{ runner.os }}-node-
- run: npm ci - run: npm ci
- run: npm run format - run: npm run format
- run: npm run test - run: npm run test
- run: npm run build - run: npm run build
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
``` ```
@@ -602,8 +547,6 @@ An example for [Next.js] (React.js) project with [create-next-app]
[Next.js]: https://github.com/zeit/next.js [Next.js]: https://github.com/zeit/next.js
[create-next-app]: https://nextjs.org/docs [create-next-app]: https://nextjs.org/docs
![peaceiris/actions-gh-pages latest version](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg?label=peaceiris%2Factions-gh-pages)
```yaml ```yaml
name: github pages name: github pages
@@ -636,17 +579,13 @@ jobs:
${{ runner.os }}-yarn- ${{ runner.os }}-yarn-
- run: yarn install - run: yarn install
- run: yarn build - run: yarn build
- run: yarn export - run: yarn export
- run: touch ./out/.nojekyll
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./out publish_dir: ./out
``` ```
@@ -659,8 +598,6 @@ An example for [Nuxt.js] (Vue.js) project with [create-nuxt-app]
[Nuxt.js]: https://github.com/nuxt/nuxt.js [Nuxt.js]: https://github.com/nuxt/nuxt.js
[create-nuxt-app]: https://github.com/nuxt/create-nuxt-app [create-nuxt-app]: https://github.com/nuxt/create-nuxt-app
![peaceiris/actions-gh-pages latest version](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg?label=peaceiris%2Factions-gh-pages)
```yaml ```yaml
name: github pages name: github pages
@@ -689,18 +626,69 @@ jobs:
${{ runner.os }}-node- ${{ runner.os }}-node-
- run: npm ci - run: npm ci
- run: npm test - run: npm test
- run: npm run generate - run: npm run generate
- name: deploy - name: deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist publish_dir: ./dist
``` ```
### ⭐️ Docusaurus
An example for pages created using [Docusaurus](https://docusaurus.io/).
Examples where this is being used:
- [Mittens](https://github.com/ExpediaGroup/mittens)
- [graphql-kotlin](https://github.com/ExpediaGroup/graphql-kotlin)
```yaml
name: github pages
on:
push:
branches:
- master
paths:
- 'docs/**'
- 'website/**'
jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 12
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('website/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Build
run: |
cd website
npm ci
npm run build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# use the projectName from your siteConfig.js file: https://docusaurus.io/docs/en/site-config#projectname-string
publish_dir: ./website/build/<projectName>
```
### ⭐️ Static Site Generators with Python ### ⭐️ Static Site Generators with Python
[pelican], [MkDocs], [sphinx], etc. [pelican], [MkDocs], [sphinx], etc.
@@ -711,8 +699,6 @@ jobs:
Premise: Dependencies are managed by `requirements.txt` Premise: Dependencies are managed by `requirements.txt`
![peaceiris/actions-gh-pages latest version](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg?label=peaceiris%2Factions-gh-pages)
```yaml ```yaml
name: github pages name: github pages
@@ -751,7 +737,7 @@ jobs:
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site publish_dir: ./site
``` ```
@@ -788,7 +774,7 @@ jobs:
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./book publish_dir: ./book
``` ```
@@ -834,7 +820,7 @@ jobs:
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build/web publish_dir: ./build/web
``` ```
@@ -875,7 +861,7 @@ jobs:
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v3 uses: peaceiris/actions-gh-pages@v3
with: with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public publish_dir: ./public
``` ```

View File

@@ -1,6 +1,7 @@
// import * as main from '../src/main'; // import * as main from '../src/main';
import {Inputs} from '../src/interfaces'; import {Inputs} from '../src/interfaces';
import {getInputs} from '../src/get-inputs'; import {showInputs, getInputs} from '../src/get-inputs';
import os from 'os';
beforeEach(() => { beforeEach(() => {
jest.resetModules(); jest.resetModules();
@@ -25,6 +26,96 @@ afterEach(() => {
delete process.env['INPUT_CNAME']; delete process.env['INPUT_CNAME'];
}); });
// Assert that process.stdout.write calls called only with the given arguments.
// cf. https://github.com/actions/toolkit/blob/8b0300129f08728419263b016de8630f1d426d5f/packages/core/__tests__/core.test.ts
function assertWriteCalls(calls: string[]): void {
expect(process.stdout.write).toHaveBeenCalledTimes(calls.length);
for (let i = 0; i < calls.length; i++) {
expect(process.stdout.write).toHaveBeenNthCalledWith(i + 1, calls[i]);
}
}
function setTestInputs(): void {
process.env['INPUT_PUBLISH_BRANCH'] = 'master';
process.env['INPUT_PUBLISH_DIR'] = 'out';
process.env['INPUT_EXTERNAL_REPOSITORY'] = 'user/repo';
process.env['INPUT_ALLOW_EMPTY_COMMIT'] = 'true';
process.env['INPUT_KEEP_FILES'] = 'true';
process.env['INPUT_FORCE_ORPHAN'] = 'true';
process.env['INPUT_USER_NAME'] = 'username';
process.env['INPUT_USER_EMAIL'] = 'github@github.com';
process.env['INPUT_COMMIT_MESSAGE'] = 'feat: Add new feature';
process.env['INPUT_TAG_NAME'] = 'deploy-v1.2.3';
process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3';
process.env['INPUT_DISABLE_NOJEKYLL'] = 'true';
process.env['INPUT_CNAME'] = 'github.com';
}
function getInputsLog(authMethod: string, inps: Inputs): string {
return `\
[INFO] ${authMethod}: true
[INFO] PublishBranch: ${inps.PublishBranch}
[INFO] PublishDir: ${inps.PublishDir}
[INFO] ExternalRepository: ${inps.ExternalRepository}
[INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}
[INFO] KeepFiles: ${inps.KeepFiles}
[INFO] ForceOrphan: ${inps.ForceOrphan}
[INFO] UserName: ${inps.UserName}
[INFO] UserEmail: ${inps.UserEmail}
[INFO] CommitMessage: ${inps.CommitMessage}
[INFO] TagName: ${inps.TagName}
[INFO] TagMessage: ${inps.TagMessage}
[INFO] DisableNoJekyll: ${inps.DisableNoJekyll}
[INFO] CNAME: ${inps.CNAME}
`;
}
describe('showInputs()', () => {
beforeEach(() => {
process.stdout.write = jest.fn();
});
// eslint-disable-next-line jest/expect-expect
test('print all inputs DeployKey', () => {
process.env['INPUT_DEPLOY_KEY'] = 'test_deploy_key';
setTestInputs();
const inps: Inputs = getInputs();
showInputs(inps);
const authMethod = 'DeployKey';
const test = getInputsLog(authMethod, inps);
assertWriteCalls([`${test}${os.EOL}`]);
});
// eslint-disable-next-line jest/expect-expect
test('print all inputs GithubToken', () => {
process.env['INPUT_GITHUB_TOKEN'] = 'test_github_token';
setTestInputs();
const inps: Inputs = getInputs();
showInputs(inps);
const authMethod = 'GithubToken';
const test = getInputsLog(authMethod, inps);
assertWriteCalls([`${test}${os.EOL}`]);
});
// eslint-disable-next-line jest/expect-expect
test('print all inputs PersonalToken', () => {
process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
setTestInputs();
const inps: Inputs = getInputs();
showInputs(inps);
const authMethod = 'PersonalToken';
const test = getInputsLog(authMethod, inps);
assertWriteCalls([`${test}${os.EOL}`]);
});
});
describe('getInputs()', () => { describe('getInputs()', () => {
test('get default inputs', () => { test('get default inputs', () => {
process.env['INPUT_DEPLOY_KEY'] = 'test_deploy_key'; process.env['INPUT_DEPLOY_KEY'] = 'test_deploy_key';

View File

@@ -1,32 +0,0 @@
// import {run} from '../src/main';
beforeEach(() => {
jest.resetModules();
});
afterEach(() => {
delete process.env['INPUT_DEPLOY_KEY'];
delete process.env['INPUT_GITHUB_TOKEN'];
delete process.env['INPUT_PERSONAL_TOKEN'];
delete process.env['INPUT_PUBLISH_BRANCH'];
delete process.env['INPUT_PUBLISH_DIR'];
delete process.env['INPUT_EXTERNAL_REPOSITORY'];
delete process.env['INPUT_ALLOW_EMPTY_COMMIT'];
delete process.env['INPUT_KEEP_FILES'];
delete process.env['INPUT_FORCE_ORPHAN'];
delete process.env['INPUT_USER_NAME'];
delete process.env['INPUT_USER_EMAIL'];
delete process.env['INPUT_COMMIT_MESSAGE'];
delete process.env['INPUT_TAG_NAME'];
delete process.env['INPUT_TAG_MESSAGE'];
delete process.env['INPUT_TAG_OVERWRITE'];
});
describe('Integration testing run()', () => {
test('succeed in pushing using deploy key', async () => {
// process.env['INPUT_DEPLOY_KEY'] = 'test_deploy_key';
// process.env['GITHUB_REPOSITORY'] = 'owner/repo';
// const exitcode = await run();
expect(0).toBe(0);
});
});

View File

@@ -0,0 +1,105 @@
import {
getPublishRepo,
setPersonalToken,
setGithubToken
} from '../src/set-tokens';
beforeEach(() => {
jest.resetModules();
});
// afterEach(() => {
// });
describe('getPublishRepo()', () => {
test('return repository name', () => {
const test = getPublishRepo('', 'owner', 'repo');
expect(test).toMatch('owner/repo');
});
test('return external repository name', () => {
const test = getPublishRepo('extOwner/extRepo', 'owner', 'repo');
expect(test).toMatch('extOwner/extRepo');
});
});
describe('setGithubToken()', () => {
test('return remote url with GITHUB_TOKEN gh-pages', () => {
const expected =
'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git';
const test = setGithubToken(
'GITHUB_TOKEN',
'owner/repo',
'gh-pages',
'',
'refs/heads/master',
'push'
);
expect(test).toMatch(expected);
});
test('return remote url with GITHUB_TOKEN master', () => {
const expected =
'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git';
const test = setGithubToken(
'GITHUB_TOKEN',
'owner/repo',
'master',
'',
'refs/heads/source',
'push'
);
expect(test).toMatch(expected);
});
test('throw error master to master', () => {
expect(() => {
setGithubToken(
'GITHUB_TOKEN',
'owner/repo',
'master',
'',
'refs/heads/master',
'push'
);
}).toThrowError('You deploy from master to master');
});
test('throw error external repository with GITHUB_TOKEN', () => {
expect(() => {
setGithubToken(
'GITHUB_TOKEN',
'owner/repo',
'gh-pages',
'extOwner/extRepo',
'refs/heads/master',
'push'
);
}).toThrowError(
'GITHUB_TOKEN does not support to push to an external repository'
);
});
test('return remote url with GITHUB_TOKEN pull_request', () => {
const expected =
'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git';
const test = setGithubToken(
'GITHUB_TOKEN',
'owner/repo',
'gh-pages',
'',
'refs/pull/29/merge',
'pull_request'
);
expect(test).toMatch(expected);
});
});
describe('setPersonalToken()', () => {
test('return remote url with personal access token', () => {
const expected = 'https://x-access-token:pat@github.com/owner/repo.git';
const test = setPersonalToken('pat', 'owner/repo');
expect(test).toMatch(expected);
});
});

View File

@@ -77,8 +77,8 @@ describe('addNoJekyll()', () => {
const filepath = path.join(workDir, '.nojekyll'); const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, false, 'gh-pages'); await addNoJekyll(workDir, false, 'gh-pages');
const test1 = fs.existsSync(filepath); const test = fs.existsSync(filepath);
expect(test1).toBe(true); expect(test).toBe(true);
fs.unlinkSync(filepath); fs.unlinkSync(filepath);
}); });
@@ -91,8 +91,23 @@ describe('addNoJekyll()', () => {
const filepath = path.join(workDir, '.nojekyll'); const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, false, 'master'); await addNoJekyll(workDir, false, 'master');
const test2 = fs.existsSync(filepath); const test = fs.existsSync(filepath);
expect(test2).toBe(true); expect(test).toBe(true);
fs.unlinkSync(filepath);
});
test('.nojekyll already exists', async () => {
let workDir = '';
(async (): Promise<void> => {
workDir = await getWorkDir();
})();
const filepath = path.join(workDir, '.nojekyll');
fs.closeSync(fs.openSync(filepath, 'w'));
await addNoJekyll(workDir, false, 'master');
const test = fs.existsSync(filepath);
expect(test).toBe(true);
fs.unlinkSync(filepath); fs.unlinkSync(filepath);
}); });
@@ -105,8 +120,8 @@ describe('addNoJekyll()', () => {
const filepath = path.join(workDir, '.nojekyll'); const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, true, 'gh-pages'); await addNoJekyll(workDir, true, 'gh-pages');
const test3 = fs.existsSync(filepath); const test = fs.existsSync(filepath);
expect(test3).toBe(false); expect(test).toBe(false);
}); });
test('not add .nojekyll disable_nojekyll master', async () => { test('not add .nojekyll disable_nojekyll master', async () => {
@@ -117,8 +132,8 @@ describe('addNoJekyll()', () => {
const filepath = path.join(workDir, '.nojekyll'); const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, true, 'master'); await addNoJekyll(workDir, true, 'master');
const test4 = fs.existsSync(filepath); const test = fs.existsSync(filepath);
expect(test4).toBe(false); expect(test).toBe(false);
}); });
test('not add .nojekyll other-branch', async () => { test('not add .nojekyll other-branch', async () => {
@@ -129,8 +144,8 @@ describe('addNoJekyll()', () => {
const filepath = path.join(workDir, '.nojekyll'); const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, false, 'other-branch'); await addNoJekyll(workDir, false, 'other-branch');
const test5 = fs.existsSync(filepath); const test = fs.existsSync(filepath);
expect(test5).toBe(false); expect(test).toBe(false);
}); });
test('not add .nojekyll disable_nojekyll other-branch', async () => { test('not add .nojekyll disable_nojekyll other-branch', async () => {
@@ -141,8 +156,8 @@ describe('addNoJekyll()', () => {
const filepath = path.join(workDir, '.nojekyll'); const filepath = path.join(workDir, '.nojekyll');
await addNoJekyll(workDir, true, 'other-branch'); await addNoJekyll(workDir, true, 'other-branch');
const test6 = fs.existsSync(filepath); const test = fs.existsSync(filepath);
expect(test6).toBe(false); expect(test).toBe(false);
}); });
}); });
@@ -155,8 +170,8 @@ describe('addCNAME()', () => {
const filepath = path.join(workDir, 'CNAME'); const filepath = path.join(workDir, 'CNAME');
await addCNAME(workDir, 'github.com'); await addCNAME(workDir, 'github.com');
const test1 = fs.readFileSync(filepath, 'utf8'); const test = fs.readFileSync(filepath, 'utf8');
expect(test1).toMatch('github.com'); expect(test).toMatch('github.com');
fs.unlinkSync(filepath); fs.unlinkSync(filepath);
}); });
@@ -169,8 +184,8 @@ describe('addCNAME()', () => {
const filepath = path.join(workDir, 'CNAME'); const filepath = path.join(workDir, 'CNAME');
await addCNAME(workDir, ''); await addCNAME(workDir, '');
const test2 = fs.existsSync(filepath); const test = fs.existsSync(filepath);
expect(test2).toBe(false); expect(test).toBe(false);
}); });
test('CNAME already exists', async () => { test('CNAME already exists', async () => {
@@ -182,8 +197,8 @@ describe('addCNAME()', () => {
await addCNAME(workDir, 'github.io'); await addCNAME(workDir, 'github.io');
await addCNAME(workDir, 'github.com'); await addCNAME(workDir, 'github.com');
const test3 = fs.readFileSync(filepath, 'utf8'); const test = fs.readFileSync(filepath, 'utf8');
expect(test3).toMatch('github.io'); expect(test).toMatch('github.io');
fs.unlinkSync(filepath); fs.unlinkSync(filepath);
}); });

View File

@@ -2257,6 +2257,7 @@ function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const inps = get_inputs_1.getInputs(); const inps = get_inputs_1.getInputs();
get_inputs_1.showInputs(inps);
yield git.setConfig(inps.UserName, inps.UserEmail); yield git.setConfig(inps.UserName, inps.UserEmail);
const remoteURL = yield set_tokens_1.setTokens(inps); const remoteURL = yield set_tokens_1.setTokens(inps);
core.debug(`[INFO] remoteURL: ${remoteURL}`); core.debug(`[INFO] remoteURL: ${remoteURL}`);
@@ -2270,7 +2271,7 @@ function run() {
yield exec.exec('git', ['remote', 'rm', 'origin']); yield exec.exec('git', ['remote', 'rm', 'origin']);
} }
catch (e) { catch (e) {
core.info(`[INFO] ${e}`); core.info(`[INFO] ${e.message}`);
} }
yield exec.exec('git', ['remote', 'add', 'origin', remoteURL]); yield exec.exec('git', ['remote', 'add', 'origin', remoteURL]);
yield exec.exec('git', ['add', '--all']); yield exec.exec('git', ['add', '--all']);
@@ -2281,7 +2282,7 @@ function run() {
return; return;
} }
catch (e) { catch (e) {
throw new Error(e); throw new Error(e.message);
} }
}); });
} }
@@ -5098,7 +5099,7 @@ const main = __importStar(__webpack_require__(131));
yield main.run(); yield main.run();
} }
catch (e) { catch (e) {
core.setFailed(`Action failed with "${e}"`); core.setFailed(`Action failed with "${e.message}"`);
} }
}))(); }))();
@@ -6044,29 +6045,34 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
function showInputs(inps) { function showInputs(inps) {
let authMethod = '';
if (inps.DeployKey) { if (inps.DeployKey) {
core.info(`[INFO] DeployKey: true`); authMethod = 'DeployKey';
} }
else if (inps.GithubToken) { else if (inps.GithubToken) {
core.info(`[INFO] GithubToken: true`); authMethod = 'GithubToken';
} }
else if (inps.PersonalToken) { else if (inps.PersonalToken) {
core.info(`[INFO] PersonalToken: true`); authMethod = 'PersonalToken';
} }
core.info(`[INFO] PublishBranch: ${inps.PublishBranch}`); core.info(`\
core.info(`[INFO] PublishDir: ${inps.PublishDir}`); [INFO] ${authMethod}: true
core.info(`[INFO] ExternalRepository: ${inps.ExternalRepository}`); [INFO] PublishBranch: ${inps.PublishBranch}
core.info(`[INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}`); [INFO] PublishDir: ${inps.PublishDir}
core.info(`[INFO] KeepFiles: ${inps.KeepFiles}`); [INFO] ExternalRepository: ${inps.ExternalRepository}
core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`); [INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}
core.info(`[INFO] UserName: ${inps.UserName}`); [INFO] KeepFiles: ${inps.KeepFiles}
core.info(`[INFO] UserEmail: ${inps.UserEmail}`); [INFO] ForceOrphan: ${inps.ForceOrphan}
core.info(`[INFO] CommitMessage: ${inps.CommitMessage}`); [INFO] UserName: ${inps.UserName}
core.info(`[INFO] TagName: ${inps.TagName}`); [INFO] UserEmail: ${inps.UserEmail}
core.info(`[INFO] TagMessage: ${inps.TagMessage}`); [INFO] CommitMessage: ${inps.CommitMessage}
core.info(`[INFO] DisableNoJekyll: ${inps.DisableNoJekyll}`); [INFO] TagName: ${inps.TagName}
core.info(`[INFO] CNAME: ${inps.CNAME}`); [INFO] TagMessage: ${inps.TagMessage}
[INFO] DisableNoJekyll: ${inps.DisableNoJekyll}
[INFO] CNAME: ${inps.CNAME}
`);
} }
exports.showInputs = showInputs;
function getInputs() { function getInputs() {
const inps = { const inps = {
DeployKey: core.getInput('deploy_key'), DeployKey: core.getInput('deploy_key'),
@@ -6086,7 +6092,6 @@ function getInputs() {
DisableNoJekyll: (core.getInput('disable_nojekyll') || 'false').toUpperCase() === 'TRUE', DisableNoJekyll: (core.getInput('disable_nojekyll') || 'false').toUpperCase() === 'TRUE',
CNAME: core.getInput('cname') CNAME: core.getInput('cname')
}; };
showInputs(inps);
return inps; return inps;
} }
exports.getInputs = getInputs; exports.getInputs = getInputs;
@@ -8157,6 +8162,13 @@ exports.setFailed = setFailed;
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Logging Commands // Logging Commands
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/**
* Gets whether Actions Step Debug is on or not
*/
function isDebug() {
return process.env['RUNNER_DEBUG'] === '1';
}
exports.isDebug = isDebug;
/** /**
* Writes debug message to user log * Writes debug message to user log
* @param message debug message * @param message debug message
@@ -8485,7 +8497,7 @@ function setRepo(inps, remoteURL, workDir) {
} }
catch (e) { catch (e) {
core.info(`[INFO] first deployment, create new branch ${inps.PublishBranch}`); core.info(`[INFO] first deployment, create new branch ${inps.PublishBranch}`);
core.info(e); core.info(e.message);
yield utils_1.createWorkDir(workDir); yield utils_1.createWorkDir(workDir);
process.chdir(workDir); process.chdir(workDir);
yield createBranchForce(inps.PublishBranch); yield createBranchForce(inps.PublishBranch);
@@ -8545,7 +8557,7 @@ function commit(allowEmptyCommit, externalRepository, message) {
} }
catch (e) { catch (e) {
core.info('[INFO] skip commit'); core.info('[INFO] skip commit');
core.debug(`[INFO] skip commit ${e}`); core.debug(`[INFO] skip commit ${e.message}`);
} }
}); });
} }
@@ -9581,13 +9593,6 @@ const fs_1 = __importDefault(__webpack_require__(747));
const cpSpawnSync = __webpack_require__(129).spawnSync; const cpSpawnSync = __webpack_require__(129).spawnSync;
const cpexec = __webpack_require__(129).execFileSync; const cpexec = __webpack_require__(129).execFileSync;
const utils_1 = __webpack_require__(163); const utils_1 = __webpack_require__(163);
function setPublishRepo(insp) {
if (insp.ExternalRepository) {
return insp.ExternalRepository;
}
return `${github.context.repo.owner}/${github.context.repo.repo}`;
}
exports.setPublishRepo = setPublishRepo;
function setSSHKey(inps, publishRepo) { function setSSHKey(inps, publishRepo) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info('[INFO] setup SSH deploy key'); core.info('[INFO] setup SSH deploy key');
@@ -9630,53 +9635,57 @@ Host github
}); });
} }
exports.setSSHKey = setSSHKey; exports.setSSHKey = setSSHKey;
function setGithubToken(inps, publishRepo) { function setGithubToken(githubToken, publishRepo, publishBranch, externalRepository, ref, eventName) {
return __awaiter(this, void 0, void 0, function* () { core.info('[INFO] setup GITHUB_TOKEN');
core.info('[INFO] setup GITHUB_TOKEN'); core.debug(`ref: ${ref}`);
const context = github.context; core.debug(`eventName: ${eventName}`);
core.debug(`ref: ${context.ref}`); let isProhibitedBranch = false;
core.debug(`eventName: ${context.eventName}`); if (eventName === 'push') {
let isProhibitedBranch = false; isProhibitedBranch = ref.includes(`refs/heads/${publishBranch}`);
const ref = context.ref; if (isProhibitedBranch) {
if (context.eventName === 'push') { throw new Error(`You deploy from ${publishBranch} to ${publishBranch}`);
isProhibitedBranch = ref.includes(`refs/heads/${inps.PublishBranch}`);
if (isProhibitedBranch) {
throw new Error(`You deploy from ${inps.PublishBranch} to ${inps.PublishBranch}`);
}
} }
if (inps.ExternalRepository) { }
throw new Error('GITHUB_TOKEN does not support to push to an external repository'); if (externalRepository) {
} throw new Error('GITHUB_TOKEN does not support to push to an external repository');
return `https://x-access-token:${inps.GithubToken}@github.com/${publishRepo}.git`; }
}); return `https://x-access-token:${githubToken}@github.com/${publishRepo}.git`;
} }
exports.setGithubToken = setGithubToken; exports.setGithubToken = setGithubToken;
function setPersonalToken(inps, publishRepo) { function setPersonalToken(personalToken, publishRepo) {
return __awaiter(this, void 0, void 0, function* () { core.info('[INFO] setup personal access token');
core.info('[INFO] setup personal access token'); return `https://x-access-token:${personalToken}@github.com/${publishRepo}.git`;
return `https://x-access-token:${inps.PersonalToken}@github.com/${publishRepo}.git`;
});
} }
exports.setPersonalToken = setPersonalToken; exports.setPersonalToken = setPersonalToken;
function getPublishRepo(externalRepository, owner, repo) {
if (externalRepository) {
return externalRepository;
}
return `${owner}/${repo}`;
}
exports.getPublishRepo = getPublishRepo;
function setTokens(inps) { function setTokens(inps) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const publishRepo = setPublishRepo(inps); const publishRepo = getPublishRepo(inps.ExternalRepository, github.context.repo.owner, github.context.repo.repo);
if (inps.DeployKey) { if (inps.DeployKey) {
return setSSHKey(inps, publishRepo); return setSSHKey(inps, publishRepo);
} }
else if (inps.GithubToken) { else if (inps.GithubToken) {
return setGithubToken(inps, publishRepo); const context = github.context;
const ref = context.ref;
const eventName = context.eventName;
return setGithubToken(inps.GithubToken, publishRepo, inps.PublishBranch, inps.ExternalRepository, ref, eventName);
} }
else if (inps.PersonalToken) { else if (inps.PersonalToken) {
return setPersonalToken(inps, publishRepo); return setPersonalToken(inps.PersonalToken, publishRepo);
} }
else { else {
throw new Error('not found deploy key or tokens'); throw new Error('not found deploy key or tokens');
} }
} }
catch (e) { catch (e) {
throw new Error(e); throw new Error(e.message);
} }
}); });
} }

92
package-lock.json generated
View File

@@ -1,13 +1,13 @@
{ {
"name": "actions-github-pages", "name": "actions-github-pages",
"version": "3.3.0", "version": "3.4.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@actions/core": { "@actions/core": {
"version": "1.2.2", "version": "1.2.3",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.2.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.3.tgz",
"integrity": "sha512-IbCx7oefq+Gi6FWbSs2Fnw8VkEI6Y4gvjrYprY3RV//ksq/KPMlClOerJ4jRosyal6zkUIc8R9fS/cpRMlGClg==" "integrity": "sha512-Wp4xnyokakM45Uuj4WLUxdsa8fJjKVl1fDTsPbTEcTcuu0Nb26IPQbOtjmnfaCPGcaoPOOqId8H9NapZ8gii4w=="
}, },
"@actions/exec": { "@actions/exec": {
"version": "1.0.3", "version": "1.0.3",
@@ -756,9 +756,9 @@
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
"version": "12.12.28", "version": "12.12.29",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.28.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.29.tgz",
"integrity": "sha512-g73GJYJDXgf0jqg+P9S8h2acWbDXNkoCX8DLtJVu7Fkn788pzQ/oJsrdJz/2JejRf/SjfZaAhsw+3nd1D5EWGg==" "integrity": "sha512-yo8Qz0ygADGFptISDj3pOC9wXfln/5pQaN/ysDIzOaAWXt73cNHmtEC8zSO2Y+kse/txmwIAJzkYZ5fooaS5DQ=="
}, },
"@types/parse-json": { "@types/parse-json": {
"version": "4.0.0", "version": "4.0.0",
@@ -788,12 +788,12 @@
"dev": true "dev": true
}, },
"@typescript-eslint/eslint-plugin": { "@typescript-eslint/eslint-plugin": {
"version": "2.20.0", "version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.20.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.22.0.tgz",
"integrity": "sha512-cimIdVDV3MakiGJqMXw51Xci6oEDEoPkvh8ggJe2IIzcc0fYqAxOXN6Vbeanahz6dLZq64W+40iUEc9g32FLDQ==", "integrity": "sha512-BvxRLaTDVQ3N+Qq8BivLiE9akQLAOUfxNHIEhedOcg8B2+jY8Rc4/D+iVprvuMX1AdezFYautuGDwr9QxqSxBQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/experimental-utils": "2.20.0", "@typescript-eslint/experimental-utils": "2.22.0",
"eslint-utils": "^1.4.3", "eslint-utils": "^1.4.3",
"functional-red-black-tree": "^1.0.1", "functional-red-black-tree": "^1.0.1",
"regexpp": "^3.0.0", "regexpp": "^3.0.0",
@@ -801,20 +801,20 @@
}, },
"dependencies": { "dependencies": {
"@typescript-eslint/experimental-utils": { "@typescript-eslint/experimental-utils": {
"version": "2.20.0", "version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.20.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.22.0.tgz",
"integrity": "sha512-fEBy9xYrwG9hfBLFEwGW2lKwDRTmYzH3DwTmYbT+SMycmxAoPl0eGretnBFj/s+NfYBG63w/5c3lsvqqz5mYag==", "integrity": "sha512-sJt1GYBe6yC0dWOQzXlp+tiuGglNhJC9eXZeC8GBVH98Zv9jtatccuhz0OF5kC/DwChqsNfghHx7OlIDQjNYAQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/json-schema": "^7.0.3", "@types/json-schema": "^7.0.3",
"@typescript-eslint/typescript-estree": "2.20.0", "@typescript-eslint/typescript-estree": "2.22.0",
"eslint-scope": "^5.0.0" "eslint-scope": "^5.0.0"
} }
}, },
"@typescript-eslint/typescript-estree": { "@typescript-eslint/typescript-estree": {
"version": "2.20.0", "version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.20.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.22.0.tgz",
"integrity": "sha512-WlFk8QtI8pPaE7JGQGxU7nGcnk1ccKAJkhbVookv94ZcAef3m6oCE/jEDL6dGte3JcD7reKrA0o55XhBRiVT3A==", "integrity": "sha512-2HFZW2FQc4MhIBB8WhDm9lVFaBDy6h9jGrJ4V2Uzxe/ON29HCHBTj3GkgcsgMWfsl2U5as+pTOr30Nibaw7qRQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"debug": "^4.1.1", "debug": "^4.1.1",
@@ -835,43 +835,43 @@
} }
}, },
"@typescript-eslint/experimental-utils": { "@typescript-eslint/experimental-utils": {
"version": "2.19.0", "version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.19.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.22.0.tgz",
"integrity": "sha512-zwpg6zEOPbhB3+GaQfufzlMUOO6GXCNZq6skk+b2ZkZAIoBhVoanWK255BS1g5x9bMwHpLhX0Rpn5Fc3NdCZdg==", "integrity": "sha512-sJt1GYBe6yC0dWOQzXlp+tiuGglNhJC9eXZeC8GBVH98Zv9jtatccuhz0OF5kC/DwChqsNfghHx7OlIDQjNYAQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/json-schema": "^7.0.3", "@types/json-schema": "^7.0.3",
"@typescript-eslint/typescript-estree": "2.19.0", "@typescript-eslint/typescript-estree": "2.22.0",
"eslint-scope": "^5.0.0" "eslint-scope": "^5.0.0"
} }
}, },
"@typescript-eslint/parser": { "@typescript-eslint/parser": {
"version": "2.20.0", "version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.20.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.22.0.tgz",
"integrity": "sha512-o8qsKaosLh2qhMZiHNtaHKTHyCHc3Triq6aMnwnWj7budm3xAY9owSZzV1uon5T9cWmJRJGzTFa90aex4m77Lw==", "integrity": "sha512-FaZKC1X+nvD7qMPqKFUYHz3H0TAioSVFGvG29f796Nc5tBluoqfHgLbSFKsh7mKjRoeTm8J9WX2Wo9EyZWjG7w==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/eslint-visitor-keys": "^1.0.0", "@types/eslint-visitor-keys": "^1.0.0",
"@typescript-eslint/experimental-utils": "2.20.0", "@typescript-eslint/experimental-utils": "2.22.0",
"@typescript-eslint/typescript-estree": "2.20.0", "@typescript-eslint/typescript-estree": "2.22.0",
"eslint-visitor-keys": "^1.1.0" "eslint-visitor-keys": "^1.1.0"
}, },
"dependencies": { "dependencies": {
"@typescript-eslint/experimental-utils": { "@typescript-eslint/experimental-utils": {
"version": "2.20.0", "version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.20.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.22.0.tgz",
"integrity": "sha512-fEBy9xYrwG9hfBLFEwGW2lKwDRTmYzH3DwTmYbT+SMycmxAoPl0eGretnBFj/s+NfYBG63w/5c3lsvqqz5mYag==", "integrity": "sha512-sJt1GYBe6yC0dWOQzXlp+tiuGglNhJC9eXZeC8GBVH98Zv9jtatccuhz0OF5kC/DwChqsNfghHx7OlIDQjNYAQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/json-schema": "^7.0.3", "@types/json-schema": "^7.0.3",
"@typescript-eslint/typescript-estree": "2.20.0", "@typescript-eslint/typescript-estree": "2.22.0",
"eslint-scope": "^5.0.0" "eslint-scope": "^5.0.0"
} }
}, },
"@typescript-eslint/typescript-estree": { "@typescript-eslint/typescript-estree": {
"version": "2.20.0", "version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.20.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.22.0.tgz",
"integrity": "sha512-WlFk8QtI8pPaE7JGQGxU7nGcnk1ccKAJkhbVookv94ZcAef3m6oCE/jEDL6dGte3JcD7reKrA0o55XhBRiVT3A==", "integrity": "sha512-2HFZW2FQc4MhIBB8WhDm9lVFaBDy6h9jGrJ4V2Uzxe/ON29HCHBTj3GkgcsgMWfsl2U5as+pTOr30Nibaw7qRQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"debug": "^4.1.1", "debug": "^4.1.1",
@@ -892,9 +892,9 @@
} }
}, },
"@typescript-eslint/typescript-estree": { "@typescript-eslint/typescript-estree": {
"version": "2.19.0", "version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.19.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.22.0.tgz",
"integrity": "sha512-n6/Xa37k0jQdwpUszffi19AlNbVCR0sdvCs3DmSKMD7wBttKY31lhD2fug5kMD91B2qW4mQldaTEc1PEzvGu8w==", "integrity": "sha512-2HFZW2FQc4MhIBB8WhDm9lVFaBDy6h9jGrJ4V2Uzxe/ON29HCHBTj3GkgcsgMWfsl2U5as+pTOr30Nibaw7qRQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"debug": "^4.1.1", "debug": "^4.1.1",
@@ -2385,9 +2385,9 @@
} }
}, },
"eslint-plugin-jest": { "eslint-plugin-jest": {
"version": "23.7.0", "version": "23.8.2",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.7.0.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.8.2.tgz",
"integrity": "sha512-zkiyGlvJeHNjAEz8FaIxTXNblJJ/zj3waNbYbgflK7K6uy0cpE5zJBt/JpJtOBGM/UGkC6BqsQ4n0y7kQ2HA8w==", "integrity": "sha512-xwbnvOsotSV27MtAe7s8uGWOori0nUsrXh2f1EnpmXua8sDfY6VZhHAhHg2sqK7HBNycRQExF074XSZ7DvfoFg==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/experimental-utils": "^2.5.0" "@typescript-eslint/experimental-utils": "^2.5.0"
@@ -4598,9 +4598,9 @@
"dev": true "dev": true
}, },
"lint-staged": { "lint-staged": {
"version": "10.0.7", "version": "10.0.8",
"resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-10.0.7.tgz", "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-10.0.8.tgz",
"integrity": "sha512-Byj0F4l7GYUpYYHEqyFH69NiI6ICTg0CeCKbhRorL+ickbzILKUlZLiyCkljZV02wnoh7yH7PmFyYm9PRNwk9g==", "integrity": "sha512-Oa9eS4DJqvQMVdywXfEor6F4vP+21fPHF8LUXgBbVWUSWBddjqsvO6Bv1LwMChmgQZZqwUvgJSHlu8HFHAPZmA==",
"dev": true, "dev": true,
"requires": { "requires": {
"chalk": "^3.0.0", "chalk": "^3.0.0",
@@ -7507,9 +7507,9 @@
} }
}, },
"typescript": { "typescript": {
"version": "3.8.2", "version": "3.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.2.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz",
"integrity": "sha512-EgOVgL/4xfVrCMbhYKUQTdF37SQn4Iw73H5BgCrF1Abdun7Kwy/QZsE/ssAy0y4LxBbvua3PIbFsbRczWWnDdQ==", "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==",
"dev": true "dev": true
}, },
"uglify-js": { "uglify-js": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "actions-github-pages", "name": "actions-github-pages",
"version": "3.3.0", "version": "3.4.1",
"description": "GitHub Actions for GitHub Pages", "description": "GitHub Actions for GitHub Pages",
"main": "lib/index.js", "main": "lib/index.js",
"engines": { "engines": {
@@ -50,7 +50,7 @@
}, },
"homepage": "https://github.com/peaceiris/actions-gh-pages#readme", "homepage": "https://github.com/peaceiris/actions-gh-pages#readme",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.2", "@actions/core": "^1.2.3",
"@actions/exec": "^1.0.3", "@actions/exec": "^1.0.3",
"@actions/github": "^2.1.1", "@actions/github": "^2.1.1",
"@actions/io": "^1.0.2" "@actions/io": "^1.0.2"
@@ -58,18 +58,18 @@
"devDependencies": { "devDependencies": {
"@types/jest": "^25.1.3", "@types/jest": "^25.1.3",
"@types/node": "~12", "@types/node": "~12",
"@typescript-eslint/eslint-plugin": "^2.20.0", "@typescript-eslint/eslint-plugin": "^2.22.0",
"@typescript-eslint/parser": "^2.20.0", "@typescript-eslint/parser": "^2.22.0",
"@zeit/ncc": "^0.21.1", "@zeit/ncc": "^0.21.1",
"eslint": "^6.8.0", "eslint": "^6.8.0",
"eslint-plugin-jest": "^23.7.0", "eslint-plugin-jest": "^23.8.2",
"husky": "^4.2.3", "husky": "^4.2.3",
"jest": "^25.1.0", "jest": "^25.1.0",
"jest-circus": "^25.1.0", "jest-circus": "^25.1.0",
"lint-staged": "^10.0.7", "lint-staged": "^10.0.8",
"prettier": "1.19.1", "prettier": "1.19.1",
"standard-version": "^7.1.0", "standard-version": "^7.1.0",
"ts-jest": "^25.2.1", "ts-jest": "^25.2.1",
"typescript": "^3.8.2" "typescript": "^3.8.3"
} }
} }

View File

@@ -1,28 +1,32 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import {Inputs} from './interfaces'; import {Inputs} from './interfaces';
function showInputs(inps: Inputs): void { export function showInputs(inps: Inputs): void {
let authMethod = '';
if (inps.DeployKey) { if (inps.DeployKey) {
core.info(`[INFO] DeployKey: true`); authMethod = 'DeployKey';
} else if (inps.GithubToken) { } else if (inps.GithubToken) {
core.info(`[INFO] GithubToken: true`); authMethod = 'GithubToken';
} else if (inps.PersonalToken) { } else if (inps.PersonalToken) {
core.info(`[INFO] PersonalToken: true`); authMethod = 'PersonalToken';
} }
core.info(`[INFO] PublishBranch: ${inps.PublishBranch}`); core.info(`\
core.info(`[INFO] PublishDir: ${inps.PublishDir}`); [INFO] ${authMethod}: true
core.info(`[INFO] ExternalRepository: ${inps.ExternalRepository}`); [INFO] PublishBranch: ${inps.PublishBranch}
core.info(`[INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}`); [INFO] PublishDir: ${inps.PublishDir}
core.info(`[INFO] KeepFiles: ${inps.KeepFiles}`); [INFO] ExternalRepository: ${inps.ExternalRepository}
core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`); [INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}
core.info(`[INFO] UserName: ${inps.UserName}`); [INFO] KeepFiles: ${inps.KeepFiles}
core.info(`[INFO] UserEmail: ${inps.UserEmail}`); [INFO] ForceOrphan: ${inps.ForceOrphan}
core.info(`[INFO] CommitMessage: ${inps.CommitMessage}`); [INFO] UserName: ${inps.UserName}
core.info(`[INFO] TagName: ${inps.TagName}`); [INFO] UserEmail: ${inps.UserEmail}
core.info(`[INFO] TagMessage: ${inps.TagMessage}`); [INFO] CommitMessage: ${inps.CommitMessage}
core.info(`[INFO] DisableNoJekyll: ${inps.DisableNoJekyll}`); [INFO] TagName: ${inps.TagName}
core.info(`[INFO] CNAME: ${inps.CNAME}`); [INFO] TagMessage: ${inps.TagMessage}
[INFO] DisableNoJekyll: ${inps.DisableNoJekyll}
[INFO] CNAME: ${inps.CNAME}
`);
} }
export function getInputs(): Inputs { export function getInputs(): Inputs {
@@ -49,7 +53,5 @@ export function getInputs(): Inputs {
CNAME: core.getInput('cname') CNAME: core.getInput('cname')
}; };
showInputs(inps);
return inps; return inps;
} }

View File

@@ -94,7 +94,7 @@ export async function setRepo(
core.info( core.info(
`[INFO] first deployment, create new branch ${inps.PublishBranch}` `[INFO] first deployment, create new branch ${inps.PublishBranch}`
); );
core.info(e); core.info(e.message);
await createWorkDir(workDir); await createWorkDir(workDir);
process.chdir(workDir); process.chdir(workDir);
await createBranchForce(inps.PublishBranch); await createBranchForce(inps.PublishBranch);
@@ -156,7 +156,7 @@ export async function commit(
} }
} catch (e) { } catch (e) {
core.info('[INFO] skip commit'); core.info('[INFO] skip commit');
core.debug(`[INFO] skip commit ${e}`); core.debug(`[INFO] skip commit ${e.message}`);
} }
} }

View File

@@ -5,6 +5,6 @@ import * as main from './main';
try { try {
await main.run(); await main.run();
} catch (e) { } catch (e) {
core.setFailed(`Action failed with "${e}"`); core.setFailed(`Action failed with "${e.message}"`);
} }
})(); })();

View File

@@ -1,7 +1,7 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import {Inputs} from './interfaces'; import {Inputs} from './interfaces';
import {getInputs} from './get-inputs'; import {showInputs, getInputs} from './get-inputs';
import {setTokens} from './set-tokens'; import {setTokens} from './set-tokens';
import * as git from './git-utils'; import * as git from './git-utils';
import {getWorkDirName, addNoJekyll, addCNAME} from './utils'; import {getWorkDirName, addNoJekyll, addCNAME} from './utils';
@@ -9,6 +9,7 @@ import {getWorkDirName, addNoJekyll, addCNAME} from './utils';
export async function run(): Promise<void> { export async function run(): Promise<void> {
try { try {
const inps: Inputs = getInputs(); const inps: Inputs = getInputs();
showInputs(inps);
await git.setConfig(inps.UserName, inps.UserEmail); await git.setConfig(inps.UserName, inps.UserEmail);
@@ -26,7 +27,7 @@ export async function run(): Promise<void> {
try { try {
await exec.exec('git', ['remote', 'rm', 'origin']); await exec.exec('git', ['remote', 'rm', 'origin']);
} catch (e) { } catch (e) {
core.info(`[INFO] ${e}`); core.info(`[INFO] ${e.message}`);
} }
await exec.exec('git', ['remote', 'add', 'origin', remoteURL]); await exec.exec('git', ['remote', 'add', 'origin', remoteURL]);
await exec.exec('git', ['add', '--all']); await exec.exec('git', ['add', '--all']);
@@ -43,6 +44,6 @@ export async function run(): Promise<void> {
return; return;
} catch (e) { } catch (e) {
throw new Error(e); throw new Error(e.message);
} }
} }

View File

@@ -9,13 +9,6 @@ const cpexec = require('child_process').execFileSync;
import {Inputs} from './interfaces'; import {Inputs} from './interfaces';
import {getHomeDir} from './utils'; import {getHomeDir} from './utils';
export function setPublishRepo(insp: Inputs): string {
if (insp.ExternalRepository) {
return insp.ExternalRepository;
}
return `${github.context.repo.owner}/${github.context.repo.repo}`;
}
export async function setSSHKey( export async function setSSHKey(
inps: Inputs, inps: Inputs,
publishRepo: string publishRepo: string
@@ -66,57 +59,82 @@ Host github
return `git@github.com:${publishRepo}.git`; return `git@github.com:${publishRepo}.git`;
} }
export async function setGithubToken( export function setGithubToken(
inps: Inputs, githubToken: string,
publishRepo: string publishRepo: string,
): Promise<string> { publishBranch: string,
externalRepository: string,
ref: string,
eventName: string
): string {
core.info('[INFO] setup GITHUB_TOKEN'); core.info('[INFO] setup GITHUB_TOKEN');
const context = github.context; core.debug(`ref: ${ref}`);
core.debug(`ref: ${context.ref}`); core.debug(`eventName: ${eventName}`);
core.debug(`eventName: ${context.eventName}`);
let isProhibitedBranch = false; let isProhibitedBranch = false;
const ref = context.ref; if (eventName === 'push') {
if (context.eventName === 'push') { isProhibitedBranch = ref.includes(`refs/heads/${publishBranch}`);
isProhibitedBranch = ref.includes(`refs/heads/${inps.PublishBranch}`);
if (isProhibitedBranch) { if (isProhibitedBranch) {
throw new Error( throw new Error(`You deploy from ${publishBranch} to ${publishBranch}`);
`You deploy from ${inps.PublishBranch} to ${inps.PublishBranch}`
);
} }
} }
if (inps.ExternalRepository) { if (externalRepository) {
throw new Error( throw new Error(
'GITHUB_TOKEN does not support to push to an external repository' 'GITHUB_TOKEN does not support to push to an external repository'
); );
} }
return `https://x-access-token:${inps.GithubToken}@github.com/${publishRepo}.git`; return `https://x-access-token:${githubToken}@github.com/${publishRepo}.git`;
} }
export async function setPersonalToken( export function setPersonalToken(
inps: Inputs, personalToken: string,
publishRepo: string publishRepo: string
): Promise<string> { ): string {
core.info('[INFO] setup personal access token'); core.info('[INFO] setup personal access token');
return `https://x-access-token:${inps.PersonalToken}@github.com/${publishRepo}.git`; return `https://x-access-token:${personalToken}@github.com/${publishRepo}.git`;
}
export function getPublishRepo(
externalRepository: string,
owner: string,
repo: string
): string {
if (externalRepository) {
return externalRepository;
}
return `${owner}/${repo}`;
} }
export async function setTokens(inps: Inputs): Promise<string> { export async function setTokens(inps: Inputs): Promise<string> {
try { try {
const publishRepo = setPublishRepo(inps); const publishRepo = getPublishRepo(
inps.ExternalRepository,
github.context.repo.owner,
github.context.repo.repo
);
if (inps.DeployKey) { if (inps.DeployKey) {
return setSSHKey(inps, publishRepo); return setSSHKey(inps, publishRepo);
} else if (inps.GithubToken) { } else if (inps.GithubToken) {
return setGithubToken(inps, publishRepo); const context = github.context;
const ref = context.ref;
const eventName = context.eventName;
return setGithubToken(
inps.GithubToken,
publishRepo,
inps.PublishBranch,
inps.ExternalRepository,
ref,
eventName
);
} else if (inps.PersonalToken) { } else if (inps.PersonalToken) {
return setPersonalToken(inps, publishRepo); return setPersonalToken(inps.PersonalToken, publishRepo);
} else { } else {
throw new Error('not found deploy key or tokens'); throw new Error('not found deploy key or tokens');
} }
} catch (e) { } catch (e) {
throw new Error(e); throw new Error(e.message);
} }
} }