Skip to content

Commit

Permalink
Deprecate custom-url in favour of pages-base-url
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjrw committed Jan 9, 2025
1 parent d23d07a commit 3fc0990
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ Input parameter | Description
`deploy-repository` | The repository to deploy the preview to. <br> __Note:__ The `token` parameter must also be set if changing this from the default. <br><br> Default: The pull request's target repository.
`preview-branch` | Branch to save previews to. This should be the same branch that your GitHub Pages site is deployed from. <br><br> Default: `gh-pages`
`umbrella-dir` | Path to the directory to place previews in. <br> The umbrella directory is used to namespace previews from your main branch's deployment on GitHub Pages. <br><br> Default: `pr-preview`
`custom-url` | Base URL to use when providing a link to the preview site. <br><br> Default: The pull request's target repository's default GitHub Pages URL (e.g. `rossjrw.github.io/pr-preview-action/`)
`pages-base-path` | Path that GitHub Pages is being served from, as configured in your repository settings, e.g. `docs/`. When generating the preview URL, this is removed from the beginning of the path. <br><br> Default: `.` (repository root)
`pages-base-url` | Base URL to use when providing a link to the preview site. <br><br> Default: The pull request's target repository's default GitHub Pages URL (e.g. `rossjrw.github.io/pr-preview-action/`)
`pages-base-path` | Path that GitHub Pages is being served from, as configured in your repository settings, e.g. `docs/`. When generating the preview URL path, this is removed from the beginning of the file path. <br><br> Default: `.` (repository root)
`token` | Authentication token for the preview deployment. <br> The default value works for non-fork pull requests to the same repository. For anything else, you will need 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, and [store it as a secret](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) in your repository. E.g. you might name that secret 'PREVIEW_TOKEN' and use it with `token: ${{ secrets.PREVIEW_TOKEN }}`. <br><br> Default: `${{ github.token }}`, which gives the action permission to deploy to the current repository.
`action` <br> (Advanced) | Determines what this action will do when it is executed. Supported values: <br><br> <ul><li>`deploy` - create and deploy the preview, overwriting any existing preview in that location.</li><li>`remove` - remove the preview.</li><li>`auto` - determine whether to deploy or remove the preview based on [the emitted event](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request). If the event is `pull_request`, it will deploy the preview when the event type is `opened`, `reopened` and `synchronize`, and remove it on `closed` events. Does not do anything for other events or event types, even if you explicitly instruct the workflow to run on them.</li><li>`none` and all other values: does not do anything.</li></ul> Default: `auto`

Expand Down
11 changes: 9 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ inputs:
description: Path to the directory containing all previews.
required: false
default: pr-preview
pages-base-url:
description: URL of the repo's GitHub Pages site.
required: false
default: ""
pages-base-path:
description: Path that GitHub Pages is served from.
required: false
Expand All @@ -45,8 +49,10 @@ inputs:
to another repository.
required: false
default: ${{ github.repository }}

custom-url:
description: Custom pages URL
description: Deprecated, use `pages-base-url` instead.
deprecationMessage: Use `pages-base-url` instead.
required: false
default: ""
action:
Expand Down Expand Up @@ -103,13 +109,14 @@ runs:
env:
deployment_action: ${{ inputs.action }}
umbrella_path: ${{ inputs.umbrella-dir }}
pages_base_url: ${{ inputs.pages-base-url }}
pages_base_path: ${{ inputs.pages-base-path }}
pr_number: ${{ github.event.number }}
github_action_ref: ${{ github.action_ref }}
github_action_repository: ${{ github.action_repository }}
custom_pages_base_url: ${{ inputs.custom-url }}
deployment_repository: ${{ inputs.deploy-repository }}
token: ${{ inputs.token }}
deprecated_custom_url: ${{ inputs.custom-url }}
run: $GITHUB_ACTION_PATH/lib/main.sh
shell: bash

Expand Down
24 changes: 15 additions & 9 deletions lib/main.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#!/usr/bin/env bash

declare deployment_action pr_number deployment_repository custom_pages_base_url pages_base_path umbrella_path github_action_ref github_action_repository
declare deployment_action pr_number deployment_repository pages_base_url pages_base_path umbrella_path github_action_ref github_action_repository deprecated_custom_url

repo_org=$(echo "$deployment_repository" | cut -d "/" -f 1)
repo_name=$(echo "$deployment_repository" | cut -d "/" -f 2)
# Deprecation of custom-url in favour of pages-base-url
if [ -z "$pages_base_url" ] && [ -n "$deprecated_custom_url" ]; then
pages_base_url=$deprecated_custom_url
fi

if [ -n "$custom_pages_base_url" ]; then
pages_base_url="$custom_pages_base_url"
elif [ "$repo_name" = "${repo_org}.github.io" ]; then
pages_base_url="${repo_org}.github.io"
else
pages_base_url=$(echo "$deployment_repository" | sed 's/\//.github.io\//')
# If pages_base_url was not set by the user, try to guess
if [ -z "$pages_base_url" ]; then
# Either .github.io or .github.io/repo
repo_org=$(echo "$deployment_repository" | cut -d "/" -f 1)
repo_name=$(echo "$deployment_repository" | cut -d "/" -f 2)
if [ "$repo_name" = "${repo_org}.github.io" ]; then
pages_base_url="${repo_org}.github.io"
else
pages_base_url=$(echo "$deployment_repository" | sed -e 's/\//.github.io\//')
fi
fi

preview_file_path="$umbrella_path/pr-$pr_number"
Expand Down

0 comments on commit 3fc0990

Please sign in to comment.