-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6ebbb3e
Showing
10 changed files
with
1,841 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Capture Vercel preview URL | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
types: [opened] | ||
issue_comment: | ||
types: [edited] | ||
|
||
jobs: | ||
capture_vercel_preview_url: | ||
name: Capture Vercel preview URL | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- uses: aaron-binary/vercel-preview-url-action@master | ||
id: vercel_preview_url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Overview | ||
|
||
Capture a Vercel preview URL and feed it into your next GitHub action. | ||
|
||
1. This action runs whenever an edit is made to a pull request comment (see `example.yml` below). | ||
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. | ||
|
||
Please note that the action only succeeds when a preview URL was found, it fails on every other event (each edit made on a pull request comment will run this action). | ||
|
||
## Inputs | ||
|
||
- `vercel_bot_name`: The name of the Vercel account commenting on pull requests. (default: `vercel[bot]`) | ||
- `preview_url_regexp`: Regular expression pattern (without delimiters) to capture the preview URL. Ensure first capture group captures the preview URL. (default: `Preview: \[(.*)\]`) | ||
|
||
## Outputs | ||
|
||
- `vercel_preview_url`: The preview URL which can be accessed in the next action through the `needs` context, e.g. `${{needs.capture_vercel_preview_url.outputs.vercel_preview_url}}` ([Read more](https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#needs-context)) | ||
|
||
## Example | ||
|
||
```YML | ||
name: Capture Vercel preview URL | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
types: [opened] | ||
issue_comment: | ||
types: [edited] | ||
|
||
jobs: | ||
capture_vercel_preview_url: | ||
name: Capture Vercel preview URL | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- uses: aaron-binary/vercel-preview-url-action@master | ||
id: vercel_preview_url | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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" | ||
inputs: | ||
vercel_bot_name: | ||
description: "The name of the Vercel account commenting on pull requests." | ||
required: false | ||
default: "vercel[bot]" | ||
preview_url_regexp: | ||
description: "Regular expression pattern to capture the preview URL. Ensure first capture group captures the preview URL." | ||
required: false | ||
default: 'Preview: \[(.*)\]' # Do use single quotes, do NOT use delimiters. | ||
outputs: | ||
vercel_preview_url: | ||
description: "The preview URL for the pull request's Vercel deployment." | ||
runs: | ||
using: "node12" | ||
main: "dist/index.js" |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const core = require("@actions/core"); | ||
const github = require("@actions/github"); | ||
|
||
const runAction = async () => { | ||
const { payload } = github.context; | ||
const { comment } = payload; | ||
const vercel_bot_name = core.getInput("vercel_bot_name"); | ||
|
||
if (comment.user.login !== vercel_bot_name) { | ||
console.log("Comment did not originate from Vercel bot.", { | ||
vercel_bot_name, | ||
}); | ||
process.exit(1); | ||
} | ||
|
||
const preview_url_regexp = new RegExp(core.getInput("preview_url_regexp")); | ||
const regex_matches = comment.body.match(preview_url_regexp); | ||
|
||
if (!regex_matches) { | ||
console.log("Unable to find a preview URL in comment's body."); | ||
process.exit(1); | ||
} | ||
|
||
const vercel_preview_url = regex_matches[1]; | ||
|
||
if (vercel_preview_url) { | ||
console.log("Found preview URL.", { vercel_preview_url }); | ||
core.setOutput("vercel_preview_url", vercel_preview_url); | ||
process.exit(0); | ||
} else { | ||
console.log( | ||
"The regular expression is in an invalid format. Please ensure the first capture group caputures the preview URL." | ||
); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
runAction(); |
Oops, something went wrong.