Skip to content

Commit

Permalink
No longer error on triggering disabled workflow (#49)
Browse files Browse the repository at this point in the history
* skip disabled workflows
* logging
* version bump
  • Loading branch information
benc-uk authored Oct 28, 2022
1 parent f9d8d79 commit 0aef261
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
13 changes: 9 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ const PackageJSON = __importStar(__webpack_require__(731));
//
function run() {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Workflow Dispatch Action v${PackageJSON.version}`);
core.info(`🏃 Workflow Dispatch Action v${PackageJSON.version}`);
try {
// Required inputs
const token = core.getInput('token');
Expand Down Expand Up @@ -597,17 +597,22 @@ function run() {
});
if (!foundWorkflow)
throw new Error(`Unable to find workflow '${workflowRef}' in ${owner}/${repo} 😥`);
console.log(`Workflow id is: ${foundWorkflow.id}`);
console.log(`🔎 Found workflow, id: ${foundWorkflow.id}, name: ${foundWorkflow.name}, path: ${foundWorkflow.path}`);
// Call workflow_dispatch API
console.log('🚀 Calling GitHub API to dispatch workflow...');
const dispatchResp = yield octokit.request(`POST /repos/${owner}/${repo}/actions/workflows/${foundWorkflow.id}/dispatches`, {
ref: ref,
inputs: inputs
});
core.info(`API response status: ${dispatchResp.status} 🚀`);
core.info(`🏆 API response status: ${dispatchResp.status}`);
core.setOutput('workflowId', foundWorkflow.id);
}
catch (error) {
const e = error;
if (e.message.endsWith('a disabled workflow')) {
core.warning('Workflow is disabled, no action was taken');
return;
}
core.setFailed(e.message);
}
});
Expand Down Expand Up @@ -6201,7 +6206,7 @@ exports.default = _default;
/***/ 731:
/***/ (function(module) {

module.exports = {"name":"workflow-dispatch","version":"1.2.0","description":"Trigger running GitHub Actions workflows","main":"dist/index.js","scripts":{"build":"ncc build src/main.ts -o dist","lint":"eslint src/"},"keywords":["github","actions"],"author":"Ben Coleman","license":"MIT","devDependencies":{"@actions/core":"^1.10.0","@actions/github":"^5.1.1","@zeit/ncc":"^0.22.3","@typescript-eslint/eslint-plugin":"^5.41.0","@typescript-eslint/parser":"^5.41.0","eslint":"^8.26.0","typescript":"^4.8.4"}};
module.exports = {"name":"workflow-dispatch","version":"1.2.1","description":"Trigger running GitHub Actions workflows","main":"dist/index.js","scripts":{"build":"ncc build src/main.ts -o dist","lint":"eslint src/"},"keywords":["github","actions"],"author":"Ben Coleman","license":"MIT","devDependencies":{"@actions/core":"^1.10.0","@actions/github":"^5.1.1","@zeit/ncc":"^0.22.3","@typescript-eslint/eslint-plugin":"^5.41.0","@typescript-eslint/parser":"^5.41.0","eslint":"^8.26.0","typescript":"^4.8.4"}};

/***/ }),

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workflow-dispatch",
"version": "1.2.0",
"version": "1.2.1",
"description": "Trigger running GitHub Actions workflows",
"main": "dist/index.js",
"scripts": {
Expand Down
13 changes: 10 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Workflow = {
// Main task function (async wrapper)
//
async function run(): Promise<void> {
core.info(`Workflow Dispatch Action v${PackageJSON.version}`)
core.info(`🏃 Workflow Dispatch Action v${PackageJSON.version}`)
try {
// Required inputs
const token = core.getInput('token')
Expand Down Expand Up @@ -60,18 +60,25 @@ async function run(): Promise<void> {

if(!foundWorkflow) throw new Error(`Unable to find workflow '${workflowRef}' in ${owner}/${repo} 😥`)

console.log(`Workflow id is: ${foundWorkflow.id}`)
console.log(`🔎 Found workflow, id: ${foundWorkflow.id}, name: ${foundWorkflow.name}, path: ${foundWorkflow.path}`)

// Call workflow_dispatch API
console.log('🚀 Calling GitHub API to dispatch workflow...')
const dispatchResp = await octokit.request(`POST /repos/${owner}/${repo}/actions/workflows/${foundWorkflow.id}/dispatches`, {
ref: ref,
inputs: inputs
})

core.info(`API response status: ${dispatchResp.status} 🚀`)
core.info(`🏆 API response status: ${dispatchResp.status}`)
core.setOutput('workflowId', foundWorkflow.id)
} catch (error) {
const e = error as Error

if(e.message.endsWith('a disabled workflow')){
core.warning('Workflow is disabled, no action was taken')
return
}

core.setFailed(e.message)
}
}
Expand Down

0 comments on commit 0aef261

Please sign in to comment.