Compare commits
30 Commits
v2.3.2-rc2
...
v2.6.0-rc0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6a9b4b75a | ||
|
|
69067de181 | ||
|
|
a0131c39a3 | ||
|
|
a899cb542b | ||
|
|
f83fbff9f3 | ||
|
|
7216888f95 | ||
|
|
7f7794a793 | ||
|
|
e60d374041 | ||
|
|
8191f265b1 | ||
|
|
4eb9565412 | ||
|
|
e5910bfc4f | ||
|
|
09158e35aa | ||
|
|
26405de510 | ||
|
|
855ba06744 | ||
|
|
159b07d518 | ||
|
|
37e4747275 | ||
|
|
ea833f5400 | ||
|
|
3ceceb921f | ||
|
|
9e74ae3f23 | ||
|
|
76490a48db | ||
|
|
c138367a6e | ||
|
|
3e2f32bb1e | ||
|
|
f54520fcda | ||
|
|
83bc08b934 | ||
|
|
380b190669 | ||
|
|
8eedda6921 | ||
|
|
13d694636e | ||
|
|
551961e807 | ||
|
|
3e09c28a79 | ||
|
|
8f168fea5a |
15
.github/workflows/docker-image-ci.yml
vendored
15
.github/workflows/docker-image-ci.yml
vendored
@@ -1,12 +1,11 @@
|
||||
name: docker image ci
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
push:
|
||||
paths:
|
||||
- '**'
|
||||
- '!LICENSE'
|
||||
- '!README.md'
|
||||
- '!images'
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
test:
|
||||
@@ -14,6 +13,8 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: build
|
||||
env:
|
||||
@@ -26,6 +27,8 @@ jobs:
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- name: shellcheck
|
||||
run: shellcheck ./entrypoint.sh
|
||||
|
||||
@@ -33,6 +36,8 @@ jobs:
|
||||
runs-on: macOS-10.14
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- name: hadolint
|
||||
run: |
|
||||
brew install hadolint
|
||||
|
||||
234
README.md
234
README.md
@@ -1,42 +1,62 @@
|
||||
[](https://github.com/peaceiris/actions-gh-pages/blob/master/LICENSE)
|
||||
[](https://github.com/peaceiris/actions-gh-pages/releases/latest)
|
||||
[](https://github.com/peaceiris/actions-gh-pages/releases)
|
||||
[](https://github.com/peaceiris/actions-gh-pages/actions)
|
||||

|
||||
[](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">
|
||||
|
||||
|
||||
|
||||
## 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/
|
||||
|
||||
```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 -->
|
||||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||
Table of Contents
|
||||
|
||||
|
||||
- [Getting started](#getting-started)
|
||||
- [(1) Add ssh deploy key](#1-add-ssh-deploy-key)
|
||||
- [(2) Create `.github/workflows/gh-pages.yml`](#2-create-githubworkflowsgh-pagesyml)
|
||||
- [(1) Add SSH deploy key](#1-add-ssh-deploy-key)
|
||||
- [(2) Create your workflow](#2-create-your-workflow)
|
||||
- [⭐️ Repository type - Project](#%EF%B8%8F-repository-type---project)
|
||||
- [⭐️ Repository type - User and Organization](#%EF%B8%8F-repository-type---user-and-organization)
|
||||
- [Options](#options)
|
||||
- [⭐️ Pull action image from Docker Hub](#%EF%B8%8F-pull-action-image-from-docker-hub)
|
||||
- [⭐️ `PERSONAL_TOKEN`](#%EF%B8%8F-personal_token)
|
||||
- [⭐️ `GITHUB_TOKEN`](#%EF%B8%8F-github_token)
|
||||
- [⭐️ Suppressing empty commits](#%EF%B8%8F-suppressing-empty-commits)
|
||||
- [Options](#options)
|
||||
- [⭐️ Pull action image from Docker Hub](#%EF%B8%8F-pull-action-image-from-docker-hub)
|
||||
- [⭐️ `PERSONAL_TOKEN`](#%EF%B8%8F-personal_token)
|
||||
- [⭐️ `GITHUB_TOKEN`](#%EF%B8%8F-github_token)
|
||||
- [⭐️ 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)
|
||||
- [How to add `CNAME`](#how-to-add-cname)
|
||||
- [Deployment completed but you cannot read](#deployment-completed-but-you-cannot-read)
|
||||
- [⭐️ 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)
|
||||
- [Static Site Generators with Node.js](#static-site-generators-with-nodejs)
|
||||
- [Gatsby](#gatsby)
|
||||
- [React and Next](#react-and-next)
|
||||
- [Vue and Nuxt](#vue-and-nuxt)
|
||||
- [Static Site Generators with Python](#static-site-generators-with-python)
|
||||
- [⭐️ Static Site Generators with Node.js](#%EF%B8%8F-static-site-generators-with-nodejs)
|
||||
- [⭐️ Gatsby](#%EF%B8%8F-gatsby)
|
||||
- [⭐️ React and Next](#%EF%B8%8F-react-and-next)
|
||||
- [⭐️ Vue and Nuxt](#%EF%B8%8F-vue-and-nuxt)
|
||||
- [⭐️ Static Site Generators with Python](#%EF%B8%8F-static-site-generators-with-python)
|
||||
- [License](#license)
|
||||
- [About the author](#about-the-author)
|
||||
|
||||
@@ -46,7 +66,7 @@ Table of Contents
|
||||
|
||||
## Getting started
|
||||
|
||||
### (1) Add ssh deploy key
|
||||
### (1) Add SSH deploy key
|
||||
|
||||
Generate your deploy key with the following command.
|
||||
|
||||
@@ -70,7 +90,9 @@ Next, Go to **Repository Settings**
|
||||
|---|---|
|
||||
|  |  |
|
||||
|
||||
### (2) Create `.github/workflows/gh-pages.yml`
|
||||
### (2) Create your workflow
|
||||
|
||||
Add your workflow setting YAML file `.github/workflows/gh-pages.yml` and push to the default branch.
|
||||
|
||||
#### ⭐️ Repository type - Project
|
||||
|
||||
@@ -96,17 +118,19 @@ jobs:
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
# with:
|
||||
# submodules: true
|
||||
|
||||
- name: Setup Hugo
|
||||
uses: peaceiris/actions-hugo@v2.2.0
|
||||
uses: peaceiris/actions-hugo@v2.2.2
|
||||
with:
|
||||
hugo-version: '0.58.2'
|
||||
hugo-version: '0.58.3'
|
||||
|
||||
- name: Build
|
||||
run: hugo --gc --minify --cleanDestinationDir
|
||||
run: hugo --gc --minify
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v2.3.1
|
||||
uses: peaceiris/actions-gh-pages@v2.5.0
|
||||
env:
|
||||
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||
PUBLISH_BRANCH: gh-pages
|
||||
@@ -142,21 +166,27 @@ PUBLISH_BRANCH: master # deploying branch
|
||||
|
||||

|
||||
|
||||
### Options
|
||||
<div align="right">
|
||||
<a href="#table-of-contents">Back to TOC ☝️</a>
|
||||
</div>
|
||||
|
||||
#### ⭐️ Pull action image from Docker Hub
|
||||
|
||||
|
||||
## Options
|
||||
|
||||
### ⭐️ Pull action 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.
|
||||
|
||||
```diff
|
||||
- uses: peaceiris/actions-gh-pages@v2.3.1
|
||||
+ uses: docker://peaceiris/gh-pages:v2.3.1
|
||||
- uses: peaceiris/actions-gh-pages@v2.5.0
|
||||
+ uses: docker://peaceiris/gh-pages:v2.5.0
|
||||
```
|
||||
|
||||
- [peaceiris/gh-pages - Docker Hub](https://hub.docker.com/r/peaceiris/gh-pages)
|
||||
|
||||
#### ⭐️ `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`.
|
||||
|
||||
@@ -165,9 +195,9 @@ By pulling docker images, you can reduce the overall execution time of your work
|
||||
+ PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
|
||||
```
|
||||
|
||||
#### ⭐️ `GITHUB_TOKEN`
|
||||
### ⭐️ `GITHUB_TOKEN`
|
||||
|
||||
> **NOTES**: Do not use `GITHUB_TOKEN`.
|
||||
> ⚠️ **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]
|
||||
|
||||
@@ -178,7 +208,7 @@ By pulling docker images, you can reduce the overall execution time of your work
|
||||
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
#### ⭐️ 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]
|
||||
|
||||
@@ -187,8 +217,8 @@ By default, a commit will always be generated and pushed to the `PUBLISH_BRANCH`
|
||||
For example:
|
||||
|
||||
```yaml
|
||||
- name: deploy
|
||||
uses: peaceiris/actions-gh-pages@v2.3.1
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v2.5.0
|
||||
env:
|
||||
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||
PUBLISH_BRANCH: gh-pages
|
||||
@@ -197,10 +227,82 @@ For example:
|
||||
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
|
||||
|
||||
### How to add `CNAME`
|
||||
### ⭐️ 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.
|
||||
|
||||
@@ -209,7 +311,18 @@ Most of the Static Site Generators support `CNAME` as a static file.
|
||||
|
||||
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.
|
||||
|
||||
### Deployment completed but you cannot read
|
||||
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.
|
||||
@@ -219,11 +332,26 @@ Please add `.nojekyll` file to `PUBLISH_DIR`.
|
||||
|
||||
> 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
|
||||
|
||||
### Static Site Generators with Node.js
|
||||
### ⭐️ Static Site Generators with Node.js
|
||||
|
||||
[hexo], [gitbook], [vuepress], [react-static], [gridsome], etc.
|
||||
|
||||
@@ -254,20 +382,20 @@ jobs:
|
||||
- name: build
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '10.16'
|
||||
node-version: '10.x'
|
||||
- run: |
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
- name: deploy
|
||||
uses: peaceiris/actions-gh-pages@v2.3.1
|
||||
uses: peaceiris/actions-gh-pages@v2.5.0
|
||||
env:
|
||||
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||
PUBLISH_BRANCH: gh-pages
|
||||
PUBLISH_DIR: ./public
|
||||
```
|
||||
|
||||
### Gatsby
|
||||
### ⭐️ Gatsby
|
||||
|
||||
An example for [Gatsby] (Gatsby.js) project with [gatsby-starter-blog]
|
||||
|
||||
@@ -293,7 +421,7 @@ jobs:
|
||||
- name: setup node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '10.16'
|
||||
node-version: '10.x'
|
||||
|
||||
- name: install
|
||||
run: npm install
|
||||
@@ -308,14 +436,14 @@ jobs:
|
||||
run: npm run build
|
||||
|
||||
- name: deploy
|
||||
uses: peaceiris/actions-gh-pages@v2.3.1
|
||||
uses: peaceiris/actions-gh-pages@v2.5.0
|
||||
env:
|
||||
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||
PUBLISH_BRANCH: gh-pages
|
||||
PUBLISH_DIR: ./public
|
||||
```
|
||||
|
||||
### React and Next
|
||||
### ⭐️ React and Next
|
||||
|
||||
An example for [Next.js] (React.js) project with [create-next-app]
|
||||
|
||||
@@ -343,7 +471,7 @@ jobs:
|
||||
- name: setup node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '10.16'
|
||||
node-version: '10.x'
|
||||
|
||||
- name: install
|
||||
run: yarn install
|
||||
@@ -358,14 +486,14 @@ jobs:
|
||||
run: touch ./out/.nojekyll
|
||||
|
||||
- name: deploy
|
||||
uses: peaceiris/actions-gh-pages@v2.3.1
|
||||
uses: peaceiris/actions-gh-pages@v2.5.0
|
||||
env:
|
||||
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||
PUBLISH_BRANCH: gh-pages
|
||||
PUBLISH_DIR: ./out
|
||||
```
|
||||
|
||||
### Vue and Nuxt
|
||||
### ⭐️ Vue and Nuxt
|
||||
|
||||
An example for [Nuxt.js] (Vue.js) project with [create-nuxt-app]
|
||||
|
||||
@@ -393,7 +521,7 @@ jobs:
|
||||
- name: setup node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '10.16'
|
||||
node-version: '10.x'
|
||||
|
||||
- name: install
|
||||
run: npm install
|
||||
@@ -405,14 +533,14 @@ jobs:
|
||||
run: npm run generate
|
||||
|
||||
- name: deploy
|
||||
uses: peaceiris/actions-gh-pages@v2.3.1
|
||||
uses: peaceiris/actions-gh-pages@v2.5.0
|
||||
env:
|
||||
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||
PUBLISH_BRANCH: gh-pages
|
||||
PUBLISH_DIR: ./dist
|
||||
```
|
||||
|
||||
### Static Site Generators with Python
|
||||
### ⭐️ Static Site Generators with Python
|
||||
|
||||
[pelican], [MkDocs], [sphinx], etc.
|
||||
|
||||
@@ -453,7 +581,7 @@ jobs:
|
||||
run: mkdocs build
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v2.3.1
|
||||
uses: peaceiris/actions-gh-pages@v2.5.0
|
||||
env:
|
||||
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
|
||||
PUBLISH_BRANCH: gh-pages
|
||||
@@ -473,3 +601,9 @@ jobs:
|
||||
## About the author
|
||||
|
||||
- [peaceiris's homepage](https://peaceiris.com/)
|
||||
|
||||
|
||||
|
||||
<div align="right">
|
||||
<a href="#table-of-contents">Back to TOC ☝️</a>
|
||||
</div>
|
||||
|
||||
10
action.yml
10
action.yml
@@ -1,5 +1,5 @@
|
||||
name: 'Deploy action for GitHub Pages'
|
||||
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'
|
||||
runs:
|
||||
using: 'docker'
|
||||
@@ -12,3 +12,11 @@ inputs:
|
||||
description: 'If empty commits should be made to the publication branch'
|
||||
required: false
|
||||
default: 'true'
|
||||
keepFiles:
|
||||
description: 'If existing files in the publish branch should be not removed before deploying'
|
||||
required: false
|
||||
default: 'false'
|
||||
forceOrphan:
|
||||
description: 'Keep only the latest commit on a GitHub Pages branch'
|
||||
required: false
|
||||
default: 'false'
|
||||
|
||||
@@ -11,29 +11,53 @@ function print_info() {
|
||||
echo -e "\e[36mINFO: ${1}\e[m"
|
||||
}
|
||||
|
||||
function skip() {
|
||||
print_info "No changes detected, skipping deployment"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# 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
|
||||
|
||||
print_info "setup with ACTIONS_DEPLOY_KEY"
|
||||
|
||||
mkdir /root/.ssh
|
||||
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
|
||||
echo "${ACTIONS_DEPLOY_KEY}" > /root/.ssh/id_rsa
|
||||
chmod 400 /root/.ssh/id_rsa
|
||||
if [ -n "${SCRIPT_MODE}" ]; then
|
||||
print_info "run as SCRIPT_MODE"
|
||||
SSH_DIR="${HOME}/.ssh"
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
print_error "not found ACTIONS_DEPLOY_KEY, PERSONAL_TOKEN, or GITHUB_TOKEN"
|
||||
@@ -52,10 +76,22 @@ fi
|
||||
|
||||
remote_branch="${PUBLISH_BRANCH}"
|
||||
|
||||
local_dir="${HOME}/$(tr -cd 'a-f0-9' < /dev/urandom | head -c 32)"
|
||||
if git clone --depth=1 --single-branch --branch "${remote_branch}" "${remote_repo}" "${local_dir}"; then
|
||||
local_dir="${HOME}/ghpages_${RANDOM}"
|
||||
|
||||
if [[ "${INPUT_FORCEORPHAN}" == "true" ]]; then
|
||||
print_info "force ophan: ${INPUT_FORCEORPHAN}"
|
||||
cd "${PUBLISH_DIR}"
|
||||
git init
|
||||
git checkout --orphan "${remote_branch}"
|
||||
elif git clone --depth=1 --single-branch --branch "${remote_branch}" "${remote_repo}" "${local_dir}"; then
|
||||
cd "${local_dir}"
|
||||
git rm -r --ignore-unmatch '*'
|
||||
|
||||
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 | \
|
||||
tail -n +2 | \
|
||||
xargs -I % cp -rf % "${local_dir}/"
|
||||
@@ -74,13 +110,16 @@ git add --all
|
||||
|
||||
print_info "Allowing empty commits: ${INPUT_EMPTYCOMMITS}"
|
||||
COMMIT_MESSAGE="Automated deployment: $(date -u) ${GITHUB_SHA}"
|
||||
if [[ ${INPUT_EMPTYCOMMITS} == "true" ]]; then
|
||||
git commit --allow-empty -m "${COMMIT_MESSAGE}"
|
||||
if [[ ${INPUT_EMPTYCOMMITS} == "false" ]]; then
|
||||
git commit -m "${COMMIT_MESSAGE}" || skip
|
||||
else
|
||||
git commit -m "${COMMIT_MESSAGE}" || \
|
||||
print_info "No changes detected, skipping deployment" && \
|
||||
exit 0
|
||||
git commit --allow-empty -m "${COMMIT_MESSAGE}"
|
||||
fi
|
||||
|
||||
if [[ ${INPUT_FORCEORPHAN} == "true" ]]; then
|
||||
git push origin --force "${remote_branch}"
|
||||
else
|
||||
git push origin "${remote_branch}"
|
||||
fi
|
||||
|
||||
git push origin "${remote_branch}"
|
||||
print_info "${GITHUB_SHA} was successfully deployed"
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
Reference in New Issue
Block a user