trigger-workflow
v0.1.4
Published
Easily trigger GitHub workflows, get latest workflow runs, and wait for workflow runs to complete.
Downloads
57
Readme
trigger-workflow
Easily trigger GitHub workflows, get latest workflow runs, and wait for workflow runs to complete.
Please consider following this project's author, Brian Woodward, and consider starring the project to show your :heart: and support.
Install
Install with npm:
$ npm install --save trigger-workflow
Usage
Example
import { triggerWorkflow, waitForCompletion } from 'trigger-workflow';
async function main() {
const token = 'ghp_your_github_token_here';
const owner = 'foo';
const repo = 'bar';
const run_id = await triggerWorkflow({
owner,
repo,
token,
workflow_id: 'my-workflow.yml',
ref: 'main'
});
await waitForCompletion({ owner, repo, token, run_id });
console.log(`Workflow triggered with run_id: ${run_id}`);
}
main().catch(console.error);
API
This package provides two functions: triggerWorkflow
and waitForCompletion
.
triggerWorkflow
Triggers a GitHub Actions workflow and returns the run_id
of the triggered workflow.
Example
import { triggerWorkflow } from 'trigger-workflow';
async function main() {
const run_id = await triggerWorkflow({
owner: 'foo',
repo: 'bar',
token: 'ghp_your_github_token_here',
workflow_id: 'my-workflow.yml',
ref: 'main'
});
console.log(`Workflow triggered with run_id: ${run_id}`);
}
main().catch(console.error);
waitForCompletion
Waits for a GitHub Actions workflow to complete, polling at a specified interval.
Example
import { triggerWorkflow, waitForCompletion } from 'trigger-workflow';
async function main() {
const token = 'ghp_your_github_token_here';
const run_id = '1234567890';
const owner = 'foo';
const repo = 'bar';
await waitForCompletion({
owner,
repo,
token,
run_id,
interval: 5000,
});
console.log('Workflow completed!');
}
main().catch(console.error);
About
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Contributors
| Commits | Contributor |
| --- | --- |
| 19 | doowb |
| 2 | jonschlinkert |
Author
Brian Woodward
License
Copyright © 2024, Brian Woodward. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on September 10, 2024.