Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
aaimio committed Oct 2, 2020
0 parents commit 6ebbb3e
Show file tree
Hide file tree
Showing 10 changed files with 1,841 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/example.yml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
40 changes: 40 additions & 0 deletions README.MD
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
```
21 changes: 21 additions & 0 deletions action.yml
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"
1 change: 1 addition & 0 deletions dist/index.js

Large diffs are not rendered by default.

569 changes: 569 additions & 0 deletions dist/licenses.txt

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions index.js
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();
Loading

0 comments on commit 6ebbb3e

Please sign in to comment.