Skip to content

Commit ffa7509

Browse files
authored
Merge pull request #129 from rossjrw/enable-qr
Enable QR codes by default
2 parents 7eb2064 + 5b9cf5d commit ffa7509

File tree

6 files changed

+55
-38
lines changed

6 files changed

+55
-38
lines changed

.github/workflows/preview-example.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ jobs:
2020
uses: ./
2121
with:
2222
source-dir: test/fixtures/sample
23-
qr-code: true

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Features:
77
- Creates and deploys previews of pull requests to your GitHub Pages site
88
- 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
99
- 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+
- Includes a QR code in the preview comment for easy mobile access
1111
- Cleans up after itself — removes deployed previews when the pull request is closed
1212
- Can be configured to override any of these behaviours
1313

@@ -105,7 +105,7 @@ The following input parameters are provided, which can be passed to the `with` p
105105
| `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) |
106106
| `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) |
107107
| `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` |
108+
| `qr-code` <br> | Whether to include a QR code in the sticky comment for easy mobile access, which links to the preview URL. Only affects the default comment (i.e. if `comment` is not `false`). <br> Enabled by default - set to `false` to disable, or to a string to use a different provider ([see below](#use-a-different-qr-code-provider)). <br><br> Default: [`https://qr.rossjrw.com/?color.dark=0d1117&url=`](https://qr.rossjrw.com) |
109109
| `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. |
110110
| `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` |
111111

@@ -346,18 +346,6 @@ Set `wait-for-deployment: true` to make the action automatically wait for Pages
346346
wait-for-pages-deployment: true
347347
```
348348

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.:
354-
355-
```yml
356-
- uses: rossjrw/pr-preview-action@v1
357-
with:
358-
qr-code: https://my-qrcode-provider.example.com/generate?url=
359-
```
360-
361349
### Customise the sticky comment
362350

363351
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.
@@ -396,7 +384,7 @@ jobs:
396384
message: |
397385
[PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
398386
:---:
399-
| <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>
387+
| <p><img src="https://qr.rossjrw.com/?url=${{ steps.preview-step.outputs.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>
400388
| <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>
401389

402390
- uses: marocchino/sticky-pull-request-comment@v2
@@ -410,6 +398,20 @@ jobs:
410398
${{ steps.preview-step.outputs.action-start-time }}
411399
```
412400
401+
### Use a different QR code provider
402+
403+
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.
404+
405+
To use a different QR code provider (it's easy 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.:
406+
407+
```yml
408+
- uses: rossjrw/pr-preview-action@v1
409+
with:
410+
qr-code: https://my-qrcode-provider.example.com/generate?url=
411+
```
412+
413+
If using a customised comment with `comment: false`, simply construct the image URL from your chosen provider's URL and the preview URL (`${{ steps.[JOB ID].outputs.preview-url }}`).
414+
413415
# Acknowledgements
414416

415417
Big thanks to the following:

action.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ inputs:
6464
required: false
6565
default: "true"
6666
qr-code:
67-
description: Whether to display a QR code in the sticky comment.
67+
description: URL to a QR code provider to generate a QR code for the preview URL in the comment. Preview URL will be appended to the string. Or, set to "false" to disable QR code generation.
6868
required: false
69-
default: "false"
69+
default: "https://qr.rossjrw.com/?color.dark=0d1117&url="
7070
deploy-commit-message:
7171
description: The commit message to use when adding/updating a preview.
7272
required: false
@@ -147,7 +147,6 @@ runs:
147147
deployment_repository: ${{ inputs.deploy-repository }}
148148
token: ${{ inputs.token }}
149149
deprecated_custom_url: ${{ inputs.custom-url }}
150-
qr_code_wanted: ${{ inputs.qr-code }}
151150
run: $GITHUB_ACTION_PATH/lib/main.sh
152151
shell: bash
153152

@@ -203,7 +202,7 @@ runs:
203202
"${{ inputs.deploy-repository }}" \
204203
"${{ env.action_start_time }}" \
205204
"deploy" \
206-
"${{ env.qr_code_provider }}")
205+
"${{ inputs.qr-code }}")
207206
{
208207
echo "content<<EOF"
209208
echo "$CONTENT"

lib/generate-comment.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ action_start_time=${7:?missing action_start_time}
1313
deployment_action=${8:?missing deployment_action}
1414
qr_code_provider=${9:-} # falsy qr code provider means no QR code
1515

16+
if [ "$qr_code_provider" = "true" ]; then
17+
# Default to builtin provider
18+
qr_code_provider="https://qr.rossjrw.com/?color.dark=0d1117&url="
19+
fi
20+
if [ "$qr_code_provider" = "false" ]; then
21+
qr_code_provider=""
22+
else
23+
echo >&2 "Using QR code provider: $qr_code_provider<URL>"
24+
fi
25+
1626
if [ "$deployment_action" = "deploy" ]; then
1727
qr_code=""
1828
if [ -n "$qr_code_provider" ]; then

lib/main.sh

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ source "$GITHUB_ACTION_PATH/lib/calculate-pages-base-url.sh"
55
source "$GITHUB_ACTION_PATH/lib/remove-prefix-path.sh"
66
source "$GITHUB_ACTION_PATH/lib/determine-auto-action.sh"
77

8-
declare deployment_action pr_number deployment_repository pages_base_url pages_base_path umbrella_path action_repository action_ref deprecated_custom_url qr_code_wanted
8+
declare deployment_action pr_number deployment_repository pages_base_url pages_base_path umbrella_path action_repository action_ref deprecated_custom_url
99

1010
# Deprecation of custom-url in favour of pages-base-url
1111
if [ -z "$pages_base_url" ] && [ -n "$deprecated_custom_url" ]; then
@@ -35,17 +35,6 @@ action_version=$("$GITHUB_ACTION_PATH/lib/find-current-git-tag.sh" -p "$action_r
3535
action_start_timestamp=$(date '+%s')
3636
action_start_time=$(date '+%Y-%m-%d %H:%M %Z')
3737

38-
if [ "$qr_code_wanted" != "false" ]; then
39-
if [ "$qr_code_wanted" = "true" ]; then
40-
qr_code_provider="https://qr.rossjrw.com/?color.dark=0d1117&url="
41-
else
42-
qr_code_provider="$qr_code_wanted"
43-
fi
44-
echo >&2 "Using QR code provider: $qr_code_provider<URL>"
45-
else
46-
qr_code_provider=""
47-
fi
48-
4938
# Export variables for later use by this action
5039
{
5140
echo "empty_dir_path=$(mktemp -d)"
@@ -59,8 +48,6 @@ fi
5948
echo "action_repository=$action_repository"
6049
echo "action_version=$action_version"
6150
echo "action_start_time=$action_start_time"
62-
63-
echo "qr_code_provider=$qr_code_provider"
6451
} >> "$GITHUB_ENV"
6552

6653
# Export variables for use by later actions in user workflow

test/unit/test-comment-content.sh

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ assert_file_contains "$comment_file" "$action_version"
3636
assert_file_contains "$comment_file" "$preview_url"
3737
assert_file_contains "$comment_file" "Built to branch"
3838
assert_file_contains "$comment_file" "pr-12345"
39-
assert_file_contains "$comment_file" "qr.rossjrw.com" && exit 1 || true
39+
assert_file_contains "$comment_file" "/?url=" && exit 1 || true
4040

4141
echo >&2 "test comment: removal"
4242
echo >&2 "==============================="
@@ -57,11 +57,11 @@ echo >&2 "==============================="
5757
assert_file_contains "$comment_file" "PR Preview Action"
5858
assert_file_contains "$comment_file" "$action_version"
5959
assert_file_contains "$comment_file" "Preview removed"
60-
assert_file_contains "$comment_file" "qr.rossjrw.com" && exit 1 || true
60+
assert_file_contains "$comment_file" "/?url=" && exit 1 || true
6161

6262
echo >&2 "test comment: deployment with QR code"
6363
echo >&2 "==============================="
64-
qr_code_provider="https://qr.rossjrw.com/?url="
64+
qr_code_provider="https://qr.example.com/?url="
6565
bash lib/generate-comment.sh \
6666
"$action_repository" \
6767
"$action_version" \
@@ -77,4 +77,24 @@ qr_code_provider=""
7777
cat >&2 "$comment_file"
7878
echo >&2 "==============================="
7979

80-
assert_file_contains "$comment_file" "qr.rossjrw.com/?url=$preview_url"
80+
assert_file_contains "$comment_file" "qr.example.com/?url=$preview_url"
81+
82+
echo >&2 "test comment: deployment with QR code, backwards compatibility with qr-code:true"
83+
echo >&2 "==============================="
84+
qr_code_provider="true"
85+
bash lib/generate-comment.sh \
86+
"$action_repository" \
87+
"$action_version" \
88+
"$preview_url" \
89+
"$preview_branch" \
90+
"$server_url" \
91+
"$deployment_repository" \
92+
"$action_start_time" \
93+
"deploy" \
94+
"$qr_code_provider" \
95+
> "$comment_file"
96+
qr_code_provider=""
97+
cat >&2 "$comment_file"
98+
echo >&2 "==============================="
99+
100+
assert_file_contains "$comment_file" "qr.rossjrw.com"

0 commit comments

Comments
 (0)