Compare commits

...

44 Commits

Author SHA1 Message Date
peaceiris
e4df4b2d92 github: Enhance action name 2019-10-29 03:30:53 +09:00
peaceiris
d6d7a5601d github: Remove FUNDING.yml 2019-10-29 03:27:49 +09:00
peaceiris
cd78101d9c docs: Remove Hugo --gc flag
This flag should be used on local.
It is wasteful to use the Garbage Collection on CI.
2019-10-24 21:46:41 +09:00
peaceiris
8076e77c01 github: Add CODEOWNERS 2019-10-24 06:04:56 +09:00
peaceiris
5e8a6ff9d9 ci: Add dependabot config 2019-10-23 19:52:00 +09:00
dependabot-preview[bot]
78a8692f54 build(deps): bump alpine from 3.10.2 to 3.10.3 (#44)
Bumps alpine from 3.10.2 to 3.10.3.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-22 15:08:18 +09:00
peaceiris
69067de181 docs: Remove the link to actions tab
We need to login to access the actions tab.

https://github.com/sdras/awesome-actions/issues/232
2019-10-17 16:36:44 +09:00
peaceiris
7f7794a793 docs: update Hugo workflow example, enhance build step 2019-10-14 22:03:59 +09:00
peaceiris
e60d374041 docs: Enhance node-version 2019-10-08 18:59:10 +09:00
imgbot[bot]
8191f265b1 [ImgBot] Optimize images (#40)
/images/ogp.svg -- 45.84kb -> 45.82kb (0.05%)

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
2019-10-08 14:00:13 +09:00
peaceiris
4eb9565412 docs: update 2019-10-07 03:20:07 +09:00
peaceiris
e5910bfc4f docs: update tag 2019-10-07 00:21:11 +09:00
peaceiris
09158e35aa docs: Fix tag 2019-10-07 00:01:25 +09:00
peaceiris
26405de510 docs: update latest tag 2019-10-07 00:00:09 +09:00
Shohei Ueda
855ba06744 Release: v2.5.0 (#38)
* gha: enhance trigger
* feat: Add SCRIPT_MODE
* docs: Update about GITHUB_TOKEN
* docs: Add new section about Script mode, close #37
2019-10-06 23:53:36 +09:00
peaceiris
159b07d518 docs: update 2019-10-06 21:10:05 +09:00
Simon Eßlinger
37e4747275 feat: deploy to other repo (#36)
* feat: Add EXTERNAL_REPOSITORY option
* docs: Add section about EXTERNAL_REPOSITORY
2019-10-06 19:41:46 +09:00
peaceiris
ea833f5400 meta: Update description 2019-10-03 11:31:57 +09:00
peaceiris
3ceceb921f docs: Add new section (Use the latest and specific release) 2019-09-29 18:03:31 +09:00
peaceiris
9e74ae3f23 docs: update 2019-09-29 17:50:32 +09:00
peaceiris
76490a48db docs: enhance TOC 2019-09-29 17:46:43 +09:00
peaceiris
c138367a6e docs: Add Back to TOC link 2019-09-29 17:42:23 +09:00
peaceiris
3e2f32bb1e docs: enhance description 2019-09-29 17:36:37 +09:00
peaceiris
f54520fcda docs: Add file addition examples 2019-09-29 14:26:04 +09:00
peaceiris
83bc08b934 docs: update tag of peaceiris/actions-hugo to v2.2.1 2019-09-25 12:45:09 +09:00
Shohei Ueda
380b190669 fix: avoid #29 for keepFiles option (#34)
Some checks failed
docker image ci / test (push) Has been cancelled
docker image ci / shellcheck (push) Has been cancelled
docker image ci / hadolint (push) Has been cancelled
* fix: avoid #29
* docs: update TOC
* docs: update tag to v2.4.0
2019-09-25 03:00:25 +09:00
Roman Hotsiy
8eedda6921 feat: new option keepFiles (#33) 2019-09-25 02:41:21 +09:00
peaceiris
13d694636e docs: Add submodules to actions/checkout
https://github.com/peaceiris/actions-hugo/issues/42
2019-09-24 07:29:34 +09:00
peaceiris
551961e807 gha: remove paths 2019-09-23 14:36:00 +09:00
peaceiris
3e09c28a79 docs: update tag 2019-09-23 14:07:50 +09:00
Shohei Ueda
8f168fea5a fix: Fixes for docker hub image (#28)
Some checks failed
docker image ci / test (push) Has been cancelled
docker image ci / shellcheck (push) Has been cancelled
docker image ci / hadolint (push) Has been cancelled
* fix: Fixes for docker hub image (INPUT_EMPTYCOMMITS false condition)
* fix: Add skip function

Close #27
Close #31 
Keep open #29 

* gha: Add fetch-depth 1 to actions/checkout
* gha: Add pull_request trigger, Close #32
2019-09-23 14:00:10 +09:00
peaceiris
5a72c9206d docs: update 2019-09-22 16:15:46 +09:00
peaceiris
b8dd2848eb gha: Add paths trigger 2019-09-22 16:14:23 +09:00
peaceiris
4530dcd167 docs: Add link to issue #9
https://github.com/peaceiris/actions-gh-pages/issues/31
2019-09-22 14:03:03 +09:00
Shohei Ueda
74f032c7e9 docs: Add log images (#30)
* docs: Add log images
* docs: replace star emoji
2019-09-22 13:06:23 +09:00
peaceiris
0713c6cb9c docs: update peaceiris/actions-hugo@v2.2.0 2019-09-21 10:48:31 +09:00
peaceiris
c647ffeac6 style: reindent 2019-09-20 14:59:10 +09:00
peaceiris
b16172a44d docs: Add section about .nojekyll #26 2019-09-20 09:07:35 +09:00
peaceiris
4f0ad674b7 docs: update peaceiris/actions-hugo@v2.1.0 2019-09-18 04:26:28 +09:00
peaceiris
16fae5a6db docs: Add Tips and FAQ section for #25 2019-09-17 22:55:15 +09:00
peaceiris
e46ccd0122 docs: Add peaceiris/actions-hugo@v2.0.0 2019-09-16 08:40:04 +09:00
peaceiris
087a904156 docs: Upgrade peaceiris/actions-gh-pages to v2.3.1 2019-09-16 01:11:55 +09:00
blue-jam
47a6d63ea8 Fix: "git rm" fails when publish branch is empty (#24)
Some checks failed
docker image ci / test (push) Has been cancelled
docker image ci / shellcheck (push) Has been cancelled
docker image ci / hadolint (push) Has been cancelled
When a publish branch exists and it has no files, `git rm -r '*'` fails with

```
fatal: pathspec '*' did not match any files
```

`--ignore-unmatch` option let git exit with a zero status in this case.

Reference: https://git-scm.com/docs/git-rm#Documentation/git-rm.txt---ignore-unmatch
2019-09-16 01:06:45 +09:00
peaceiris
201f9af234 docs: Update Hugo workflow example
- Update Hugo workflow example (Install Hugo with downloading binary)
- Remove `peaceiris/actions-hugo` from README

Close #23
2019-09-15 04:24:29 +09:00
18 changed files with 312 additions and 107 deletions

10
.dependabot/config.yml Normal file
View File

@@ -0,0 +1,10 @@
version: 1
update_configs:
- package_manager: "docker"
directory: "/"
update_schedule: "weekly"
default_labels:
- "dependencies"
- "docker"
commit_message:
prefix: "deps"

3
.github/CODEOWNERS vendored Normal file
View File

@@ -0,0 +1,3 @@
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
* @peaceiris

9
.github/FUNDING.yml vendored
View File

@@ -1,9 +0,0 @@
# These are supported funding model platforms
# github: peaceiris
patreon: peaceiris
issuehunt: peaceiris
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
custom: # Replace with a single custom sponsorship URL

View File

@@ -1,6 +1,11 @@
name: docker image ci name: docker image ci
on: push on:
pull_request:
types: [opened, synchronize]
push:
branches:
- master
jobs: jobs:
test: test:
@@ -8,6 +13,8 @@ jobs:
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master
with:
fetch-depth: 1
- name: build - name: build
env: env:
@@ -20,6 +27,8 @@ jobs:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master
with:
fetch-depth: 1
- name: shellcheck - name: shellcheck
run: shellcheck ./entrypoint.sh run: shellcheck ./entrypoint.sh
@@ -27,6 +36,8 @@ jobs:
runs-on: macOS-10.14 runs-on: macOS-10.14
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master
with:
fetch-depth: 1
- name: hadolint - name: hadolint
run: | run: |
brew install hadolint brew install hadolint

View File

@@ -1,4 +1,4 @@
FROM alpine:3.10.2 FROM alpine:3.10.3
RUN apk add --no-cache \ RUN apk add --no-cache \
bash \ bash \

297
README.md
View File

@@ -1,39 +1,62 @@
[![license](https://img.shields.io/github/license/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/blob/master/LICENSE) [![license](https://img.shields.io/github/license/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/blob/master/LICENSE)
[![release](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/releases/latest) [![release](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/releases/latest)
[![GitHub release date](https://img.shields.io/github/release-date/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/releases) [![GitHub release date](https://img.shields.io/github/release-date/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/releases)
[![GitHub Actions status](https://github.com/peaceiris/actions-gh-pages/workflows/docker%20image%20ci/badge.svg)](https://github.com/peaceiris/actions-gh-pages/actions) ![GitHub Actions status](https://github.com/peaceiris/actions-gh-pages/workflows/docker%20image%20ci/badge.svg)
[![Docker Hub Build Status](https://img.shields.io/docker/cloud/build/peaceiris/gh-pages.svg)](https://hub.docker.com/r/peaceiris/gh-pages) [![Docker Hub Build Status](https://img.shields.io/docker/cloud/build/peaceiris/gh-pages.svg)](https://hub.docker.com/r/peaceiris/gh-pages)
<img width="400" alt="GitHub Actions for deploying to GitHub Pages with Static Site Generators" src="./images/ogp.svg"> <img width="400" alt="GitHub Actions for deploying to GitHub Pages with Static Site Generators" src="./images/ogp.svg">
## GitHub Actions for deploying to GitHub Pages ## GitHub Actions for GitHub Pages
A GitHub Action to deploy your static site to GitHub Pages with [Static Site Generators] (Hugo, MkDocs, Gatsby, GitBook, etc.) This is a **GitHub Action** to deploy your static files to **GitHub Pages**.
This deploy action can be combined simply and freely with [Static Site Generators]. (Hugo, MkDocs, Gatsby, GitBook, etc.)
[Static Site Generators]: https://www.staticgen.com/ [Static Site Generators]: https://www.staticgen.com/
```yaml
- name: Deploy
uses: peaceiris/actions-gh-pages@v2.5.0
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public
```
The above example step will deploy `./public` directory to `gh-pages` branch.
## Table of Contents
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
Table of Contents
- [Getting started](#getting-started) - [Getting started](#getting-started)
- [(1) Add ssh deploy key](#1-add-ssh-deploy-key) - [(1) Add SSH deploy key](#1-add-ssh-deploy-key)
- [(2) Create `.github/workflows/gh-pages.yml`](#2-create-githubworkflowsgh-pagesyml) - [(2) Create your workflow](#2-create-your-workflow)
- [:star: Repository type - Project](#star-repository-type---project) - [⭐️ Repository type - Project](#%EF%B8%8F-repository-type---project)
- [:star: Repository type - User and Organization](#star-repository-type---user-and-organization) - [⭐️ Repository type - User and Organization](#%EF%B8%8F-repository-type---user-and-organization)
- [Options](#options) - [Options](#options)
- [:star: Pull action image from Docker Hub](#star-pull-action-image-from-docker-hub) - [⭐️ Pull action image from Docker Hub](#%EF%B8%8F-pull-action-image-from-docker-hub)
- [:star: `PERSONAL_TOKEN`](#star-personal_token) - [⭐️ `PERSONAL_TOKEN`](#%EF%B8%8F-personal_token)
- [:star: `GITHUB_TOKEN`](#star-github_token) - [⭐️ `GITHUB_TOKEN`](#%EF%B8%8F-github_token)
- [:star: Suppressing empty commits](#star-suppressing-empty-commits) - [⭐️ Suppressing empty commits](#%EF%B8%8F-suppressing-empty-commits)
- [⭐️ Keeping existing files](#%EF%B8%8F-keeping-existing-files)
- [⭐️ Deploy to external repository](#%EF%B8%8F-deploy-to-external-repository)
- [⭐️ Script mode](#%EF%B8%8F-script-mode)
- [Tips and FAQ](#tips-and-faq)
- [⭐️ 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](#static-site-generators-with-nodejs) - [⭐️ Static Site Generators with Node.js](#%EF%B8%8F-static-site-generators-with-nodejs)
- [Gatsby](#gatsby) - [⭐️ Gatsby](#%EF%B8%8F-gatsby)
- [React and Next](#react-and-next) - [⭐️ React and Next](#%EF%B8%8F-react-and-next)
- [Vue and Nuxt](#vue-and-nuxt) - [⭐️ Vue and Nuxt](#%EF%B8%8F-vue-and-nuxt)
- [Static Site Generators with Python](#static-site-generators-with-python) - [⭐️ Static Site Generators with Python](#%EF%B8%8F-static-site-generators-with-python)
- [License](#license) - [License](#license)
- [About the author](#about-the-author) - [About the author](#about-the-author)
@@ -43,7 +66,7 @@ Table of Contents
## Getting started ## Getting started
### (1) Add ssh deploy key ### (1) Add SSH deploy key
Generate your deploy key with the following command. Generate your deploy key with the following command.
@@ -59,13 +82,23 @@ Next, Go to **Repository Settings**
- Go to **Deploy Keys** and add your public key with the **Allow write access** - 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` - Go to **Secrets** and add your private key as `ACTIONS_DEPLOY_KEY`
### (2) Create `.github/workflows/gh-pages.yml` | Add your public key | Success |
|---|---|
| ![](./images/deploy-keys-1.jpg) | ![](./images/deploy-keys-2.jpg) |
#### :star: Repository type - Project | Add your private key | Success |
|---|---|
| ![](./images/secrets-1.jpg) | ![](./images/secrets-2.jpg) |
An example yaml file with Hugo action. ### (2) Create your workflow
- [peaceiris/actions-hugo: GitHub Actions for Hugo extended](https://github.com/peaceiris/actions-hugo) 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.
- [peaceiris/actions-hugo: GitHub Actions for Hugo](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 - GitHub](https://gh-card.dev/repos/peaceiris/actions-hugo.svg?fullname)](https://github.com/peaceiris/actions-hugo)
@@ -85,14 +118,19 @@ jobs:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@master
# with:
# submodules: true
- name: build - name: Setup Hugo
uses: peaceiris/actions-hugo@v0.58.1 uses: peaceiris/actions-hugo@v2.2.2
with: with:
args: --gc --minify --cleanDestinationDir hugo-version: '0.58.3'
- name: deploy - name: Build
uses: peaceiris/actions-gh-pages@v2.3.0 run: hugo --minify
- name: Deploy
uses: peaceiris/actions-gh-pages@v2.5.0
env: env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages PUBLISH_BRANCH: gh-pages
@@ -101,7 +139,15 @@ jobs:
The above example is for [Project Pages sites]. (`<username>/<project_name>` repository) The above example is for [Project Pages sites]. (`<username>/<project_name>` repository)
#### :star: Repository type - User and Organization | Actions log overview | Build step log |
|---|---|
| ![](./images/log1.jpg) | ![](./images/log2.jpg) |
| Deploy step log | GitHub Pages log |
|---|---|
| ![](./images/log3.jpg) | ![](./images/log4.jpg) |
#### ⭐️ 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`.
@@ -118,28 +164,29 @@ PUBLISH_BRANCH: master # deploying branch
[Project Pages sites]: https://help.github.com/en/articles/user-organization-and-project-pages#project-pages-sites [Project Pages sites]: https://help.github.com/en/articles/user-organization-and-project-pages#project-pages-sites
[User and Organization Pages sites]: https://help.github.com/en/articles/user-organization-and-project-pages#user-and-organization-pages-sites [User and Organization Pages sites]: https://help.github.com/en/articles/user-organization-and-project-pages#user-and-organization-pages-sites
### Options ![Change default branch](./images/default-branch.jpg)
#### :star: Pull action image from Docker Hub <div align="right">
<a href="#table-of-contents">Back to TOC ☝️</a>
</div>
## Options
### ⭐️ Pull action image from Docker Hub
You can pull a public docker image from Docker Hub. You can pull a public docker image from Docker Hub.
By pulling docker images, you can reduce the overall execution time of your workflow. In addition, `latest` tag is provided. By pulling docker images, you can reduce the overall execution time of your workflow. In addition, `latest` tag is provided.
```diff ```diff
- uses: peaceiris/actions-gh-pages@v2.3.0 - uses: peaceiris/actions-gh-pages@v2.5.0
+ uses: docker://peaceiris/gh-pages:v2.3.0 + uses: docker://peaceiris/gh-pages:v2.5.0
``` ```
- [peaceiris/gh-pages - Docker Hub](https://hub.docker.com/r/peaceiris/gh-pages) - [peaceiris/gh-pages - Docker Hub](https://hub.docker.com/r/peaceiris/gh-pages)
```diff ### ⭐️ `PERSONAL_TOKEN`
- uses: peaceiris/actions-hugo@v0.58.1
+ uses: docker://peaceiris/gha-hugo:v0.58.1
```
- [peaceiris/gha-hugo - Docker Hub](https://hub.docker.com/r/peaceiris/gha-hugo)
#### :star: `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`.
@@ -148,16 +195,20 @@ By pulling docker images, you can reduce the overall execution time of your work
+ PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }} + PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
``` ```
#### :star: `GITHUB_TOKEN` ### ⭐️ `GITHUB_TOKEN`
> **NOTES**: This action supports `GITHUB_TOKEN` but it has some problems to deploy to GitHub Pages. See #9 > ⚠️ **NOTES**: `GITHUB_TOKEN` works only on a **private** repository.
>
> This action supports `GITHUB_TOKEN` but it has some problems to deploy to GitHub Pages. GitHub team is investigating that. See [Issue #9]
[Issue #9]: https://github.com/peaceiris/actions-gh-pages/issues/9
```diff ```diff
- ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} - ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
``` ```
#### :star: Suppressing empty commits ### ⭐️ Suppressing empty commits
By default, a commit will always be generated and pushed to the `PUBLISH_BRANCH`, even if nothing changed. If you want to suppress this behavior, set the optional parameter `emptyCommits` to `false`. cf. [Issue #21] By default, a commit will always be generated and pushed to the `PUBLISH_BRANCH`, even if nothing changed. If you want to suppress this behavior, set the optional parameter `emptyCommits` to `false`. cf. [Issue #21]
@@ -166,8 +217,8 @@ By default, a commit will always be generated and pushed to the `PUBLISH_BRANCH`
For example: For example:
```yaml ```yaml
- name: deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v2.3.0 uses: peaceiris/actions-gh-pages@v2.5.0
env: env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages PUBLISH_BRANCH: gh-pages
@@ -176,11 +227,131 @@ For example:
emptyCommits: false emptyCommits: false
``` ```
### ⭐️ Keeping existing files
By default, existing files in the publish branch are removed before adding the ones from publish dir. If you want the action to add new files but leave existing ones untouched, set the optional parameter `keepFiles` to `true`.
For example:
```yaml
- name: Deploy
uses: peaceiris/actions-gh-pages@v2.5.0
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public
with:
keepFiles: true
```
### ⭐️ Deploy to external repository
By default, your files are published to the repository which is running this action.
If you want to publish to another repository on GitHub, set the environment variable `EXTERNAL_REPOSITORY` to `<username>/<external-repository>`.
This option is available from `v2.5.0`.
For example:
```yaml
- name: Deploy
uses: peaceiris/actions-gh-pages@v2.5.0
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
EXTERNAL_REPOSITORY: username/external-repository
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public
```
You can use `ACTIONS_DEPLOY_KEY` or `PERSONAL_TOKEN`.
When you use `ACTIONS_DEPLOY_KEY`, set your private key to the repository which includes this action and set your public key to your external repository.
Be careful, `GITHUB_TOKEN` has no permission to access to external repositories.
### ⭐️ Script mode
From `v2.5.0`, we can run this action as a shell script.
There is no Docker build or pull step, so it will start immediately.
- `ACTIONS_DEPLOY_KEY` requires `SCRIPT_MODE: true`
- `*_TOKEN` do not require `SCRIPT_MODE`
```yaml
- name: Deploy
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public
SCRIPT_MODE: true
run: |
wget https://raw.githubusercontent.com/peaceiris/actions-gh-pages/v2.5.0/entrypoint.sh
bash ./entrypoint.sh
```
<div align="right">
<a href="#table-of-contents">Back to TOC ☝️</a>
</div>
## Tips and FAQ
### ⭐️ Use the latest and specific release
We recommend you to use the latest and specific release of this action for stable CI/CD.
It is useful to watch this repository (release only) to check the [latest release] of this action.
[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">
<a href="#table-of-contents">Back to TOC ☝️</a>
</div>
## Examples ## Examples
### Static Site Generators with Node.js ### ⭐️ Static Site Generators with Node.js
[hexo], [gitbook], [vuepress], [react-static], [gridsome], etc. [hexo], [gitbook], [vuepress], [react-static], [gridsome], etc.
@@ -211,20 +382,20 @@ jobs:
- name: build - name: build
uses: actions/setup-node@v1 uses: actions/setup-node@v1
with: with:
node-version: '10.16' node-version: '10.x'
- run: | - run: |
npm install npm install
npm run build npm run build
- name: deploy - name: deploy
uses: peaceiris/actions-gh-pages@v2.3.0 uses: peaceiris/actions-gh-pages@v2.5.0
env: env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public PUBLISH_DIR: ./public
``` ```
### Gatsby ### ⭐️ Gatsby
An example for [Gatsby] (Gatsby.js) project with [gatsby-starter-blog] An example for [Gatsby] (Gatsby.js) project with [gatsby-starter-blog]
@@ -250,7 +421,7 @@ jobs:
- name: setup node - name: setup node
uses: actions/setup-node@v1 uses: actions/setup-node@v1
with: with:
node-version: '10.16' node-version: '10.x'
- name: install - name: install
run: npm install run: npm install
@@ -265,14 +436,14 @@ jobs:
run: npm run build run: npm run build
- name: deploy - name: deploy
uses: peaceiris/actions-gh-pages@v2.3.0 uses: peaceiris/actions-gh-pages@v2.5.0
env: env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public PUBLISH_DIR: ./public
``` ```
### React and Next ### ⭐️ React and Next
An example for [Next.js] (React.js) project with [create-next-app] An example for [Next.js] (React.js) project with [create-next-app]
@@ -300,7 +471,7 @@ jobs:
- name: setup node - name: setup node
uses: actions/setup-node@v1 uses: actions/setup-node@v1
with: with:
node-version: '10.16' node-version: '10.x'
- name: install - name: install
run: yarn install run: yarn install
@@ -315,14 +486,14 @@ jobs:
run: touch ./out/.nojekyll run: touch ./out/.nojekyll
- name: deploy - name: deploy
uses: peaceiris/actions-gh-pages@v2.3.0 uses: peaceiris/actions-gh-pages@v2.5.0
env: env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./out PUBLISH_DIR: ./out
``` ```
### Vue and Nuxt ### ⭐️ Vue and Nuxt
An example for [Nuxt.js] (Vue.js) project with [create-nuxt-app] An example for [Nuxt.js] (Vue.js) project with [create-nuxt-app]
@@ -350,7 +521,7 @@ jobs:
- name: setup node - name: setup node
uses: actions/setup-node@v1 uses: actions/setup-node@v1
with: with:
node-version: '10.16' node-version: '10.x'
- name: install - name: install
run: npm install run: npm install
@@ -362,14 +533,14 @@ jobs:
run: npm run generate run: npm run generate
- name: deploy - name: deploy
uses: peaceiris/actions-gh-pages@v2.3.0 uses: peaceiris/actions-gh-pages@v2.5.0
env: env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./dist PUBLISH_DIR: ./dist
``` ```
### Static Site Generators with Python ### ⭐️ Static Site Generators with Python
[pelican], [MkDocs], [sphinx], etc. [pelican], [MkDocs], [sphinx], etc.
@@ -410,7 +581,7 @@ jobs:
run: mkdocs build run: mkdocs build
- name: Deploy - name: Deploy
uses: peaceiris/actions-gh-pages@v2.3.0 uses: peaceiris/actions-gh-pages@v2.5.0
env: env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
PUBLISH_BRANCH: gh-pages PUBLISH_BRANCH: gh-pages
@@ -430,3 +601,9 @@ jobs:
## About the author ## About the author
- [peaceiris's homepage](https://peaceiris.com/) - [peaceiris's homepage](https://peaceiris.com/)
<div align="right">
<a href="#table-of-contents">Back to TOC ☝️</a>
</div>

View File

@@ -1,5 +1,5 @@
name: 'Deploy action for GitHub Pages' name: 'GitHub Pages action'
description: 'A GitHub Action to deploy your static site to GitHub Pages with Static Site Generator' description: 'GitHub Actions for GitHub Pages 🚀 Deploy static files and publish your site easily. Static-Site-Generators-friendly.'
author: 'peaceiris' author: 'peaceiris'
runs: runs:
using: 'docker' using: 'docker'
@@ -12,3 +12,7 @@ inputs:
description: 'If empty commits should be made to the publication branch' description: 'If empty commits should be made to the publication branch'
required: false required: false
default: 'true' default: 'true'
keepFiles:
description: 'If existing files in the publish branch should be not removed before deploying'
required: false
default: 'false'

View File

@@ -11,29 +11,53 @@ function print_info() {
echo -e "\e[36mINFO: ${1}\e[m" echo -e "\e[36mINFO: ${1}\e[m"
} }
function skip() {
print_info "No changes detected, skipping deployment"
exit 0
}
# check values # check values
if [ -n "${EXTERNAL_REPOSITORY}" ]; then
PUBLISH_REPOSITORY=${EXTERNAL_REPOSITORY}
else
PUBLISH_REPOSITORY=${GITHUB_REPOSITORY}
fi
print_info "Deploy to ${PUBLISH_REPOSITORY}"
if [ -n "${ACTIONS_DEPLOY_KEY}" ]; then if [ -n "${ACTIONS_DEPLOY_KEY}" ]; then
print_info "setup with ACTIONS_DEPLOY_KEY" print_info "setup with ACTIONS_DEPLOY_KEY"
mkdir /root/.ssh if [ -n "${SCRIPT_MODE}" ]; then
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts print_info "run as SCRIPT_MODE"
echo "${ACTIONS_DEPLOY_KEY}" > /root/.ssh/id_rsa SSH_DIR="${HOME}/.ssh"
chmod 400 /root/.ssh/id_rsa else
SSH_DIR="/root/.ssh"
fi
mkdir "${SSH_DIR}"
ssh-keyscan -t rsa github.com > "${SSH_DIR}/known_hosts"
echo "${ACTIONS_DEPLOY_KEY}" > "${SSH_DIR}/id_rsa"
chmod 400 "${SSH_DIR}/id_rsa"
remote_repo="git@github.com:${GITHUB_REPOSITORY}.git" remote_repo="git@github.com:${PUBLISH_REPOSITORY}.git"
elif [ -n "${PERSONAL_TOKEN}" ]; then elif [ -n "${PERSONAL_TOKEN}" ]; then
print_info "setup with PERSONAL_TOKEN" print_info "setup with PERSONAL_TOKEN"
remote_repo="https://x-access-token:${PERSONAL_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" remote_repo="https://x-access-token:${PERSONAL_TOKEN}@github.com/${PUBLISH_REPOSITORY}.git"
elif [ -n "${GITHUB_TOKEN}" ]; then elif [ -n "${GITHUB_TOKEN}" ]; then
print_info "setup with GITHUB_TOKEN" print_info "setup with GITHUB_TOKEN"
print_error "GITHUB_TOKEN works only private repo, See #9"
remote_repo="https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" if [ -n "${EXTERNAL_REPOSITORY}" ]; then
print_error "can not use GITHUB_TOKEN to deploy to a external repository"
exit 1
fi
remote_repo="https://x-access-token:${GITHUB_TOKEN}@github.com/${PUBLISH_REPOSITORY}.git"
else else
print_error "not found ACTIONS_DEPLOY_KEY, PERSONAL_TOKEN, or GITHUB_TOKEN" print_error "not found ACTIONS_DEPLOY_KEY, PERSONAL_TOKEN, or GITHUB_TOKEN"
@@ -52,10 +76,16 @@ fi
remote_branch="${PUBLISH_BRANCH}" remote_branch="${PUBLISH_BRANCH}"
local_dir="${HOME}/$(tr -cd 'a-f0-9' < /dev/urandom | head -c 32)" local_dir="${HOME}/ghpages_${RANDOM}"
if git clone --depth=1 --single-branch --branch "${remote_branch}" "${remote_repo}" "${local_dir}"; then if git clone --depth=1 --single-branch --branch "${remote_branch}" "${remote_repo}" "${local_dir}"; then
cd "${local_dir}" cd "${local_dir}"
git rm -r '*'
if [[ ${INPUT_KEEPFILES} == "true" ]]; then
print_info "Keeping existing files: ${INPUT_KEEPFILES}"
else
git rm -r --ignore-unmatch '*'
fi
find "${GITHUB_WORKSPACE}/${PUBLISH_DIR}" -maxdepth 1 | \ find "${GITHUB_WORKSPACE}/${PUBLISH_DIR}" -maxdepth 1 | \
tail -n +2 | \ tail -n +2 | \
xargs -I % cp -rf % "${local_dir}/" xargs -I % cp -rf % "${local_dir}/"
@@ -74,12 +104,10 @@ git add --all
print_info "Allowing empty commits: ${INPUT_EMPTYCOMMITS}" print_info "Allowing empty commits: ${INPUT_EMPTYCOMMITS}"
COMMIT_MESSAGE="Automated deployment: $(date -u) ${GITHUB_SHA}" COMMIT_MESSAGE="Automated deployment: $(date -u) ${GITHUB_SHA}"
if [[ ${INPUT_EMPTYCOMMITS} == "true" ]]; then if [[ ${INPUT_EMPTYCOMMITS} == "false" ]]; then
git commit --allow-empty -m "${COMMIT_MESSAGE}" git commit -m "${COMMIT_MESSAGE}" || skip
else else
git commit -m "${COMMIT_MESSAGE}" || \ git commit --allow-empty -m "${COMMIT_MESSAGE}"
print_info "No changes detected, skipping deployment" && \
exit 0
fi fi
git push origin "${remote_branch}" git push origin "${remote_branch}"

BIN
images/default-branch.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
images/deploy-keys-1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

BIN
images/deploy-keys-2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
images/log1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
images/log2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
images/log3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

BIN
images/log4.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

BIN
images/secrets-1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

BIN
images/secrets-2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB