diff --git a/README.md b/README.md index a6777f1..c1bccc1 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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 }} diff --git a/action.yml b/action.yml index 7994986..f6e8cb0 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/index.js b/index.js index ce7affb..52b2c2b 100644 --- a/index.js +++ b/index.js @@ -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")}`, @@ -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