0
Dispatch Workflow Run
One script reply has been approved by the moderators Verified

Trigger a GitHub Actions workflow run. The workflow needs to have the workflow_dispatch trigger.

Created by adam186 402 days ago Viewed 6543 times
0
Submitted by adam186 Deno
Verified 402 days ago
1
import { Octokit } from "https://cdn.skypack.dev/@octokit/rest";
2

3
/**
4
 * @param owner The account owner of the repository. The name is not case sensitive.
5
 *
6
 * @param repo The name of the repository. The name is not case sensitive.
7
 *
8
 * @param workflow_id The ID of the workflow. You can also pass the workflow file
9
 * name as a string.
10
 *
11
 * @param ref The git reference for the workflow. The reference can be a branch or
12
 * tag name.
13
 *
14
 * @param inputs Input keys and values configured in the workflow file. The maximum
15
 * number of properties is 10. Any default properties configured in the workflow
16
 * file will be used when inputs are omitted.
17
 */
18
type Github = {
19
  token: string;
20
};
21
export async function main(
22
  gh_auth: Github,
23
  owner: string,
24
  repo: string,
25
  workflow_id: string,
26
  ref: string,
27
  inputs?: Record<string | number, any>
28
) {
29
  const octokit = new Octokit({ auth: gh_auth.token });
30

31
  return await octokit.request(
32
    "POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",
33
    {
34
      owner,
35
      repo,
36
      workflow_id,
37
      ref,
38
      inputs: inputs || {},
39
      headers: {
40
        "X-GitHub-Api-Version": "2022-11-28",
41
        Accept: "application/vnd.github+json",
42
      },
43
    }
44
  );
45
}
46