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

Migrate to use @kesin11/gha-utils #158

Merged
merged 6 commits into from
Aug 17, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-deno-with-cache
- run: deno test
- run: deno test --allow-env
- name: CLI somke test
run: |
RUN_URL=$(gh run list -L 1 -w release --json url --jq .[].url)
deno run --allow-net --allow-write cli.ts -t "${GITHUB_TOKEN}" -o output.md $RUN_URL
deno run --allow-net --allow-write --allow-env=GITHUB_API_URL cli.ts -t "${GITHUB_TOKEN}" -o output.md $RUN_URL
cat output.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ job, `actions-timeline` omits `Waiting for a runner` step in the timeline.
`deno run` command.

```bash
deno run --allow-net --allow-write \
deno run --allow-net --allow-write --allow-env=GITHUB_API_URL \
https://raw.githubusercontent.com/Kesin11/actions-timeline/main/cli.ts \
https://github.com/Kesin11/actions-timeline/actions/runs/8021493760/attempts/1 \
-t $(gh auth token) \
-o output.md

# Fetch latest attempt if ommit attempts
deno run --allow-net --allow-write \
deno run --allow-net --allow-write --allow-env=GITHUB_API_URL \
https://raw.githubusercontent.com/Kesin11/actions-timeline/main/cli.ts \
https://github.com/Kesin11/actions-timeline/actions/runs/8021493760/ \
-t $(gh auth token) \
-o output.md

# GHES
deno run --allow-net --allow-write \
deno run --allow-net --allow-write --allow-env=GITHUB_API_URL \
https://raw.githubusercontent.com/Kesin11/actions-timeline/main/cli.ts \
https://YOUR_ENTERPRISE_HOST/OWNER/REPO/actions/runs/RUN_ID/attempts/1 \
-t $(gh auth token -h YOUR_ENTERPRISE_HOST) \
Expand Down
40 changes: 10 additions & 30 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts";
import { createMermaid } from "./src/workflow_gantt.ts";
import {
createOctokitForCli,
fetchWorkflow,
fetchWorkflowLatestAttempt,
fetchWorkflowRunJobs,
} from "./src/github.ts";
import { parseWorkflowRunUrl } from "./src/github.ts";
import { Github, parseWorkflowRunUrl } from "@kesin11/gha-utils";

const { options, args } = await new Command()
.name("actions-timeline-cli")
Expand All @@ -27,34 +21,20 @@ const { options, args } = await new Command()
const url = args[0];
const runUrl = parseWorkflowRunUrl(url);

const octokit = createOctokitForCli({
token: options.token,
origin: runUrl.origin,
});

const runAttempt = runUrl.runAttempt ??
await fetchWorkflowLatestAttempt(
octokit,
runUrl.owner,
runUrl.repo,
runUrl.runId,
);
const host = (runUrl.origin !== "https://github.com")
? runUrl.origin
: undefined;
const client = new Github({ token: options.token, host });

const workflow = await fetchWorkflow(
octokit,
const workflowRun = await client.fetchWorkflowRun(
runUrl.owner,
runUrl.repo,
runUrl.runId,
runAttempt,
runUrl.runAttempt,
);
const workflowJobs = await fetchWorkflowRunJobs(
octokit,
runUrl.owner,
runUrl.repo,
runUrl.runId,
runAttempt,
);
const gantt = createMermaid(workflow, workflowJobs, {
const workflowJobs = await client.fetchWorkflowJobs([workflowRun]);

const gantt = createMermaid(workflowRun, workflowJobs, {
showWaitingRunner: options.showWaitingRunner,
});

Expand Down
3 changes: 3 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
},
"lint": {
"exclude": ["./dist/", "./npm/"]
},
"imports": {
"@kesin11/gha-utils": "jsr:@kesin11/gha-utils@^0.1.0"
}
}
Loading