-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
369 changed files
with
88,436 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# wait-for-deployment | ||
Github action that waits for a deployment | ||
# Wait For GitHub Deployment | ||
|
||
Wait for a GitHub deployment to complete and get its url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Wait For GitHub Deployment | ||
description: Wait for a GitHub deployment to complete and get its url | ||
inputs: | ||
token: | ||
description: Your GitHub access token | ||
required: true | ||
timeout: | ||
description: The max time to run the action (in seconds) | ||
required: false | ||
default: "120" | ||
outputs: | ||
url: | ||
description: The url of the new deployment | ||
runs: | ||
using: node12 | ||
main: index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const core = require("@actions/core"); | ||
const github = require("@actions/github"); | ||
|
||
const sleep = (seconds) => | ||
new Promise((resolve) => setTimeout(resolve, seconds * 1000)); | ||
|
||
async function waitForDeployment() { | ||
const { eventName, payload, repo } = github.context; | ||
const token = core.getInput("token"); | ||
const timeout = core.getInput("timeout") * 1000; | ||
const endTime = new Date().getTime() + timeout; | ||
|
||
let params = { | ||
...repo, | ||
}; | ||
|
||
core.debug(`eventName? ${eventName}`); | ||
|
||
if (eventName === "pull_request") { | ||
params = { | ||
...params, | ||
sha: payload.pull_request.head.sha, | ||
environment: "Preview", | ||
}; | ||
} else if (eventName === "push") { | ||
params = { | ||
...params, | ||
sha: payload.head_commit.id, | ||
environment: "Production", | ||
}; | ||
} else { | ||
throw new Error(`Unhandled event: ${eventName}`); | ||
} | ||
|
||
let attempt = 1; | ||
|
||
const octokit = github.getOctokit(token); | ||
|
||
while (new Date().getTime() < endTime) { | ||
try { | ||
const { data: deployments } = await octokit.repos.listDeployments(params); | ||
|
||
if (deployments.length > 1) { | ||
throw new Error( | ||
`There should be only one deployment for ${params.sha} but found ${deployments.length} instead.` | ||
); | ||
} | ||
|
||
for (const deployment of deployments) { | ||
const { data: statuses } = await octokit.repos.listDeploymentStatuses({ | ||
...repo, | ||
deployment_id: deployment.id, | ||
}); | ||
|
||
const [success] = statuses.filter( | ||
(status) => status.state === "success" | ||
); | ||
|
||
if (success) { | ||
return success.target_url; | ||
} | ||
} | ||
} catch (error) { | ||
throw error; | ||
} | ||
|
||
console.log(`Url unavailable. Attempt ${attempt++}.`); | ||
|
||
await sleep(2); | ||
} | ||
|
||
throw new Error( | ||
`Timeout reached before deployment for ${params.sha} was found.` | ||
); | ||
} | ||
|
||
(async () => { | ||
try { | ||
const url = await waitForDeployment(); | ||
core.setOutput("url", url); | ||
} catch (err) { | ||
core.setFailed(err.message); | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.