Skip to content

Commit

Permalink
Merge pull request #38 from MH4GF/allow-specify-different-repository-…
Browse files Browse the repository at this point in the history
…to-deployment

feat: allow to specify a different repository to deploy to
  • Loading branch information
rossjrw authored Apr 23, 2023
2 parents 699c12b + 108d93b commit 0223615
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ the `with` parameter.
Default: Will attempt to calculate the repository's GitHub Pages URL
(e.g. "rossjrw.github.io").

- `deploy-repository`: The repository to deploy the preview to.

If this value is changed from the default, the `token` parameter must also
be set (see below).

Default: The current repository that the pull request was made in.

- `token`: The token to use for the preview deployment. The default value is
fine for most purposes, but if you want to deploy the preview to a different
repository (see `deploy-repository` above), you will need to create a
[Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
with permission to access it.

Default: GITHUB_TOKEN, which gives the action permission to deploy to the
current repository.

- **(Advanced)** `action`: Determines what this action will do when it is
executed. Supported values: `deploy`, `remove`, `none`, `auto`.

Expand Down
34 changes: 31 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ branding:
color: yellow

inputs:
token:
description: >
The token to use for the deployment.
Default is GITHUB_TOKEN in the current repository.
If you need more permissions for things such as deploying to another
repository, you can add a Personal Access Token (PAT).
required: false
default: ${{ github.token }}
preview-branch:
description: Branch on which the previews will be deployed.
required: false
Expand All @@ -21,6 +29,18 @@ inputs:
description: Directory containing files to deploy.
required: false
default: .
deploy-repository:
description: >
The GitHub repository to deploy the preview to.
This should be formatted like `<org name>/<repo name>`, e.g.
`rossjrw/pr-preview-action`.
Defaults to the current repository.
You will need to add a Personal Access Token (PAT) in the `token` input
in order to allow the action running in one repository to make changes
to another repository.
required: false
default: ${{ github.repository }}
custom-url:
description: Custom pages URL
required: false
Expand Down Expand Up @@ -60,20 +80,22 @@ runs:
actionref: ${{ github.action_ref }}
actionrepo: ${{ github.action_repository }}
customurl: ${{ inputs.custom-url }}
deployrepo: ${{ inputs.deploy-repository }}
token: ${{ inputs.token }}
run: |
echo "action=$action" >> $GITHUB_ENV
echo "targetdir=$umbrella/pr-$pr" >> $GITHUB_ENV
echo "pr=$pr" >> $GITHUB_ENV
org=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 1)
thirdleveldomain=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2)
org=$(echo "$deployrepo" | cut -d "/" -f 1)
thirdleveldomain=$(echo "$deployrepo" | cut -d "/" -f 2)
if [ ! -z "$customurl" ]; then
pagesurl="$customurl"
elif [ "${org}.github.io" == "$thirdleveldomain" ]; then
pagesurl="${org}.github.io"
else
pagesurl=$(echo "$GITHUB_REPOSITORY" | sed 's/\//.github.io\//')
pagesurl=$(echo "$deployrepo" | sed 's/\//.github.io\//')
fi
echo "pagesurl=$pagesurl" >> $GITHUB_ENV
Expand All @@ -83,6 +105,8 @@ runs:
echo "actionref=$actionref" >> $GITHUB_ENV
echo "actionrepo=$actionrepo" >> $GITHUB_ENV
echo "deployrepo=$deployrepo" >> $GITHUB_ENV
echo "token=$token" >> $GITHUB_ENV
shell: bash

- name: Determine action version
Expand All @@ -100,6 +124,8 @@ runs:
if: env.action == 'deploy'
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ env.token }}
repository-name: ${{ env.deployrepo }}
branch: ${{ inputs.preview-branch }}
folder: ${{ inputs.source-dir }}
target-folder: ${{ env.targetdir }}
Expand Down Expand Up @@ -136,6 +162,8 @@ runs:
if: env.action == 'remove'
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ env.token }}
repository-name: ${{ env.deployrepo }}
branch: ${{ inputs.preview-branch }}
folder: ${{ env.emptydir }}
target-folder: ${{ env.targetdir }}
Expand Down

0 comments on commit 0223615

Please sign in to comment.