@softure-ai/ci-usage 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/README.md +128 -2
- package/dist/billing.d.ts +37 -0
- package/dist/billing.d.ts.map +1 -0
- package/dist/billing.js +83 -0
- package/dist/billing.js.map +1 -0
- package/dist/cli/command.d.ts +33 -0
- package/dist/cli/command.d.ts.map +1 -0
- package/dist/cli/command.js +203 -0
- package/dist/cli/command.js.map +1 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +10 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/collect.d.ts +45 -0
- package/dist/collect.d.ts.map +1 -0
- package/dist/collect.js +189 -0
- package/dist/collect.js.map +1 -0
- package/dist/github.d.ts +41 -0
- package/dist/github.d.ts.map +1 -0
- package/dist/github.js +91 -0
- package/dist/github.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/messages/en.d.ts +51 -0
- package/dist/messages/en.d.ts.map +1 -0
- package/dist/messages/en.js +51 -0
- package/dist/messages/en.js.map +1 -0
- package/dist/messages/index.d.ts +11 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/index.js +13 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/prices.d.ts +32 -0
- package/dist/prices.d.ts.map +1 -0
- package/dist/prices.js +52 -0
- package/dist/prices.js.map +1 -0
- package/dist/publish.d.ts +29 -0
- package/dist/publish.d.ts.map +1 -0
- package/dist/publish.js +91 -0
- package/dist/publish.js.map +1 -0
- package/dist/report.d.ts +57 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +168 -0
- package/dist/report.js.map +1 -0
- package/dist/runner.d.ts +28 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +55 -0
- package/dist/runner.js.map +1 -0
- package/dist/usage.d.ts +67 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +112 -0
- package/dist/usage.js.map +1 -0
- package/examples/ci-usage.yml +34 -0
- package/package.json +42 -4
- package/src/billing.ts +102 -0
- package/src/cli/command.ts +212 -0
- package/src/cli/main.ts +10 -0
- package/src/collect.ts +230 -0
- package/src/github.ts +113 -0
- package/src/index.ts +10 -0
- package/src/messages/en.ts +52 -0
- package/src/messages/index.ts +15 -0
- package/src/prices.ts +74 -0
- package/src/publish.ts +95 -0
- package/src/report.ts +215 -0
- package/src/runner.ts +64 -0
- package/src/usage.ts +192 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Newest first. Each version lists what changed for an app that uses `@softure-ai/ci-usage` or the reusable
|
|
4
|
+
`ci-usage.yml` workflow. When an app has run a version in production, the version gets a line
|
|
5
|
+
`verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md), "Definition of done").
|
|
6
|
+
|
|
7
|
+
## 0.1.0
|
|
8
|
+
|
|
9
|
+
- First version (#1360). `softure-ci-usage report` reads the finished workflow runs of a period through the Actions
|
|
10
|
+
API (one UTC day at a time, split into hours past GitHub's 1,000-run cap) and writes `ci-usage.json`
|
|
11
|
+
(`schemaVersion: 1`) and `ci-usage.md`: billable minutes (each job rounded up to a whole minute, reruns included)
|
|
12
|
+
and estimated USD per repository, workflow and job, split into GitHub-hosted, Ubicloud and other self-hosted
|
|
13
|
+
runners, with the heaviest and the longest jobs.
|
|
14
|
+
- Prices: GitHub's standard runner SKUs and Ubicloud's standard and premium sizes, built in with their source and
|
|
15
|
+
the day they were checked; `--prices` adds or overrides prices by runner label.
|
|
16
|
+
- `--billing org:<name>|user:<name>` adds what GitHub billed per repository and SKU from the billing usage API.
|
|
17
|
+
- A request budget (`--reserve`) and a cache of finished runs (`--cache`): a busy repository ends in a partial
|
|
18
|
+
report, never a failed or sleeping job.
|
|
19
|
+
- `softure-ci-usage publish` keeps one issue labelled `ci-usage` up to date and comments each run's totals.
|
|
20
|
+
- The reusable workflow `.github/workflows/ci-usage.yml` and the example caller `examples/ci-usage.yml` (weekly
|
|
21
|
+
schedule and `workflow_dispatch`).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SOFTURE
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,129 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @softure-ai/ci-usage
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
How many GitHub Actions minutes a repository used in a period, and which workflows and jobs used them, on
|
|
4
|
+
GitHub-hosted and Ubicloud runners alike, with the estimated cost of each. An app calls the reusable workflow every
|
|
5
|
+
week and by hand; the report lands in one issue that people and agents read, in the job summary, and as JSON in the
|
|
6
|
+
run's artifact. The same CLI runs on a laptop or in an agent session.
|
|
7
|
+
|
|
8
|
+
- **One source for every runner.** The Actions jobs API: each job's start, end and runner labels. Minutes are billed
|
|
9
|
+
the way GitHub and Ubicloud bill them: each job rounded up to a whole minute, reruns included, queue time free.
|
|
10
|
+
GitHub's per-run "timing" endpoints are closing down and Ubicloud has no usage API, so nothing else covers both.
|
|
11
|
+
- **Per repository, workflow and job.** Totals per provider, every workflow with its share, the jobs that use the
|
|
12
|
+
most minutes (count, p50, p95), the ten longest single jobs with links.
|
|
13
|
+
- **Estimated USD at list price.** Built-in prices for GitHub's standard runner SKUs and Ubicloud's standard and
|
|
14
|
+
premium sizes, with their source and the day they were checked; `prices` adds runners the table does not know
|
|
15
|
+
(larger GitHub runners, own runners). A public repository pays nothing for standard GitHub runners and a plan's
|
|
16
|
+
included minutes are not subtracted: the estimate measures how resource-hungry the CI is, not the invoice.
|
|
17
|
+
- **What GitHub billed, optionally.** `billing: org:<name>` (or `user:<name>`) adds the billed minutes and amounts per
|
|
18
|
+
SKU from GitHub's billing usage API, next to the estimate.
|
|
19
|
+
- **Never red for a busy repository.** Runs are listed one UTC day at a time (split into hours past GitHub's
|
|
20
|
+
1,000-run cap), finished runs are cached between reports, and the client stops at a request reserve: a report that
|
|
21
|
+
could not count everything says so (`partial`) and still succeeds.
|
|
22
|
+
|
|
23
|
+
## Adoption
|
|
24
|
+
|
|
25
|
+
1. Copy [`examples/ci-usage.yml`](examples/ci-usage.yml) to `.github/workflows/ci-usage.yml` in the app. It runs
|
|
26
|
+
every Monday at 06:30 UTC and by hand (Actions → ci-usage → Run workflow, or `gh workflow run ci-usage.yml`).
|
|
27
|
+
2. Nothing else for a report on the app's own repository: the job reads with its `GITHUB_TOKEN` (`actions: read`)
|
|
28
|
+
and writes the issue with it (`issues: write`).
|
|
29
|
+
3. Optional, for one report over several repositories or for the billing lookup: a fine-grained personal access
|
|
30
|
+
token with "Actions: read" on those repositories (and organization "Administration: read" or user "Plan: read"
|
|
31
|
+
for billing), saved as the repository secret `CI_USAGE_TOKEN`; then set `repositories` (and `billing`).
|
|
32
|
+
|
|
33
|
+
The caller grants `contents: read`, `actions: read` and `issues: write`.
|
|
34
|
+
|
|
35
|
+
### Inputs
|
|
36
|
+
|
|
37
|
+
| Input | Default | What it does |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| `runs-on` | `'"ubuntu-latest"'` | The report's own runner as JSON, one label or an array (`'"ubicloud-standard-2"'`) |
|
|
40
|
+
| `repositories` | the calling repository | `owner/name` entries, comma or space separated (others need `CI_USAGE_TOKEN`) |
|
|
41
|
+
| `days` | `"7"` | Length of the period, ending now (1 to 31) |
|
|
42
|
+
| `prices` | empty | JSON of runner label to USD per minute, over the built-in table |
|
|
43
|
+
| `ubicloud-premium` | `false` | Price Ubicloud minutes as premium (an account setting a job does not show) |
|
|
44
|
+
| `billing` | empty | `org:<organization>` or `user:<user>`: add what GitHub billed |
|
|
45
|
+
| `publish` | `true` | Keep the `ci-usage` issue up to date |
|
|
46
|
+
| `cli-version` | the released version | `@softure-ai/ci-usage` version |
|
|
47
|
+
| `node-version` | `"22"` | Node.js version |
|
|
48
|
+
|
|
49
|
+
Secret: `CI_USAGE_TOKEN` (optional). The report always reads with it when it is set and writes the issue with the
|
|
50
|
+
job's own `GITHUB_TOKEN`.
|
|
51
|
+
|
|
52
|
+
### Busy repositories
|
|
53
|
+
|
|
54
|
+
`GITHUB_TOKEN` allows 1,000 API requests an hour per repository, and the report needs about one per run. A
|
|
55
|
+
repository with more runs a week than that keeps the run cache warm with a daily run and publishes weekly: two
|
|
56
|
+
schedules, and `publish` only for the weekly one (SOFTURE/AI's own `.github/workflows/ci-usage-self.yml` does this; permissions
|
|
57
|
+
and secrets as in the example):
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
on:
|
|
61
|
+
schedule:
|
|
62
|
+
- cron: "30 6 * * 1"
|
|
63
|
+
- cron: "30 6 * * 0,2-6"
|
|
64
|
+
workflow_dispatch:
|
|
65
|
+
jobs:
|
|
66
|
+
ci-usage:
|
|
67
|
+
uses: SOFTURE/AI/.github/workflows/ci-usage.yml@master
|
|
68
|
+
with:
|
|
69
|
+
publish: ${{ github.event_name == 'workflow_dispatch' || github.event.schedule == '30 6 * * 1' }}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`CI_USAGE_TOKEN` (5,000 requests an hour) is the other way out.
|
|
73
|
+
|
|
74
|
+
## Reading the report
|
|
75
|
+
|
|
76
|
+
- **The issue** `CI usage report` (label `ci-usage`): its body is always the latest report, with the JSON in a
|
|
77
|
+
collapsed block at the end (or a pointer to the artifact when it is too long); every run adds a comment with its
|
|
78
|
+
period and totals, so the comments are the history. An agent reads it with the GitHub tools it already has (an
|
|
79
|
+
issue read of the label `ci-usage`).
|
|
80
|
+
- **The artifact** `ci-usage-report` of the run: `ci-usage.json` and `ci-usage.md`, kept 90 days.
|
|
81
|
+
- **The CLI**, anywhere with a token:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
GITHUB_TOKEN=… npx @softure-ai/ci-usage report --repository acme/app --days 7 --out-dir report
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Every minute in the report is a billable minute; `Est. USD` is minutes times the list price of the runner. A
|
|
88
|
+
repository whose runs could not all be counted (the rate limit, an hour of more than 1,000 runs, a run whose jobs
|
|
89
|
+
could not be read) is listed with the reason under "Notes", and the report says `Status: partial`.
|
|
90
|
+
|
|
91
|
+
### The JSON (`schemaVersion: 1`)
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
generatedAt, period { from, to, days }, partial, notes[]
|
|
95
|
+
totals { minutes, usd, unpricedMinutes, runs, jobs, byProvider { github-hosted, ubicloud, self-hosted } }
|
|
96
|
+
prices { source, checkedOn, ubicloudPremium, labels }
|
|
97
|
+
repositories[] {
|
|
98
|
+
repository, minutes, usd, unpricedMinutes, runs, jobs, byProvider, partial[], error, runsRunning, runsFromCache,
|
|
99
|
+
byWorkflow[] { name, path, runs, jobs, minutes, usd, share, byJob[] { name, runner, provider, count, minutes, usd, p50Minutes, p95Minutes } },
|
|
100
|
+
longestJobs[] { workflow, job, runner, minutes, url },
|
|
101
|
+
billing[] { sku, minutes, grossUsd, netUsd } | null
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`usd` is `null` wherever some minutes ran on a runner without a known price (`unpricedMinutes` says how many).
|
|
106
|
+
|
|
107
|
+
## Runners
|
|
108
|
+
|
|
109
|
+
| Labels | Provider | Price |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| `ubuntu-*`, `ubuntu-*-arm`, `ubuntu-slim`, `windows-*`, `windows-*-arm`, `macos-*` | GitHub-hosted | the SKU's list price |
|
|
112
|
+
| a custom label in GitHub's runner group (a larger runner) | GitHub-hosted | Linux 2-core unless `prices` names the label |
|
|
113
|
+
| `ubicloud`, `ubicloud-arm`, `ubicloud-standard-<2/4/8/16/30>[-arm][-ubuntu-XXXX]` | Ubicloud | standard (or premium with `ubicloud-premium`) by vCPU |
|
|
114
|
+
| anything else | self-hosted | only from `prices`; otherwise counted without a price |
|
|
115
|
+
|
|
116
|
+
## CLI
|
|
117
|
+
|
|
118
|
+
```text
|
|
119
|
+
softure-ci-usage report [--repository <owner/name>[,…]] [--days 7 | --from <date> --to <date>] [--out-dir .]
|
|
120
|
+
[--prices <json>] [--ubicloud-premium] [--billing org:<name>|user:<name>]
|
|
121
|
+
[--cache <file>] [--reserve 50]
|
|
122
|
+
softure-ci-usage publish [--repository <owner/name>] [--report-dir .] [--run-url <url>]
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The token comes from `GITHUB_TOKEN` (or `GH_TOKEN`); the repository defaults to `GITHUB_REPOSITORY`. `report` exits
|
|
126
|
+
0 when at least one repository was read (a partial report included) and 1 on an input error or when no repository
|
|
127
|
+
could be read. The library exports the same steps (`collectRepository`, `summarizeUsage`, `buildReport`,
|
|
128
|
+
`renderMarkdown`, `publishReport`) and the copy as a message dictionary (`ciUsageMessages.en`), which an app can
|
|
129
|
+
replace with its own wording of the same shape.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { GithubClient } from "./github.js";
|
|
2
|
+
export type BillingAccount = {
|
|
3
|
+
kind: "org" | "user";
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
export type AccountResult = {
|
|
7
|
+
ok: true;
|
|
8
|
+
account: BillingAccount;
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
error: string;
|
|
12
|
+
};
|
|
13
|
+
/** Reads `org:<name>` or `user:<name>`; an empty value means no billing lookup. */
|
|
14
|
+
export declare function parseBillingAccount(value: string | undefined): AccountResult | null;
|
|
15
|
+
export interface BilledSku {
|
|
16
|
+
sku: string;
|
|
17
|
+
minutes: number;
|
|
18
|
+
grossUsd: number;
|
|
19
|
+
netUsd: number;
|
|
20
|
+
}
|
|
21
|
+
export type BillingResult = {
|
|
22
|
+
ok: true;
|
|
23
|
+
byRepository: Record<string, BilledSku[]>;
|
|
24
|
+
} | {
|
|
25
|
+
ok: false;
|
|
26
|
+
error: string;
|
|
27
|
+
};
|
|
28
|
+
export interface BillingOptions {
|
|
29
|
+
client: GithubClient;
|
|
30
|
+
account: BillingAccount;
|
|
31
|
+
repositories: readonly string[];
|
|
32
|
+
from: Date;
|
|
33
|
+
to: Date;
|
|
34
|
+
}
|
|
35
|
+
/** Sums the Actions minute items of the period per repository and SKU. */
|
|
36
|
+
export declare function getBillingUsage(options: BillingOptions): Promise<BillingResult>;
|
|
37
|
+
//# sourceMappingURL=billing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpE,MAAM,MAAM,aAAa,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,cAAc,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjG,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CAKnF;AAeD,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAwBnH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,cAAc,CAAC;IACxB,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,IAAI,EAAE,IAAI,CAAC;IACX,EAAE,EAAE,IAAI,CAAC;CACV;AAED,0EAA0E;AAC1E,wBAAsB,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CA8BrF"}
|
package/dist/billing.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// What GitHub actually billed for Actions, per repository and SKU, from the billing usage API. Optional: it needs a
|
|
2
|
+
// fine-grained token with organization "Administration: read" or user "Plan: read", and its answer only ever
|
|
3
|
+
// completes the estimate.
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
/** Reads `org:<name>` or `user:<name>`; an empty value means no billing lookup. */
|
|
6
|
+
export function parseBillingAccount(value) {
|
|
7
|
+
if (value === undefined || value.trim() === "")
|
|
8
|
+
return null;
|
|
9
|
+
const match = /^(org|user):([A-Za-z0-9][A-Za-z0-9-]*)$/.exec(value.trim());
|
|
10
|
+
if (!match?.[1] || !match[2])
|
|
11
|
+
return { ok: false, error: `--billing must be org:<organization> or user:<user>, not "${value}"` };
|
|
12
|
+
return { ok: true, account: { kind: match[1], name: match[2] } };
|
|
13
|
+
}
|
|
14
|
+
const ITEM = z.object({
|
|
15
|
+
date: z.string(),
|
|
16
|
+
product: z.string(),
|
|
17
|
+
sku: z.string(),
|
|
18
|
+
quantity: z.number(),
|
|
19
|
+
unitType: z.string(),
|
|
20
|
+
netAmount: z.number(),
|
|
21
|
+
grossAmount: z.number().optional(),
|
|
22
|
+
repositoryName: z.string().nullable().optional(),
|
|
23
|
+
});
|
|
24
|
+
const USAGE = z.object({ usageItems: z.array(ITEM) });
|
|
25
|
+
function getMonths(from, to) {
|
|
26
|
+
const months = [];
|
|
27
|
+
let year = from.getUTCFullYear();
|
|
28
|
+
let month = from.getUTCMonth();
|
|
29
|
+
const last = new Date(to.getTime() - 1);
|
|
30
|
+
while (year < last.getUTCFullYear() || (year === last.getUTCFullYear() && month <= last.getUTCMonth())) {
|
|
31
|
+
months.push({ year, month: month + 1 });
|
|
32
|
+
month += 1;
|
|
33
|
+
if (month === 12) {
|
|
34
|
+
month = 0;
|
|
35
|
+
year += 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return months;
|
|
39
|
+
}
|
|
40
|
+
/** The usage item's repository as `owner/name`: GitHub gives the name alone or the full name. */
|
|
41
|
+
function matchRepository(item, repositories) {
|
|
42
|
+
if (!item)
|
|
43
|
+
return null;
|
|
44
|
+
return repositories.find((repository) => repository === item || repository.split("/")[1] === item) ?? null;
|
|
45
|
+
}
|
|
46
|
+
/** Sums the Actions minute items of the period per repository and SKU. */
|
|
47
|
+
export async function getBillingUsage(options) {
|
|
48
|
+
const base = options.account.kind === "org" ? `/organizations/${options.account.name}` : `/users/${options.account.name}`;
|
|
49
|
+
const sums = new Map();
|
|
50
|
+
for (const { year, month } of getMonths(options.from, options.to)) {
|
|
51
|
+
const result = await options.client.get(`${base}/settings/billing/usage`, { year: String(year), month: String(month) });
|
|
52
|
+
if (!result.ok)
|
|
53
|
+
return { ok: false, error: `billing usage of ${options.account.kind}:${options.account.name} unavailable: ${result.message}` };
|
|
54
|
+
const parsed = USAGE.safeParse(result.data);
|
|
55
|
+
if (!parsed.success)
|
|
56
|
+
return { ok: false, error: `billing usage of ${options.account.kind}:${options.account.name} answered an unexpected shape` };
|
|
57
|
+
for (const item of parsed.data.usageItems) {
|
|
58
|
+
if (item.product.toLowerCase() !== "actions" || item.unitType.toLowerCase() !== "minutes")
|
|
59
|
+
continue;
|
|
60
|
+
const date = Date.parse(item.date);
|
|
61
|
+
if (!(date >= options.from.getTime() && date < options.to.getTime()))
|
|
62
|
+
continue;
|
|
63
|
+
const repository = matchRepository(item.repositoryName, options.repositories);
|
|
64
|
+
if (repository === null)
|
|
65
|
+
continue;
|
|
66
|
+
const skus = sums.get(repository) ?? new Map();
|
|
67
|
+
sums.set(repository, skus);
|
|
68
|
+
const sum = skus.get(item.sku) ?? { sku: item.sku, minutes: 0, grossUsd: 0, netUsd: 0 };
|
|
69
|
+
skus.set(item.sku, sum);
|
|
70
|
+
sum.minutes += item.quantity;
|
|
71
|
+
sum.grossUsd += item.grossAmount ?? item.netAmount;
|
|
72
|
+
sum.netUsd += item.netAmount;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const byRepository = {};
|
|
76
|
+
for (const repository of options.repositories) {
|
|
77
|
+
byRepository[repository] = [...(sums.get(repository)?.values() ?? [])]
|
|
78
|
+
.map((sum) => ({ ...sum, grossUsd: Math.round(sum.grossUsd * 10_000) / 10_000, netUsd: Math.round(sum.netUsd * 10_000) / 10_000 }))
|
|
79
|
+
.sort((a, b) => b.minutes - a.minutes);
|
|
80
|
+
}
|
|
81
|
+
return { ok: true, byRepository };
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,6GAA6G;AAC7G,0BAA0B;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,mFAAmF;AACnF,MAAM,UAAU,mBAAmB,CAAC,KAAyB;IAC3D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAC5D,MAAM,KAAK,GAAG,yCAAyC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3E,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,6DAA6D,KAAK,GAAG,EAAE,CAAC;IACjI,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAmB,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACrF,CAAC;AAED,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC;IACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,QAAQ,EAAE,CAAC,C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AAE,CAAC;IACrD,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QAC9C,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;aACnE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC;aAClI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type FetchLike } from "../github.js";
|
|
2
|
+
export interface CommandContext {
|
|
3
|
+
cwd: string;
|
|
4
|
+
env: NodeJS.ProcessEnv;
|
|
5
|
+
write: (text: string) => void;
|
|
6
|
+
writeError: (text: string) => void;
|
|
7
|
+
/** Replaces the network in tests. */
|
|
8
|
+
fetch?: FetchLike;
|
|
9
|
+
now?: () => Date;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_DAYS = 7;
|
|
12
|
+
export declare const USAGE: string;
|
|
13
|
+
export declare function parseRepositories(values: readonly string[] | undefined, env: NodeJS.ProcessEnv): {
|
|
14
|
+
ok: true;
|
|
15
|
+
repositories: string[];
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
error: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function parsePeriod(values: {
|
|
21
|
+
days?: string;
|
|
22
|
+
from?: string;
|
|
23
|
+
to?: string;
|
|
24
|
+
}, now: Date): {
|
|
25
|
+
ok: true;
|
|
26
|
+
from: Date;
|
|
27
|
+
to: Date;
|
|
28
|
+
} | {
|
|
29
|
+
ok: false;
|
|
30
|
+
error: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function runCommand(argv: string[], context: CommandContext): Promise<number>;
|
|
33
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/cli/command.ts"],"names":[],"mappings":"AAKA,OAAO,EAAuC,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAKnF,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,qCAAqC;IACrC,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,eAAO,MAAM,YAAY,IAAI,CAAC;AAI9B,eAAO,MAAM,KAAK,QAY8E,CAAC;AAYjG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,YAAY,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAMpK;AAOD,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,EAAE,IAAI,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,IAAI,CAAC;IAAC,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAe/J;AAwHD,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAezF"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import { getBillingUsage, parseBillingAccount } from "../billing.js";
|
|
5
|
+
import { collectRepository, parseRunCache } from "../collect.js";
|
|
6
|
+
import { createGithubClient, DEFAULT_RESERVE } from "../github.js";
|
|
7
|
+
import { parsePriceOverrides } from "../prices.js";
|
|
8
|
+
import { publishReport } from "../publish.js";
|
|
9
|
+
import { buildReport, JSON_FILE, MARKDOWN_FILE, renderMarkdown } from "../report.js";
|
|
10
|
+
export const DEFAULT_DAYS = 7;
|
|
11
|
+
const DAY_MS = 86_400_000;
|
|
12
|
+
const REPOSITORY = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
13
|
+
export const USAGE = `Usage:
|
|
14
|
+
softure-ci-usage report [--repository <owner/name>[,<owner/name>…]] [--days ${String(DEFAULT_DAYS)} | --from <date> --to <date>]
|
|
15
|
+
[--out-dir .] [--prices <json>] [--ubicloud-premium] [--billing org:<name>|user:<name>]
|
|
16
|
+
[--cache <file>] [--reserve ${String(DEFAULT_RESERVE)}]
|
|
17
|
+
softure-ci-usage publish [--repository <owner/name>] [--report-dir .] [--run-url <url>]
|
|
18
|
+
|
|
19
|
+
report reads the finished workflow runs of the period through the Actions API and writes ${JSON_FILE} and ${MARKDOWN_FILE}:
|
|
20
|
+
billable minutes and estimated USD per repository, workflow and job, on GitHub-hosted, Ubicloud and other runners.
|
|
21
|
+
publish keeps the issue labelled ci-usage in the repository up to date with the report and comments the run's totals.
|
|
22
|
+
|
|
23
|
+
The token comes from GITHUB_TOKEN (or GH_TOKEN): "Actions: read" on every repository for report (plus organization
|
|
24
|
+
"Administration: read" or user "Plan: read" for --billing), "Issues: write" for publish. The repository defaults to
|
|
25
|
+
GITHUB_REPOSITORY. A report that could not count every run is marked partial and still exits 0.`;
|
|
26
|
+
function getToken(env) {
|
|
27
|
+
const token = env.GITHUB_TOKEN ?? env.GH_TOKEN;
|
|
28
|
+
return token === undefined || token === "" ? undefined : token;
|
|
29
|
+
}
|
|
30
|
+
/** An empty value means "not set", so a workflow can always pass its input through. */
|
|
31
|
+
function toOptional(value) {
|
|
32
|
+
return value === undefined || value.trim() === "" ? undefined : value.trim();
|
|
33
|
+
}
|
|
34
|
+
export function parseRepositories(values, env) {
|
|
35
|
+
const listed = (values ?? []).flatMap((value) => value.split(/[\s,]+/)).filter((value) => value !== "");
|
|
36
|
+
const repositories = listed.length > 0 ? [...new Set(listed)] : env.GITHUB_REPOSITORY ? [env.GITHUB_REPOSITORY] : [];
|
|
37
|
+
if (repositories.length === 0)
|
|
38
|
+
return { ok: false, error: "--repository is required outside GitHub Actions (owner/name)" };
|
|
39
|
+
const wrong = repositories.find((repository) => !REPOSITORY.test(repository));
|
|
40
|
+
return wrong === undefined ? { ok: true, repositories } : { ok: false, error: `--repository must be owner/name, not "${wrong}"` };
|
|
41
|
+
}
|
|
42
|
+
function parseDate(name, value) {
|
|
43
|
+
const date = new Date(/^\d{4}-\d{2}-\d{2}$/.test(value) ? `${value}T00:00:00Z` : value);
|
|
44
|
+
return Number.isNaN(date.getTime()) ? `--${name} must be a date (YYYY-MM-DD) or an ISO time, not "${value}"` : date;
|
|
45
|
+
}
|
|
46
|
+
export function parsePeriod(values, now) {
|
|
47
|
+
const fromValue = toOptional(values.from);
|
|
48
|
+
const toValue = toOptional(values.to);
|
|
49
|
+
if (fromValue !== undefined || toValue !== undefined) {
|
|
50
|
+
if (fromValue === undefined)
|
|
51
|
+
return { ok: false, error: "--to needs --from" };
|
|
52
|
+
const from = parseDate("from", fromValue);
|
|
53
|
+
if (typeof from === "string")
|
|
54
|
+
return { ok: false, error: from };
|
|
55
|
+
const to = toValue === undefined ? now : parseDate("to", toValue);
|
|
56
|
+
if (typeof to === "string")
|
|
57
|
+
return { ok: false, error: to };
|
|
58
|
+
return from < to ? { ok: true, from, to } : { ok: false, error: "--from must be before --to" };
|
|
59
|
+
}
|
|
60
|
+
const daysValue = toOptional(values.days);
|
|
61
|
+
const days = daysValue === undefined ? DEFAULT_DAYS : Number(daysValue);
|
|
62
|
+
if (!Number.isInteger(days) || days < 1 || days > 31)
|
|
63
|
+
return { ok: false, error: `--days must be a whole number from 1 to 31, not "${String(daysValue)}"` };
|
|
64
|
+
return { ok: true, from: new Date(now.getTime() - days * DAY_MS), to: now };
|
|
65
|
+
}
|
|
66
|
+
function readCache(path) {
|
|
67
|
+
if (path === undefined || !existsSync(path))
|
|
68
|
+
return parseRunCache(null);
|
|
69
|
+
return parseRunCache(readFileSync(path, "utf8"));
|
|
70
|
+
}
|
|
71
|
+
function writeFile(path, text) {
|
|
72
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
73
|
+
writeFileSync(path, text);
|
|
74
|
+
}
|
|
75
|
+
async function runReport(args, context) {
|
|
76
|
+
const { values } = parseArgs({
|
|
77
|
+
args,
|
|
78
|
+
options: {
|
|
79
|
+
repository: { type: "string", multiple: true },
|
|
80
|
+
days: { type: "string" },
|
|
81
|
+
from: { type: "string" },
|
|
82
|
+
to: { type: "string" },
|
|
83
|
+
"out-dir": { type: "string", default: "." },
|
|
84
|
+
prices: { type: "string" },
|
|
85
|
+
"ubicloud-premium": { type: "boolean", default: false },
|
|
86
|
+
billing: { type: "string" },
|
|
87
|
+
cache: { type: "string" },
|
|
88
|
+
reserve: { type: "string" },
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const now = context.now?.() ?? new Date();
|
|
92
|
+
const repositories = parseRepositories(values.repository, context.env);
|
|
93
|
+
const period = parsePeriod(values, now);
|
|
94
|
+
const prices = parsePriceOverrides(values.prices);
|
|
95
|
+
const billing = parseBillingAccount(values.billing);
|
|
96
|
+
const reserve = toOptional(values.reserve) === undefined ? DEFAULT_RESERVE : Number(values.reserve);
|
|
97
|
+
const errors = [
|
|
98
|
+
repositories.ok ? null : repositories.error,
|
|
99
|
+
period.ok ? null : period.error,
|
|
100
|
+
prices.ok ? null : prices.error,
|
|
101
|
+
billing === null || billing.ok ? null : billing.error,
|
|
102
|
+
Number.isInteger(reserve) && reserve >= 0 ? null : `--reserve must be a whole number of requests, not "${String(values.reserve)}"`,
|
|
103
|
+
].filter((error) => error !== null);
|
|
104
|
+
const token = getToken(context.env);
|
|
105
|
+
if (token === undefined)
|
|
106
|
+
errors.push("GITHUB_TOKEN (or GH_TOKEN) is not set");
|
|
107
|
+
if (errors.length > 0 || !repositories.ok || !period.ok || !prices.ok || token === undefined) {
|
|
108
|
+
context.writeError(`${errors.join("\n")}\n\n${USAGE}\n`);
|
|
109
|
+
return 1;
|
|
110
|
+
}
|
|
111
|
+
const client = createGithubClient({ token, reserve, ...(context.fetch ? { fetch: context.fetch } : {}) });
|
|
112
|
+
const cachePath = toOptional(values.cache) === undefined ? undefined : resolve(context.cwd, String(values.cache));
|
|
113
|
+
const cache = readCache(cachePath);
|
|
114
|
+
const collected = [];
|
|
115
|
+
for (const repository of repositories.repositories) {
|
|
116
|
+
collected.push(await collectRepository({ client, repository, from: period.from, to: period.to, cache }));
|
|
117
|
+
}
|
|
118
|
+
let billingResult = null;
|
|
119
|
+
if (billing?.ok) {
|
|
120
|
+
const result = await getBillingUsage({ client, account: billing.account, repositories: repositories.repositories, from: period.from, to: period.to });
|
|
121
|
+
billingResult = result.ok ? { byRepository: result.byRepository } : { error: result.error };
|
|
122
|
+
}
|
|
123
|
+
const report = buildReport({
|
|
124
|
+
collected,
|
|
125
|
+
from: period.from,
|
|
126
|
+
to: period.to,
|
|
127
|
+
generatedAt: now,
|
|
128
|
+
priceOptions: { prices: prices.prices, ubicloudPremium: values["ubicloud-premium"] },
|
|
129
|
+
billing: billingResult,
|
|
130
|
+
});
|
|
131
|
+
const outDir = resolve(context.cwd, values["out-dir"]);
|
|
132
|
+
writeFile(join(outDir, JSON_FILE), `${JSON.stringify(report, null, 2)}\n`);
|
|
133
|
+
writeFile(join(outDir, MARKDOWN_FILE), renderMarkdown(report));
|
|
134
|
+
if (cachePath !== undefined) {
|
|
135
|
+
const merged = { version: 1, runs: Object.assign({}, ...collected.map((result) => result.cache.runs)) };
|
|
136
|
+
writeFile(cachePath, JSON.stringify(merged));
|
|
137
|
+
}
|
|
138
|
+
for (const repository of report.repositories) {
|
|
139
|
+
const usd = repository.usd === null ? "unknown" : repository.usd.toFixed(2);
|
|
140
|
+
context.write(repository.error === null ? `${repository.repository}: ${String(repository.minutes)} minutes, ${usd} USD, ${String(repository.runs)} runs${repository.partial.length > 0 ? " (partial)" : ""}\n` : `${repository.repository}: not read (${repository.error})\n`);
|
|
141
|
+
}
|
|
142
|
+
context.write(`requests: ${String(client.getRequestCount())}, rate limit left: ${String(client.getRemaining() ?? "unknown")}\n`);
|
|
143
|
+
return report.repositories.every((repository) => repository.error !== null) ? 1 : 0;
|
|
144
|
+
}
|
|
145
|
+
async function runPublish(args, context) {
|
|
146
|
+
const { values } = parseArgs({
|
|
147
|
+
args,
|
|
148
|
+
options: {
|
|
149
|
+
repository: { type: "string" },
|
|
150
|
+
"report-dir": { type: "string", default: "." },
|
|
151
|
+
"run-url": { type: "string" },
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
const repositories = parseRepositories(values.repository === undefined ? undefined : [values.repository], context.env);
|
|
155
|
+
const token = getToken(context.env);
|
|
156
|
+
const dir = resolve(context.cwd, values["report-dir"]);
|
|
157
|
+
const errors = [];
|
|
158
|
+
if (!repositories.ok)
|
|
159
|
+
errors.push(repositories.error);
|
|
160
|
+
else if (repositories.repositories.length !== 1)
|
|
161
|
+
errors.push("publish takes one --repository");
|
|
162
|
+
if (token === undefined)
|
|
163
|
+
errors.push("GITHUB_TOKEN (or GH_TOKEN) is not set");
|
|
164
|
+
if (!existsSync(join(dir, JSON_FILE)) || !existsSync(join(dir, MARKDOWN_FILE)))
|
|
165
|
+
errors.push(`${JSON_FILE} and ${MARKDOWN_FILE} are not in ${dir}: run report first`);
|
|
166
|
+
const repository = repositories.ok ? repositories.repositories[0] : undefined;
|
|
167
|
+
if (errors.length > 0 || token === undefined || repository === undefined) {
|
|
168
|
+
context.writeError(`${errors.join("\n")}\n\n${USAGE}\n`);
|
|
169
|
+
return 1;
|
|
170
|
+
}
|
|
171
|
+
const report = JSON.parse(readFileSync(join(dir, JSON_FILE), "utf8"));
|
|
172
|
+
const markdown = readFileSync(join(dir, MARKDOWN_FILE), "utf8");
|
|
173
|
+
const { GITHUB_SERVER_URL: server, GITHUB_REPOSITORY: current, GITHUB_RUN_ID: runId } = context.env;
|
|
174
|
+
const runUrl = toOptional(values["run-url"]) ?? (server && current && runId ? `${server}/${current}/actions/runs/${runId}` : `https://github.com/${repository}/actions`);
|
|
175
|
+
const client = createGithubClient({ token, ...(context.fetch ? { fetch: context.fetch } : {}) });
|
|
176
|
+
const result = await publishReport({ client, repository, report, markdown, runUrl });
|
|
177
|
+
if (!result.ok) {
|
|
178
|
+
context.writeError(`publishing the report to ${repository} failed: ${result.error}\n`);
|
|
179
|
+
return 1;
|
|
180
|
+
}
|
|
181
|
+
context.write(`${result.created ? "created" : "updated"} ${result.url}\n`);
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
export async function runCommand(argv, context) {
|
|
185
|
+
const [command, ...args] = argv;
|
|
186
|
+
try {
|
|
187
|
+
if (command === "report")
|
|
188
|
+
return await runReport(args, context);
|
|
189
|
+
if (command === "publish")
|
|
190
|
+
return await runPublish(args, context);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
// parseArgs throws on an unknown or malformed option: a usage error, not a bug.
|
|
194
|
+
if (error instanceof TypeError && "code" in error && String(error.code).startsWith("ERR_PARSE_ARGS")) {
|
|
195
|
+
context.writeError(`${error.message}\n\n${USAGE}\n`);
|
|
196
|
+
return 1;
|
|
197
|
+
}
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
context.writeError(`${command === undefined ? "No command given." : `Unknown command "${command}".`}\n\n${USAGE}\n`);
|
|
201
|
+
return 1;
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/cli/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAqC,MAAM,eAAe,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAkB,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAA+C,MAAM,cAAc,CAAC;AAYlI,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAC9B,MAAM,MAAM,GAAG,UAAU,CAAC;AAC1B,MAAM,UAAU,GAAG,oCAAoC,CAAC;AAExD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,QAAQ;YAAE,OAAO,MAAM,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAChE,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,MAAM,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,gFAAgF;QAChF,IAAI,KAAK,YAAY,SAAS,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACrG,OAAO,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC;YACrD,OAAO,CAAC,CAAC;QACX,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,oBAAoB,OAAO,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC;IACrH,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":""}
|
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Entry point of the `softure-ci-usage` bin; the behaviour is in command.ts.
|
|
3
|
+
import { runCommand } from "./command.js";
|
|
4
|
+
process.exitCode = await runCommand(process.argv.slice(2), {
|
|
5
|
+
cwd: process.cwd(),
|
|
6
|
+
env: process.env,
|
|
7
|
+
write: (text) => process.stdout.write(text),
|
|
8
|
+
writeError: (text) => process.stderr.write(text),
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AACA,6EAA6E;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,CAAC,QAAQ,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACzD,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;IAClB,GAAG,EAAE,OAAO,CAAC,GAAG;IAChB,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;IAC3C,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;CACjD,CAAC,CAAC"}
|