Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: v2.5.0 script mode #38

Merged
merged 11 commits into from
Oct 6, 2019
2 changes: 2 additions & 0 deletions .github/workflows/docker-image-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
types: [opened, synchronize]
push:
branches:
- master

jobs:
test:
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The above example step will deploy `./public` directory to `gh-pages` branch.
- [⭐️ 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)
Expand Down Expand Up @@ -196,7 +197,7 @@ By pulling docker images, you can reduce the overall execution time of your work

### ⭐️ `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]

Expand Down Expand Up @@ -247,6 +248,7 @@ For example:

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:

Expand All @@ -265,6 +267,26 @@ When you use `ACTIONS_DEPLOY_KEY`, set your private key to the repository which

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>
Expand Down
18 changes: 12 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ 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:${PUBLISH_REPOSITORY}.git"

Expand All @@ -44,7 +50,7 @@ elif [ -n "${PERSONAL_TOKEN}" ]; then
elif [ -n "${GITHUB_TOKEN}" ]; then

print_info "setup with GITHUB_TOKEN"
print_error "Do not use GITHUB_TOKEN, See #9"
print_error "GITHUB_TOKEN works only private repo, See #9"

if [ -n "${EXTERNAL_REPOSITORY}" ]; then
print_error "can not use GITHUB_TOKEN to deploy to a external repository"
Expand All @@ -70,7 +76,7 @@ fi

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
cd "${local_dir}"

Expand Down