Skip to content

Commit c0ba8ae

Browse files
committed
Add comment customisation example
1 parent df655a9 commit c0ba8ae

File tree

1 file changed

+59
-7
lines changed

1 file changed

+59
-7
lines changed

README.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ concurrency: preview-${{ github.ref }}
7272

7373
jobs:
7474
deploy-preview:
75-
runs-on: ubuntu-20.04
75+
runs-on: ubuntu-latest
7676
steps:
7777
- name: Checkout
78-
uses: actions/checkout@v3
78+
uses: actions/checkout@v4
7979

8080
- name: Install and Build
8181
if: github.event.action != 'closed' # You might want to skip the build if the PR has been closed
@@ -128,7 +128,7 @@ Output | Description
128128
`pages-base-url` | What this Action thinks the base URL of the GitHub Pages site is.
129129
`preview-url-path` | Path to the preview from the Pages base URL.
130130
`preview-url` | Full URL to the preview (`https://<pages-base-url>/<preview-url-path>/`).
131-
`action-version` | The version of this Action when it was run.
131+
`action-version` | The full, exact version of this Action when it was run.
132132
`action-start-timestamp` | The time that the workflow step started as a Unix timestamp.
133133
`action-start-time` | The time that the workflow step started in a readable format (UTC, depending on runner).
134134

@@ -251,7 +251,7 @@ jobs:
251251
deploy-preview:
252252
runs-on: ubuntu-latest
253253
steps:
254-
- uses: actions/checkout@v3
254+
- uses: actions/checkout@v4
255255
- run: npm i && npm run build
256256
if: github.event.action != 'closed'
257257
- uses: rossjrw/pr-preview-action@v1
@@ -275,7 +275,7 @@ jobs:
275275
deploy:
276276
runs-on: ubuntu-latest
277277
steps:
278-
- uses: actions/checkout@v3
278+
- uses: actions/checkout@v4
279279
- run: npm i && npm run build
280280
- uses: JamesIves/github-pages-deploy-action@v4
281281
with:
@@ -344,16 +344,68 @@ on:
344344
- synchronize
345345
jobs:
346346
deploy-preview:
347-
runs-on: ubuntu-20.04
347+
runs-on: ubuntu-latest
348348
steps:
349-
- uses: actions/checkout@v3
349+
- uses: actions/checkout@v4
350350
- run: npm i && npm run build
351351
- uses: rossjrw/pr-preview-action@v1
352352
with:
353353
source-dir: ./build/
354354
action: deploy
355355
```
356356

357+
### Customise the sticky comment
358+
359+
You can use `id`, `with: comment: false`, the output values and [context variables](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs) 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.
360+
361+
```yml
362+
# .github/workflows/preview.yml
363+
name: Deploy PR preview
364+
concurrency: preview-${{ github.ref }}
365+
on:
366+
pull_request:
367+
types:
368+
- opened
369+
- reopened
370+
- synchronize
371+
- closed
372+
env:
373+
PREVIEW_BRANCH: gh-pages
374+
jobs:
375+
deploy-preview:
376+
runs-on: ubuntu-latest
377+
steps:
378+
- uses: actions/checkout@v4
379+
- run: npm i && npm run build
380+
381+
- uses: rossjrw/pr-preview-action@v1
382+
id: preview-step
383+
with:
384+
source-dir: ./build/
385+
preview-branch: ${{ env.PREVIEW_BRANCH }}
386+
comment: false
387+
388+
- uses: marocchino/sticky-pull-request-comment@v2
389+
if: steps.preview-step.outputs.deployment_action == 'deploy' && env.deployment_status == 'success'
390+
with:
391+
header: pr-preview
392+
message: |
393+
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
394+
:---:
395+
| <p></p> :rocket: View preview at <br> ${{ steps.preview-step.outputs.preview-url }} <br><br>
396+
| <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>
397+
398+
- uses: marocchino/sticky-pull-request-comment@v2
399+
if: steps.preview-step.outputs.deployment_action == 'remove' && env.deployment_status == 'success'
400+
with:
401+
header: pr-preview
402+
message: |
403+
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
404+
:---:
405+
Preview removed because the pull request was closed.
406+
${{ steps.preview-step.outputs.action-start-time }}
407+
```
408+
357409
# Acknowledgements
358410
359411
Big thanks to the following:

0 commit comments

Comments
 (0)