Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Add team ID and await build parameters #4

Merged
merged 5 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

Maximum time in seconds to wait for the deployment. Default `120`.

### `await-build`

Wait for the deployment to be built before returning the url.

### `team-id`

[Vercel team ID](https://vercel.com/docs/api#api-basics/authentication/accessing-resources-owned-by-a-team) if the deployment is owned by a team.

## Outputs

### `url`
Expand Down Expand Up @@ -45,6 +53,7 @@ steps:
with:
prod-url: example.now.sh
token: ${{ secrets.VERCEL_TOKEN }}
await-build: true
- run: npm test
env:
ENVIRONMENT_URL: ${{ steps.wait-for-vercel.outputs.url }}
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ inputs:
token:
description: Vercel authorization token
required: true
team-id:
description: Vercel team ID
timeout:
description: The max time to run the action (in seconds)
required: false
default: "120"
await-build:
description: Wait for the deployment to be built
outputs:
url:
description: The fully qualified deployment URL
Expand Down
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const axios = require("axios")
const sleep = (seconds) =>
new Promise((resolve) => setTimeout(resolve, seconds * 1000))

const awaitBuild = (data) => {
const awaitBuild = core.getInput("await-build")

if (awaitBuild && data.deployments[0].state !== "READY") {
throw Error("Deployment not yet ready")
}
}

const headers = {
headers: {
Authorization: `Bearer ${core.getInput("token")}`,
Expand All @@ -20,13 +28,18 @@ async function getProdUrl(sha) {
throw new Error("Commit sha for prod url didn't match")
}

awaitBuild(data)

return data.url
}

async function getBranchUrl(sha) {
const url = `https://api.vercel.com/v5/now/deployments?meta-githubCommitSha=${sha}`
const teamId = core.getInput("team-id")
const url = `https://api.vercel.com/v5/now/deployments?${teamId ? `teamId=${teamId}&` : ""}meta-githubCommitSha=${sha}`
const { data } = await axios.get(url, headers)

awaitBuild(data)

// If the deployment isn't in the response, this will throw an error and
// cause a retry.
return data.deployments[0].url
Expand Down