Skip to content

Commit 0223615

Browse files
authored
Merge pull request #38 from MH4GF/allow-specify-different-repository-to-deployment
feat: allow to specify a different repository to deploy to
2 parents 699c12b + 108d93b commit 0223615

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ the `with` parameter.
224224
Default: Will attempt to calculate the repository's GitHub Pages URL
225225
(e.g. "rossjrw.github.io").
226226

227+
- `deploy-repository`: The repository to deploy the preview to.
228+
229+
If this value is changed from the default, the `token` parameter must also
230+
be set (see below).
231+
232+
Default: The current repository that the pull request was made in.
233+
234+
- `token`: The token to use for the preview deployment. The default value is
235+
fine for most purposes, but if you want to deploy the preview to a different
236+
repository (see `deploy-repository` above), you will need to create a
237+
[Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
238+
with permission to access it.
239+
240+
Default: GITHUB_TOKEN, which gives the action permission to deploy to the
241+
current repository.
242+
227243
- **(Advanced)** `action`: Determines what this action will do when it is
228244
executed. Supported values: `deploy`, `remove`, `none`, `auto`.
229245

action.yml

+31-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ branding:
99
color: yellow
1010

1111
inputs:
12+
token:
13+
description: >
14+
The token to use for the deployment.
15+
Default is GITHUB_TOKEN in the current repository.
16+
If you need more permissions for things such as deploying to another
17+
repository, you can add a Personal Access Token (PAT).
18+
required: false
19+
default: ${{ github.token }}
1220
preview-branch:
1321
description: Branch on which the previews will be deployed.
1422
required: false
@@ -21,6 +29,18 @@ inputs:
2129
description: Directory containing files to deploy.
2230
required: false
2331
default: .
32+
deploy-repository:
33+
description: >
34+
The GitHub repository to deploy the preview to.
35+
This should be formatted like `<org name>/<repo name>`, e.g.
36+
`rossjrw/pr-preview-action`.
37+
Defaults to the current repository.
38+
39+
You will need to add a Personal Access Token (PAT) in the `token` input
40+
in order to allow the action running in one repository to make changes
41+
to another repository.
42+
required: false
43+
default: ${{ github.repository }}
2444
custom-url:
2545
description: Custom pages URL
2646
required: false
@@ -60,20 +80,22 @@ runs:
6080
actionref: ${{ github.action_ref }}
6181
actionrepo: ${{ github.action_repository }}
6282
customurl: ${{ inputs.custom-url }}
83+
deployrepo: ${{ inputs.deploy-repository }}
84+
token: ${{ inputs.token }}
6385
run: |
6486
echo "action=$action" >> $GITHUB_ENV
6587
echo "targetdir=$umbrella/pr-$pr" >> $GITHUB_ENV
6688
echo "pr=$pr" >> $GITHUB_ENV
6789
68-
org=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 1)
69-
thirdleveldomain=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2)
90+
org=$(echo "$deployrepo" | cut -d "/" -f 1)
91+
thirdleveldomain=$(echo "$deployrepo" | cut -d "/" -f 2)
7092
7193
if [ ! -z "$customurl" ]; then
7294
pagesurl="$customurl"
7395
elif [ "${org}.github.io" == "$thirdleveldomain" ]; then
7496
pagesurl="${org}.github.io"
7597
else
76-
pagesurl=$(echo "$GITHUB_REPOSITORY" | sed 's/\//.github.io\//')
98+
pagesurl=$(echo "$deployrepo" | sed 's/\//.github.io\//')
7799
fi
78100
79101
echo "pagesurl=$pagesurl" >> $GITHUB_ENV
@@ -83,6 +105,8 @@ runs:
83105
84106
echo "actionref=$actionref" >> $GITHUB_ENV
85107
echo "actionrepo=$actionrepo" >> $GITHUB_ENV
108+
echo "deployrepo=$deployrepo" >> $GITHUB_ENV
109+
echo "token=$token" >> $GITHUB_ENV
86110
shell: bash
87111

88112
- name: Determine action version
@@ -100,6 +124,8 @@ runs:
100124
if: env.action == 'deploy'
101125
uses: JamesIves/github-pages-deploy-action@v4
102126
with:
127+
token: ${{ env.token }}
128+
repository-name: ${{ env.deployrepo }}
103129
branch: ${{ inputs.preview-branch }}
104130
folder: ${{ inputs.source-dir }}
105131
target-folder: ${{ env.targetdir }}
@@ -136,6 +162,8 @@ runs:
136162
if: env.action == 'remove'
137163
uses: JamesIves/github-pages-deploy-action@v4
138164
with:
165+
token: ${{ env.token }}
166+
repository-name: ${{ env.deployrepo }}
139167
branch: ${{ inputs.preview-branch }}
140168
folder: ${{ env.emptydir }}
141169
target-folder: ${{ env.targetdir }}

0 commit comments

Comments
 (0)