Skip to content

Commit

Permalink
Merge pull request #165 from aaimio/dev
Browse files Browse the repository at this point in the history
feat: support TS + new vercel comment format
  • Loading branch information
aaimio authored Jan 18, 2023
2 parents 687f235 + f48f15c commit 9f367f7
Show file tree
Hide file tree
Showing 24 changed files with 7,234 additions and 3,535 deletions.
68 changes: 34 additions & 34 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "21:00"
open-pull-requests-limit: 10
ignore:
- dependency-name: "@octokit/action"
versions:
- 3.2.3
- 3.2.6
- 3.3.1
- 3.3.2
- 3.4.0
- 3.4.1
- 3.7.1
- 3.7.3
- 3.8.0
- dependency-name: "@actions/core"
versions:
- 1.2.7
- dependency-name: husky
versions:
- 4.3.8
- 5.0.9
- 5.1.1
- 5.2.0
- 6.0.0
- dependency-name: ws
versions:
- 7.4.2
- dependency-name: lint-staged
versions:
- 10.5.3
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "21:00"
open-pull-requests-limit: 10
ignore:
- dependency-name: "@octokit/action"
versions:
- 3.2.3
- 3.2.6
- 3.3.1
- 3.3.2
- 3.4.0
- 3.4.1
- 3.7.1
- 3.7.3
- 3.8.0
- dependency-name: "@actions/core"
versions:
- 1.2.7
- dependency-name: husky
versions:
- 4.3.8
- 5.0.9
- 5.1.1
- 5.2.0
- 6.0.0
- dependency-name: ws
versions:
- 7.4.2
- dependency-name: lint-staged
versions:
- 10.5.3
6 changes: 3 additions & 3 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
name: Capture Vercel preview URL
runs-on: "ubuntu-latest"
steps:
- uses: aaimio/vercel-preview-url-action@master
- uses: aaimio/vercel-preview-url-action@v2.0.0
id: vercel_preview_url
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Below is merely an example of what you could do with the preview URL.
# The preview URL is accessed through ${{ steps.<step_id>.vercel_preview_url }}
# The preview URL is accessed through ${{ steps.<step_id>.outputs.vercel_preview_url }}
- uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.createComment({
issue_number: context.issue.number,
Expand Down
2 changes: 1 addition & 1 deletion FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github: [aaimio]
github: [aaimio]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Aaron Imming
Copyright (c) 2021-2023 Aaron Imming

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
51 changes: 32 additions & 19 deletions README.MD → README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
# Overview

Capture a Vercel preview URL and feed it into your next GitHub action.
**Capture a Vercel preview URL and feed it into your next GitHub action.**

1. This action should run whenever an edit is made to a pull request comment (see [example](https://github.com/aaimio/vercel-preview-url-action#example) below).
- If you wish to capture the preview URL on `push` or `pull_request` check out [zentered/vercel-preview-url](https://github.com/zentered/vercel-preview-url)
2. It checks whether the editor of the comment is Vercel's bot account on GitHub.
3. It attempts to extract the preview URL from the comment and sets it as the action's output so that you can feed it into your next action.
![Vercel preview URL comment (new)](./docs/vercel-preview-url-new.png)
![Vercel preview URL comment (old)](./docs/vercel-preview-url-old.png)

Please note:
1. Runs when an edit is made to a pull request comment (see
[example](https://github.com/aaimio/vercel-preview-url-action#example)
below).
- Wish to capture the preview URL on `push` or `pull_request`? Check out
[zentered/vercel-preview-url](https://github.com/zentered/vercel-preview-url)
2. Checks whether the editor of the comment is Vercel's bot account on GitHub.
3. Attempts to extract the preview URL from the comment and sets it as the
action's output so you can forward it your next action.

- This action only succeeds when a preview URL was found, it gets cancelled (if `GITHUB_TOKEN` is passed) or fails on every other event.
- This action will keep executing for every edit (if following `issue_comment.edited` trigger as per `example.yml`). When a new commit is pushed, Vercel may edit the comment again, triggering this action. Please ensure you're building in logic into your next action to handle this.
**Notes**

- This action only succeeds when a preview URL was found, it either gets
cancelled if `GITHUB_TOKEN` is passed or fails if the token is not passed.
- This action keeps executing for every edit (if following
`issue_comment.edited` trigger). When a new commit is pushed, Vercel may edit
the comment again, triggering this action. Ensure you're building in logic
into your next action to handle this.

## Inputs

| Name | Description |
|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `cancel_on_strings` | Cancel the action when any of these (comma separated) strings appear in the edited comment. |
| `GITHUB_TOKEN` | Pass this (as `${{secrets.GITHUB_TOKEN}}`) to cancel actions instead of failing them. |
| `preview_url_regexp` | Regular expression pattern (without delimiters) to capture the preview URL. Ensure first capture group captures the preview URL. (default: `Preview: \[(.*)\]`) |
| `vercel_bot_name` | The name of the Vercel account commenting on pull requests. (default: `vercel[bot]`) |
| Name | Description |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `cancel_on_strings` | Cancel the action when any of these (comma separated) strings appear in the edited comment. |
| `GITHUB_TOKEN` | Pass this (as `${{secrets.GITHUB_TOKEN}}`) to cancel actions instead of failing them. |
| `preview_url_regexp` | Regular expression pattern (without delimiters!) to capture the preview URL. Ensure one of the capture groups captures the preview URL. |
| `vercel_bot_name` | The name of the Vercel account commenting on pull requests. (default: `vercel[bot]`) |

## Outputs

| Name | Description |
|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `vercel_preview_url` | The preview URL which can be accessed through the [`steps` context](https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#steps-context). |

## Example

The example below captures the Vercel preview URL and comments with it on the pull request.
The example below captures the Vercel preview URL and comments with it on the
pull request.

```YML
name: Capture Vercel preview URL
Expand All @@ -43,11 +55,11 @@ jobs:
name: Capture Vercel preview URL
runs-on: "ubuntu-latest"
steps:
- uses: aaimio/vercel-preview-url-action@v1
- uses: aaimio/vercel-preview-url-action@v2.0.0
id: vercel_preview_url
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Below is merely an example of what you could do with the preview URL.
# Below is but an example of what you could do with the preview URL.
# The preview URL is accessed through ${{ steps.<step_id>.outputs.vercel_preview_url }}
- uses: actions/github-script@v3
with:
Expand All @@ -63,4 +75,5 @@ jobs:
## Example use cases
- **Automated Lighthouse metrics to your PR with Vercel and GitHub Actions**: [OskarAhl/Lighthouse-github-action-comment](https://github.com/OskarAhl/Lighthouse-github-action-comment)
- [Automated Lighthouse metrics to your PR with Vercel and GitHub
Actions](https://github.com/OskarAhl/Lighthouse-github-action-comment)
32 changes: 18 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
name: "Capture Vercel Preview URL"
author: "Aaron Imming <aaim@protonmail.com>"
description: "Capture a Vercel preview URL and feed it into your next GitHub action."
name: Capture Vercel Preview URL
author: Aaron Imming <aaim@protonmail.com>
description: Capture a Vercel preview URL and feed it into your next GitHub action.
branding:
icon: "triangle"
color: "black"
icon: triangle
color: gray-dark
inputs:
cancel_on_strings:
description: "Cancel the action when comment contains these words (comma separated list)"
description: Cancel the action when comment contains these words (comma separated list)
required: false
default: "Deployment in progress,Preview: Failed"
default: "Deployment in progress,Preview: Failed,In Progress"
GITHUB_TOKEN:
description: "GitHub actions token to cancel the action in case preview URL could not be found. If not specified, the action will explicitly fail."
description: >-
GitHub actions token to cancel the action in case preview URL could not be
found. If not specified, the action will explicitly fail.
required: false
default: ""
preview_url_regexp:
description: "Regular expression pattern to capture the preview URL. Ensure first capture group captures the preview URL."
description: >-
Regular expression pattern to capture the preview URL. Ensure one of the
capture groups captures the preview URL.
required: false
default: 'Preview: \[(.*)\]' # Do use single quotes, do NOT use delimiters.
default: '(?:Preview: \[?(.*)\]?|\[Visit Preview\]\(([^\s]*)\))'
vercel_bot_name:
description: "The name of the Vercel account commenting on pull requests."
description: The name of the Vercel account commenting on pull requests.
required: false
default: "vercel[bot]"
outputs:
vercel_preview_url:
description: "The preview URL for the pull request's Vercel deployment."
description: The preview URL for the pull request's Vercel deployment.
runs:
using: "node12"
main: "dist/index.js"
using: node16
main: dist/index.js
Loading

1 comment on commit 9f367f7

@vercel
Copy link

@vercel vercel bot commented on 9f367f7 Jan 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.