Skip to content

Commit

Permalink
pass tokens as envs
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheyenbrock committed Aug 8, 2022
1 parent 783b809 commit 0796e49
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

This repository contains a GitHub action that uses the Vercel API to find the latest deployment for the current commit. It waits for the deployment to be done and then outputs the URL.

## Inputs
## Envs

### `github-token`
### `GITHUB_TOKEN`

**Required** A token to authenticate requests sent to the GitHub API. You can use the one that is [automatically added](https://docs.github.com/en/actions/reference/authentication-in-a-workflow) to your workflow run.

### `vercel-token`
### `VERCEL_TOKEN`

**Required** A token to authenticate requests sent to the Vercel API. You can create one [here](https://vercel.com/account/tokens).

## Inputs

### `project-id`

**Required** The id of your Vercel project. Usually you can find it in the `.vercel/project.json` file inside your repository.
Expand Down Expand Up @@ -40,9 +42,10 @@ The URL of the Vercel preview deployment in a `READY` state.
- name: Get deployment URL
id: deployment
uses: thomasheyenbrock/vercel-deployment-url@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-token: ${{ secrets.VERCEL_TOKEN }}
project-id: ${{ secrets.VERCEL_PROjECT_ID }}
```
Expand Down
8 changes: 1 addition & 7 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
name: "Get Vercel deployment"
description: "Gets the URL of the preview deployment on Vercel for the current commit"
inputs:
github-token:
description: "A token that allows access to the GitHub-API"
required: true
vercel-token:
description: "A token that allows access to the Vercel-API"
required: true
project-id:
description: "The identifier for your Vercel project"
required: true
Expand All @@ -25,5 +19,5 @@ outputs:
url:
description: "The URL of the vercel preview deployment"
runs:
using: "node12"
using: "node16"
main: "dist/index.js"
15 changes: 13 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,19 @@ function wait(s) {
}

async function main() {
const githubToken = core.getInput("github-token", { required: true });
const vercelToken = core.getInput("vercel-token", { required: true });
const githubToken = process.env.GITHUB_TOKEN;
if (!githubToken) {
throw new Error(
"This action needs a GitHub token, you need to set the env `GITHUB_TOKEN`"
);
}
const vercelToken = process.env.VERCEL_TOKEN;
if (!vercelToken) {
throw new Error(
"This action needs a Vercel token, you need to set the env `VERCEL_TOKEN`"
);
}

const projectId = core.getInput("project-id", { required: true });
const teamId = core.getInput("team-id");
const searchRetries = parseInt(core.getInput("search-retries"), 10) || 3;
Expand Down
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ function wait(s) {
}

async function main() {
const githubToken = core.getInput("github-token", { required: true });
const vercelToken = core.getInput("vercel-token", { required: true });
const githubToken = process.env.GITHUB_TOKEN;
if (!githubToken) {
throw new Error(
"This action needs a GitHub token, you need to set the env `GITHUB_TOKEN`"
);
}
const vercelToken = process.env.VERCEL_TOKEN;
if (!vercelToken) {
throw new Error(
"This action needs a Vercel token, you need to set the env `VERCEL_TOKEN`"
);
}

const projectId = core.getInput("project-id", { required: true });
const teamId = core.getInput("team-id");
const searchRetries = parseInt(core.getInput("search-retries"), 10) || 3;
Expand Down

0 comments on commit 0796e49

Please sign in to comment.