Last active
August 1, 2021 14:02
-
-
Save adrians5j/6a3fa9f6b0e450ab88e3a5ba23f4e789 to your computer and use it in GitHub Desktop.
Dispatch GitHub Event
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
#!/usr/bin/env node | |
const { red, cyan, green } = require("chalk"); | |
const argv = require("yargs").argv; | |
const { Octokit } = require("@octokit/rest"); | |
/** | |
* A simple script that triggers GitHub workflows. | |
*/ | |
(async () => { | |
try { | |
const owner = "webiny"; | |
const repo = "webiny-js"; | |
const token = argv.token || process.env.GH_TOKEN; | |
if (!token) { | |
throw new Error(`GitHub token is missing.`); | |
} | |
const octokit = new Octokit({ | |
auth: token | |
}); | |
console.log(cyan(`Triggering ${green(argv.event)} worfklow...`)); | |
await octokit.repos.createDispatchEvent({ | |
owner, | |
repo, | |
event_type: argv.event, | |
client_payload: typeof argv.payload === "string" ? JSON.parse(argv.payload) : {} | |
}); | |
console.log(green("GitHub workflow successfully triggered.")); | |
console.log(green("See https://github.com/webiny/webiny-js/actions for action details.")); | |
} catch (e) { | |
console.log(red("Something went wrong:")); | |
console.log(red(e.message)); | |
} | |
})(); |
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
{ | |
"name": "dispatch-github-event", | |
"version": "1.0.0", | |
"bin": "./index.js", | |
"dependencies": { | |
"@octokit/rest": "^18.7.2", | |
"chalk": "^4.1.0", | |
"yargs": "^12.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment