Skip to content

Commit 0aef261

Browse files
authored
No longer error on triggering disabled workflow (benc-uk#49)
* skip disabled workflows * logging * version bump
1 parent f9d8d79 commit 0aef261

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

dist/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ const PackageJSON = __importStar(__webpack_require__(731));
564564
//
565565
function run() {
566566
return __awaiter(this, void 0, void 0, function* () {
567-
core.info(`Workflow Dispatch Action v${PackageJSON.version}`);
567+
core.info(`🏃 Workflow Dispatch Action v${PackageJSON.version}`);
568568
try {
569569
// Required inputs
570570
const token = core.getInput('token');
@@ -597,17 +597,22 @@ function run() {
597597
});
598598
if (!foundWorkflow)
599599
throw new Error(`Unable to find workflow '${workflowRef}' in ${owner}/${repo} 😥`);
600-
console.log(`Workflow id is: ${foundWorkflow.id}`);
600+
console.log(`🔎 Found workflow, id: ${foundWorkflow.id}, name: ${foundWorkflow.name}, path: ${foundWorkflow.path}`);
601601
// Call workflow_dispatch API
602+
console.log('🚀 Calling GitHub API to dispatch workflow...');
602603
const dispatchResp = yield octokit.request(`POST /repos/${owner}/${repo}/actions/workflows/${foundWorkflow.id}/dispatches`, {
603604
ref: ref,
604605
inputs: inputs
605606
});
606-
core.info(`API response status: ${dispatchResp.status} 🚀`);
607+
core.info(`🏆 API response status: ${dispatchResp.status}`);
607608
core.setOutput('workflowId', foundWorkflow.id);
608609
}
609610
catch (error) {
610611
const e = error;
612+
if (e.message.endsWith('a disabled workflow')) {
613+
core.warning('Workflow is disabled, no action was taken');
614+
return;
615+
}
611616
core.setFailed(e.message);
612617
}
613618
});
@@ -6201,7 +6206,7 @@ exports.default = _default;
62016206
/***/ 731:
62026207
/***/ (function(module) {
62036208

6204-
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"}};
6209+
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"}};
62056210

62066211
/***/ }),
62076212

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "workflow-dispatch",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Trigger running GitHub Actions workflows",
55
"main": "dist/index.js",
66
"scripts": {

src/main.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Workflow = {
1919
// Main task function (async wrapper)
2020
//
2121
async function run(): Promise<void> {
22-
core.info(`Workflow Dispatch Action v${PackageJSON.version}`)
22+
core.info(`🏃 Workflow Dispatch Action v${PackageJSON.version}`)
2323
try {
2424
// Required inputs
2525
const token = core.getInput('token')
@@ -60,18 +60,25 @@ async function run(): Promise<void> {
6060

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

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

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

71-
core.info(`API response status: ${dispatchResp.status} 🚀`)
72+
core.info(`🏆 API response status: ${dispatchResp.status}`)
7273
core.setOutput('workflowId', foundWorkflow.id)
7374
} catch (error) {
7475
const e = error as Error
76+
77+
if(e.message.endsWith('a disabled workflow')){
78+
core.warning('Workflow is disabled, no action was taken')
79+
return
80+
}
81+
7582
core.setFailed(e.message)
7683
}
7784
}

0 commit comments

Comments
 (0)