You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-6Lines changed: 37 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ Features:
7
7
- Creates and deploys previews of pull requests to your GitHub Pages site
8
8
- Leaves a comment on the pull request with a link to the preview so that you and your team can collaborate on new features faster
9
9
- Updates the deployment and the comment whenever new commits are pushed to the pull request
10
+
- Can optionally include a QR code in the preview comment for easy mobile access
10
11
- Cleans up after itself — removes deployed previews when the pull request is closed
11
12
- Can be configured to override any of these behaviours
12
13
@@ -21,13 +22,15 @@ Preview URLs look like this: `https://[owner].github.io/[repo]/pr-preview/pr-[nu
21
22
22
23
This Action does not currently support deploying previews for PRs from forks, but will do so in [the upcoming v2](https://github.com/rossjrw/pr-preview-action/pull/6).
23
24
24
-
# Usage
25
+
# Setup
25
26
26
27
A [GitHub Actions workflow](https://docs.github.com/en/actions/learn-github-actions) is required to use this Action.
27
28
28
-
All the workflow needs to do first is checkout the repository and build the Pages site.
29
+
You just need to do two things to set up your repository to support previews, both in the repository settings:
30
+
31
+
### 1. Deploy Pages from branch
29
32
30
-
First, ensure that your repository is configured to have its GitHub Pages site deployed from a branch, by setting the source for the deployment under **Settings** > **Pages** of your repository to **Deploy from branch**:
33
+
Ensure that your repository is configured to have its GitHub Pages site deployed from a branch, by setting the source for the deployment under **Settings** > **Pages** of your repository to **Deploy from branch**:
@@ -36,7 +39,16 @@ First, ensure that your repository is configured to have its GitHub Pages site d
36
39
Pictured: Repository Pages settings at /settings/page
37
40
</p>
38
41
39
-
The `gh-pages` branch is used for GitHub Pages deployments by convention, and will be used in examples here as well.
42
+
> [!IMPORTANT]
43
+
> The other option (called "GitHub Actions") has a [misleading name](https://github.com/orgs/community/discussions/30113#discussioncomment-7650234) and does not work with this action.
44
+
45
+
### 2. Let your workflow write to the repo
46
+
47
+
In **Settings** > **Actions** > **General** > **Workflow permissions**, select "Read and write permissions" to allow action runs to make changes to your deployment branch (in this case, to add and remove previews).
48
+
49
+
# Usage
50
+
51
+
All the workflow needs to do before running the preview action is checkout the repository and build the Pages site.
40
52
41
53
If your GitHub pages site is deployed from the `gh-pages` branch, built with e.g. an `npm` script to the `./build/` dir, and you're happy with the default settings, usage is very simple:
42
54
@@ -71,11 +83,16 @@ jobs:
71
83
uses: rossjrw/pr-preview-action@v1
72
84
with:
73
85
source-dir: ./build/
86
+
preview-branch: gh-pages
87
+
qr-code: true
74
88
```
75
89
90
+
> [!TIP]
91
+
> The `gh-pages` branch is used for GitHub Pages deployments by convention, and will be used in examples here as well, but you can use whatever branch you like (just make sure to change the `preview-branch` input).
92
+
76
93
## Inputs (configuration)
77
94
78
-
The following input parameters are provided, which can be passed to the `with` parameter. All parameters are optional and have a default value.
95
+
The following input parameters are provided, which can be passed to the `with` parameter. ALL parameters are optional and have a default value.
79
96
80
97
| Input parameter | Description |
81
98
| --- | --- |
@@ -88,6 +105,7 @@ The following input parameters are provided, which can be passed to the `with` p
88
105
| `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) |
89
106
| `wait-for-pages-deployment` <br> (boolean) | Whether to wait for the GitHub Pages deployment to complete. When enabled, the action will poll the GitHub Deployments API and delay workflow completion until the Pages deployment finishes, e.g. to ensure the preview URL is accessible when the comment is posted. <br><br> Default: `false`(this will be `true` in a future version of this Action) |
90
107
| `comment` <br> (boolean) | Whether to leave a [sticky comment](https://github.com/marocchino/sticky-pull-request-comment) on the PR after the preview is built.<br> The comment may be added before the preview finishes deploying unless `wait-for-pages-deployment` is enabled. <br><br> Default: `true`|
108
+
| `qr-code` <br> (booleanish) | Whether to include a QR code in the sticky comment for easy mobile access, which links to the preview URL. Does nothing if `comment` is `false`. <br> Set to `"true"`/`"false"` to enable/disable, or to a string to be used as a custom QR code provider ([see below](#use-a-different-qr-code-provider)). <br><br> Default: `false` |
91
109
| `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. |
92
110
| `action` <br> (enum) | 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` |
93
111
@@ -227,6 +245,7 @@ jobs:
227
245
action: auto
228
246
wait-for-pages-deployment: false
229
247
comment: true
248
+
qr-code: false
230
249
```
231
250
232
251
...and an accompanying main deployment workflow:
@@ -327,6 +346,18 @@ Set `wait-for-deployment: true` to make the action automatically wait for Pages
327
346
wait-for-pages-deployment: true
328
347
```
329
348
349
+
### Use a different QR code provider
350
+
351
+
If you have this action include a QR code in the sticky comment with `qr-code: true`, the default QR code provider is [qr.rossjrw.com](https://qr.rossjrw.com/), a provider that I built for this project because I don't trust any pre-existing ones. Likewise, you probably shouldn't trust mine - what if I go rogue and change all your QR codes to point to something else? You never know.
352
+
353
+
To use a different QR code provider (I encourage you to make your own - consider forking https://github.com/rossjrw/qrcode-worker), set `qr-code` to its URL. The URI-encoded preview link will be appended to it. E.g.:
You can use `id`, `with: comment: false`, the output values and [context variables](https://docs.github.com/en/actions/reference/workflows-and-actions/contexts) to construct your own comment to be left on the PR. This example recreates this Action's default comment (complete with HTML spacing jank), but you could change it however you like, use a different commenting Action from the marketplace, etc.
| <p><img src="https://qr.rossjrw.com/?url=${preview_url}" height="100" align="right" alt="QR code for preview link"></p> :rocket: View preview at <br> ${{ steps.preview-step.outputs.preview-url }} <br><br>
369
400
| <h6>Built to branch [`${{ env.PREVIEW_BRANCH }}`](${{ github.server_url }}/${{ github.repository }}/tree/${{ env.PREVIEW_BRANCH }}) at ${{ steps.preview-step.outputs.action-start-time }}. <br> Preview will be ready when the [GitHub Pages deployment](${{ github.server_url }}/${{ github.repository }}/deployments) is complete. <br><br> </h6>
Copy file name to clipboardExpand all lines: action.yml
+16-4Lines changed: 16 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ inputs:
13
13
description: >
14
14
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).
15
15
16
+
16
17
required: false
17
18
default: ${{ github.token }}
18
19
preview-branch:
@@ -39,6 +40,7 @@ inputs:
39
40
description: >
40
41
The PR number to use for the preview path. Defaults to the PR number from the GitHub event context. Override this for testing or when not triggered by a pull_request event.
41
42
43
+
42
44
required: false
43
45
default: ""
44
46
deploy-repository:
@@ -47,18 +49,24 @@ inputs:
47
49
48
50
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.
49
51
52
+
50
53
required: false
51
54
default: ${{ github.repository }}
52
55
wait-for-pages-deployment:
53
56
description: >
54
57
Whether to wait for GitHub Pages deployment before continuing, e.g. to ensure the preview URL is actually accessible when the sticky comment is posted.
55
58
59
+
56
60
required: false
57
61
default: "false"
58
62
comment:
59
63
description: Whether to leave a sticky comment on the calling PR at the end of the workflow.
60
64
required: false
61
65
default: "true"
66
+
qr-code:
67
+
description: Whether to display a QR code in the sticky comment.
68
+
required: false
69
+
default: "false"
62
70
deploy-commit-message:
63
71
description: The commit message to use when adding/updating a preview.
64
72
required: false
@@ -89,6 +97,7 @@ inputs:
89
97
90
98
If set to `auto`, the action will try to determine whether to deploy or remove the preview. It will deploy the preview on `pull_request.types.synchronize` and `.opened` events, and remove it on `pull_request.types.closed` events. It will not do anything for all other events. `auto` is the default value.
| <p></p> :rocket: View preview at <br> ${preview_url} <br><br>
25
+
| <p>$qr_code</p> :rocket: View preview at <br> ${preview_url} <br><br>
21
26
| <h6>Built to branch [\`${preview_branch}\`](${server_url}/${deploy_repository}/tree/${preview_branch}) at ${action_start_time}. <br> Preview will be ready when the [GitHub Pages deployment](${server_url}/${deploy_repository}/deployments) is complete. <br><br> </h6>
0 commit comments