-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow-ls.ts
53 lines (48 loc) · 1.84 KB
/
workflow-ls.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// reusableやcompositeが多様されたworkflowを展開して流れを把握できるようにするスクリプト
// イメージとしてはnpm lsのように依存関係をツリー、もしくはインデントで表現したい
//
// サンプルの出力イメージ
// main (.github/workflows/medianAbsoluteDeviation.yaml):
// build:
// - checkout
// - run: echo
// - uses: ../.github/actions/my-compisite (https://github.com/owner/repo/.github/actions/my-compisite/action.yml)
// - run: build
// - run: test
// - uses: ../.github/actions/common (https://github.com/owner/repo/.github/actions/common/action.yml)
// - run: post.sh
// reusable: (../.github/workflows/reusable.yml)
// - lint:
// - uses: ../.github/actions/my-composite (https://github.com/owner/repo/.github/actions/my-composite/action.yml)
// - run: build
// - run: test
// - run: lint
import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.3/command/mod.ts";
import { Github, parseWorkflowRunUrl } from "./src/github.ts";
import { WorkflowTree } from "./src/workflow_tree.ts";
const { options, args } = await new Command()
.name("workflow-ls")
.description(
"Show GitHub Actions workflow yaml expanding Reusable Workflow job and Composite Actions step",
)
.option("-t, --token <token:string>", "GitHub token. ex: $(gh auth token)", {
default: undefined,
})
.arguments("<url:string>")
.parse(Deno.args);
const url = args[0];
const runUrl = parseWorkflowRunUrl(url);
const github = new Github({ token: options.token, origin: runUrl.origin });
const workflow = await github.fetchWorkflow(
runUrl.owner,
runUrl.repo,
runUrl.runId,
runUrl.runAttempt,
);
const workflowTree = new WorkflowTree(
github,
runUrl.owner,
runUrl.repo,
workflow.head_sha,
);
await workflowTree.showWorkflow(workflow.path);