Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer error on triggering disabled workflow #49

Merged
merged 3 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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