Skip to content

Commit 77afd3c

Browse files
committed
Merge branch 'master' into release/v2.5.0
2 parents 039d969 + 37e4747 commit 77afd3c

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The above example step will deploy `./public` directory to `gh-pages` branch.
4545
- [⭐️ `GITHUB_TOKEN`](#%EF%B8%8F-github_token)
4646
- [⭐️ Suppressing empty commits](#%EF%B8%8F-suppressing-empty-commits)
4747
- [⭐️ Keeping existing files](#%EF%B8%8F-keeping-existing-files)
48+
- [⭐️ Deploy to external repository](#%EF%B8%8F-deploy-to-external-repository)
4849
- [Tips and FAQ](#tips-and-faq)
4950
- [⭐️ Use the latest and specific release](#%EF%B8%8F-use-the-latest-and-specific-release)
5051
- [⭐️ How to add `CNAME`](#%EF%B8%8F-how-to-add-cname)
@@ -242,6 +243,28 @@ For example:
242243
keepFiles: true
243244
```
244245

246+
### ⭐️ Deploy to external repository
247+
248+
By default, your files are published to the repository which is running this action.
249+
If you want to publish to another repository on GitHub, set the environment variable `EXTERNAL_REPOSITORY` to `<username>/<external-repository>`.
250+
251+
For example:
252+
253+
```yaml
254+
- name: Deploy
255+
uses: peaceiris/[email protected]
256+
env:
257+
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
258+
EXTERNAL_REPOSITORY: username/username.github.io
259+
PUBLISH_BRANCH: master
260+
PUBLISH_DIR: ./public
261+
```
262+
263+
You can use `ACTIONS_DEPLOY_KEY` or `PERSONAL_TOKEN`.
264+
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.
265+
266+
Be careful, `GITHUB_TOKEN` has no permission to access to external repositories.
267+
245268
<div align="right">
246269
<a href="#table-of-contents">Back to TOC ☝️</a>
247270
</div>

entrypoint.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ function skip() {
1717
}
1818

1919
# check values
20+
if [ -n "${EXTERNAL_REPOSITORY}" ]; then
21+
PUBLISH_REPOSITORY=${EXTERNAL_REPOSITORY}
22+
else
23+
PUBLISH_REPOSITORY=${GITHUB_REPOSITORY}
24+
fi
25+
print_info "Deploy to ${PUBLISH_REPOSITORY}"
26+
2027
if [ -n "${ACTIONS_DEPLOY_KEY}" ]; then
2128

2229
print_info "setup with ACTIONS_DEPLOY_KEY"
@@ -26,20 +33,25 @@ if [ -n "${ACTIONS_DEPLOY_KEY}" ]; then
2633
echo "${ACTIONS_DEPLOY_KEY}" > "${HOME}/.ssh/id_rsa"
2734
chmod 400 "${HOME}/.ssh/id_rsa"
2835

29-
remote_repo="[email protected]:${GITHUB_REPOSITORY}.git"
36+
remote_repo="[email protected]:${PUBLISH_REPOSITORY}.git"
3037

3138
elif [ -n "${PERSONAL_TOKEN}" ]; then
3239

3340
print_info "setup with PERSONAL_TOKEN"
3441

35-
remote_repo="https://x-access-token:${PERSONAL_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
42+
remote_repo="https://x-access-token:${PERSONAL_TOKEN}@github.com/${PUBLISH_REPOSITORY}.git"
3643

3744
elif [ -n "${GITHUB_TOKEN}" ]; then
3845

3946
print_info "setup with GITHUB_TOKEN"
4047
print_error "GITHUB_TOKEN works only private repo, See #9"
4148

42-
remote_repo="https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
49+
if [ -n "${EXTERNAL_REPOSITORY}" ]; then
50+
print_error "can not use GITHUB_TOKEN to deploy to a external repository"
51+
exit 1
52+
fi
53+
54+
remote_repo="https://x-access-token:${GITHUB_TOKEN}@github.com/${PUBLISH_REPOSITORY}.git"
4355

4456
else
4557
print_error "not found ACTIONS_DEPLOY_KEY, PERSONAL_TOKEN, or GITHUB_TOKEN"

0 commit comments

Comments
 (0)