From 1fa30577b1a0c005ccbdf034a8fc71b6a80c8b3b Mon Sep 17 00:00:00 2001 From: Rihards Gravis Date: Thu, 17 Sep 2020 16:08:00 +0300 Subject: [PATCH 1/5] Add team id option --- README.md | 4 ++++ index.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a6777f1..1d0073d 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,10 @@ Maximum time in seconds to wait for the deployment. Default `120`. +### `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` diff --git a/index.js b/index.js index ce7affb..79325ea 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,8 @@ async function getProdUrl(sha) { } 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) // If the deployment isn't in the response, this will throw an error and From 729a088e22c08b7aa77863a75cb8e9bbfea72617 Mon Sep 17 00:00:00 2001 From: Rihards Gravis Date: Thu, 17 Sep 2020 16:26:19 +0300 Subject: [PATCH 2/5] Await build --- README.md | 5 +++++ action.yml | 4 ++++ index.js | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 1d0073d..d688c14 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,10 @@ 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 @@ -49,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 79325ea..f14a77c 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,13 @@ async function getProdUrl(sha) { throw new Error("Commit sha for prod url didn't match") } + const awaitBuild = core.getInput("await-build") + + if(awaitBuild && data.deployments[0].state !== "READY"){ + throw Error("Deployment not yet ready") + } + + return data.url } @@ -28,6 +35,12 @@ async function getBranchUrl(sha) { const url = `https://api.vercel.com/v5/now/deployments?${teamId ? `teamId=${teamId}&` : ""}meta-githubCommitSha=${sha}` const { data } = await axios.get(url, headers) + const awaitBuild = core.getInput("await-build") + + if(awaitBuild && data.deployments[0].state !== "READY"){ + throw Error("Deployment not yet ready") + } + // If the deployment isn't in the response, this will throw an error and // cause a retry. return data.deployments[0].url From f33cdac10c816081050c20145b9b46e1e80e6f7b Mon Sep 17 00:00:00 2001 From: Rihards Gravis Date: Fri, 18 Sep 2020 15:59:09 +0300 Subject: [PATCH 3/5] Update README.md Co-authored-by: Mark Skelton --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d688c14..c1bccc1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ 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 +[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 From b3be9f22d798f8ca9c36500c8e093cb8d90feaa4 Mon Sep 17 00:00:00 2001 From: Rihards Gravis Date: Fri, 18 Sep 2020 15:59:18 +0300 Subject: [PATCH 4/5] Update index.js Co-authored-by: Mark Skelton --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index f14a77c..9ff8b8a 100644 --- a/index.js +++ b/index.js @@ -22,11 +22,10 @@ async function getProdUrl(sha) { const awaitBuild = core.getInput("await-build") - if(awaitBuild && data.deployments[0].state !== "READY"){ + if (awaitBuild && data.deployments[0].state !== "READY") { throw Error("Deployment not yet ready") } - return data.url } From ec5b21ca66cf2fcd32974dc5311303bd96e67860 Mon Sep 17 00:00:00 2001 From: Rihards Gravis Date: Fri, 18 Sep 2020 16:06:58 +0300 Subject: [PATCH 5/5] Update awaiting build as a helper function --- index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 9ff8b8a..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,11 +28,7 @@ async function getProdUrl(sha) { throw new Error("Commit sha for prod url didn't match") } - const awaitBuild = core.getInput("await-build") - - if (awaitBuild && data.deployments[0].state !== "READY") { - throw Error("Deployment not yet ready") - } + awaitBuild(data) return data.url } @@ -34,11 +38,7 @@ async function getBranchUrl(sha) { const url = `https://api.vercel.com/v5/now/deployments?${teamId ? `teamId=${teamId}&` : ""}meta-githubCommitSha=${sha}` const { data } = await axios.get(url, headers) - const awaitBuild = core.getInput("await-build") - - if(awaitBuild && data.deployments[0].state !== "READY"){ - throw Error("Deployment not yet ready") - } + awaitBuild(data) // If the deployment isn't in the response, this will throw an error and // cause a retry.