Compare commits

...

8 Commits

Author SHA1 Message Date
peaceiris
2485261a06 docs: enhance explanation for EXTERNAL_REPOSITORY 2019-09-27 15:21:17 +09:00
peaceiris
954d420fb6 enhance: error handling EXTERNAL_REPOSITORY with GITHUB_TOKEN 2019-09-27 14:52:07 +09:00
peaceiris
34d447917a update: Table of Contents 2019-09-27 14:47:00 +09:00
peaceiris
aee95e5b5e rename: PUBLISH_REPOSITORY to EXTERNAL_REPOSITORY 2019-09-27 14:45:47 +09:00
peaceiris
6ea8776db8 rename: PUBLISH_REPO to PUBLISH_REPOSITORY 2019-09-27 14:41:01 +09:00
skyfrk
60eb903bb7 fix: add missing exit 1 statement 2019-09-27 13:04:02 +08:00
skyfrk
da0488f27e docs: add section about PUBLISH_REPO 2019-09-27 12:57:00 +08:00
skyfrk
fd120a1d22 feat: add PUBLISH_REPO option 2019-09-27 12:41:31 +08:00
2 changed files with 36 additions and 3 deletions

View File

@ -29,6 +29,7 @@ Table of Contents
- [⭐️ `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)
- [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)
@ -217,6 +218,26 @@ For example:
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>`.
For example:
```yaml
- name: Deploy
uses: peaceiris/actions-gh-pages@v2.4.0
env:
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
EXTERNAL_REPOSITORY: username/username.github.io
PUBLISH_BRANCH: master
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.
## Tips and FAQ

View File

@ -17,6 +17,13 @@ function skip() {
}
# 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"
@ -26,20 +33,25 @@ if [ -n "${ACTIONS_DEPLOY_KEY}" ]; then
echo "${ACTIONS_DEPLOY_KEY}" > /root/.ssh/id_rsa
chmod 400 /root/.ssh/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 "Do not use GITHUB_TOKEN, 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"