Skip to content

Commit

Permalink
feat: deploy to other repo (#36)
Browse files Browse the repository at this point in the history
* feat: Add EXTERNAL_REPOSITORY option
* docs: Add section about EXTERNAL_REPOSITORY
  • Loading branch information
Simon Eßlinger authored and peaceiris committed Oct 6, 2019
1 parent ea833f5 commit 37e4747
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The above example step will deploy `./public` directory to `gh-pages` branch.
- [⭐️ `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)
- [⭐️ 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 @@ -242,6 +243,28 @@ 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.

<div align="right">
<a href="#table-of-contents">Back to TOC ☝️</a>
</div>
Expand Down
18 changes: 15 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 37e4747

Please sign in to comment.