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

Commit

Permalink
Add team ID and await build parameters (#4)
Browse files Browse the repository at this point in the history
* Add team id option

* Await build

* Update README.md

Co-authored-by: Mark Skelton <mdskelton99@gmail.com>

* Update index.js

Co-authored-by: Mark Skelton <mdskelton99@gmail.com>

* Update awaiting build as a helper function

Co-authored-by: Mark Skelton <mdskelton99@gmail.com>
  • Loading branch information
rihardsgravis and mskelton authored Sep 18, 2020
1 parent c3923e7 commit ba3742a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
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

0 comments on commit ba3742a

Please sign in to comment.