-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample.js
More file actions
36 lines (31 loc) · 1009 Bytes
/
sample.js
File metadata and controls
36 lines (31 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Octokit } from '@octokit/rest';
import fetch from 'node-fetch';
const octokit = new Octokit({
auth: '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',
request: { fetch },
});
const owner = 'SS2199';
const repo = 'Action';
const workflowFileName = '.github/workflows/trigger-workflow.yml'; // Name of the workflow YAML file
async function triggerWorkflow() {
try {
const response = await octokit.actions.createWorkflowDispatch({
owner,
repo,
workflow_file: workflowFileName,
ref: 'main', // Specify the branch or ref
inputs: {
// Provide any input parameters if your workflow expects them
exampleParam: 'value',
},
});
if (response.status === 204) {
console.log('Workflow dispatch triggered successfully.');
} else {
console.error('Failed to trigger workflow dispatch:', response.statusText);
}
} catch (error) {
console.error('Error triggering workflow dispatch:', error.message);
}
}
triggerWorkflow();