Buckets:
| // Copyright (c) 2026 the Zuke contributors | |
| // SPDX-License-Identifier: MIT | |
| /** | |
| * `CodecovTasks` — a typed wrapper for the Codecov CLI (`codecovcli`), in the | |
| * same settings-lambda style as the other Zuke tool wrappers. | |
| * | |
| * `upload` runs `codecovcli upload-process` — the recommended one-shot that | |
| * creates the commit and report records and uploads the coverage files in a | |
| * single step. Point it at one or more reports and tag them with flags: | |
| * | |
| * ```ts | |
| * import { CodecovTasks } from "@zuke/codecov"; | |
| * await CodecovTasks.upload((s) => s.files("cov.lcov").flags("unit")); | |
| * ``` | |
| * | |
| * The upload token is read from `CODECOV_TOKEN` in the environment, so it never | |
| * lands in argv. Arguments stay a discrete argv array end-to-end — never a | |
| * concatenated shell string — so command construction is injection-free. | |
| * | |
| * @module | |
| */ | |
| import { type Configure, runSettings, ToolSettings } from "@zuke/core/tooling"; | |
| import type { CommandOutput } from "@zuke/core/shell"; | |
| /** Settings for `codecovcli upload-process`. */ | |
| export class CodecovUploadSettings extends ToolSettings { | |
| #files: string[] = []; | |
| #flags: string[] = []; | |
| #plugins: string[] = []; | |
| #slug?: string; | |
| #sha?: string; | |
| #branch?: string; | |
| #pr?: string; | |
| #gitService?: string; | |
| #name?: string; | |
| #dir?: string; | |
| #networkRootFolder?: string; | |
| #reportType?: string; | |
| #disableSearch = false; | |
| #disableTelem = false; | |
| #handleNoReportsFound = false; | |
| #failOnError = false; | |
| #dryRun = false; | |
| /** The Codecov CLI binary this settings class drives. */ | |
| protected override defaultTool(): string { | |
| return "codecovcli"; | |
| } | |
| /** A coverage report file to upload (`--file`). Repeatable. */ | |
| files(...paths: string[]): this { | |
| this.#files.push(...paths); | |
| return this; | |
| } | |
| /** Tag the uploaded reports with a flag (`--flag`). Repeatable. */ | |
| flags(...names: string[]): this { | |
| this.#flags.push(...names); | |
| return this; | |
| } | |
| /** Run an upload plugin, e.g. `gcov` or `noop` (`--plugin`). Repeatable. */ | |
| plugins(...names: string[]): this { | |
| this.#plugins.push(...names); | |
| return this; | |
| } | |
| /** | |
| * Repository upload token. | |
| * | |
| * Routed through `CODECOV_TOKEN` rather than `--token`, because a child's | |
| * argv is world-readable: `ps` or `/proc/<pid>/cmdline` shows it to every | |
| * other user on the host and to every process the build starts. The | |
| * environment of another process is not readable the same way, and the CLI | |
| * documents the variable, so nothing is given up by preferring it. | |
| * | |
| * Also registered with the run's redactor, so a value that reaches the | |
| * output some other way — an error message quoting a URL, a tool echoing its | |
| * own configuration — is masked there too. | |
| */ | |
| token(value: string): this { | |
| this.env({ CODECOV_TOKEN: value }); | |
| this.markSecret(value); | |
| return this; | |
| } | |
| /** Repository slug as `OWNER/REPO` (`--slug`). */ | |
| slug(value: string): this { | |
| this.#slug = value; | |
| return this; | |
| } | |
| /** Commit SHA the coverage belongs to (`--sha`). */ | |
| sha(value: string): this { | |
| this.#sha = value; | |
| return this; | |
| } | |
| /** Branch the coverage belongs to (`--branch`). */ | |
| branch(value: string): this { | |
| this.#branch = value; | |
| return this; | |
| } | |
| /** Pull request number the coverage belongs to (`--pr`). */ | |
| pullRequest(value: string | number): this { | |
| this.#pr = String(value); | |
| return this; | |
| } | |
| /** Git host the repo lives on, e.g. `github` (`--git-service`). */ | |
| gitService(value: string): this { | |
| this.#gitService = value; | |
| return this; | |
| } | |
| /** A custom display name for this upload (`--name`). */ | |
| name(value: string): this { | |
| this.#name = value; | |
| return this; | |
| } | |
| /** Directory to search for coverage reports (`--dir`). */ | |
| dir(value: string): this { | |
| this.#dir = value; | |
| return this; | |
| } | |
| /** Root folder used to resolve report file paths (`--network-root-folder`). */ | |
| networkRootFolder(value: string): this { | |
| this.#networkRootFolder = value; | |
| return this; | |
| } | |
| /** Report kind: `coverage` (default) or `test_results` (`--report-type`). */ | |
| reportType(value: string): this { | |
| this.#reportType = value; | |
| return this; | |
| } | |
| /** | |
| * Keep the CLI from reporting its own errors to Codecov's Sentry | |
| * (`--disable-telem`). A global flag, so it is emitted before the subcommand. | |
| */ | |
| disableTelem(): this { | |
| this.#disableTelem = true; | |
| return this; | |
| } | |
| /** Upload only the named files, skipping the auto-search (`--disable-search`). */ | |
| disableSearch(): this { | |
| this.#disableSearch = true; | |
| return this; | |
| } | |
| /** Succeed instead of erroring when no reports are found (`--handle-no-reports-found`). */ | |
| handleNoReportsFound(): this { | |
| this.#handleNoReportsFound = true; | |
| return this; | |
| } | |
| /** Exit non-zero when the upload fails (`--fail-on-error`). */ | |
| failOnError(): this { | |
| this.#failOnError = true; | |
| return this; | |
| } | |
| /** Print what would be uploaded without sending anything (`--dry-run`). */ | |
| dryRun(): this { | |
| this.#dryRun = true; | |
| return this; | |
| } | |
| /** Assemble the `codecovcli upload-process` argv. */ | |
| protected override buildArgs(): string[] { | |
| const argv = this.#disableTelem ? ["--disable-telem"] : []; | |
| argv.push("upload-process"); | |
| if (this.#slug !== undefined) argv.push("--slug", this.#slug); | |
| if (this.#sha !== undefined) argv.push("--sha", this.#sha); | |
| if (this.#branch !== undefined) argv.push("--branch", this.#branch); | |
| if (this.#pr !== undefined) argv.push("--pr", this.#pr); | |
| if (this.#gitService !== undefined) { | |
| argv.push("--git-service", this.#gitService); | |
| } | |
| if (this.#name !== undefined) argv.push("--name", this.#name); | |
| if (this.#dir !== undefined) argv.push("--dir", this.#dir); | |
| if (this.#networkRootFolder !== undefined) { | |
| argv.push("--network-root-folder", this.#networkRootFolder); | |
| } | |
| if (this.#reportType !== undefined) { | |
| argv.push("--report-type", this.#reportType); | |
| } | |
| for (const file of this.#files) argv.push("--file", file); | |
| for (const flag of this.#flags) argv.push("--flag", flag); | |
| for (const plugin of this.#plugins) argv.push("--plugin", plugin); | |
| if (this.#disableSearch) argv.push("--disable-search"); | |
| if (this.#handleNoReportsFound) argv.push("--handle-no-reports-found"); | |
| if (this.#failOnError) argv.push("--fail-on-error"); | |
| if (this.#dryRun) argv.push("--dry-run"); | |
| return argv; | |
| } | |
| } | |
| /** The shape of {@link CodecovTasks}. */ | |
| export interface CodecovTasksApi { | |
| /** Upload coverage reports: `codecovcli upload-process`. */ | |
| upload(configure?: Configure<CodecovUploadSettings>): Promise<CommandOutput>; | |
| } | |
| /** Typed task functions for the Codecov CLI. */ | |
| export const CodecovTasks: CodecovTasksApi = { | |
| upload(configure?: Configure<CodecovUploadSettings>): Promise<CommandOutput> { | |
| return runSettings(new CodecovUploadSettings(), configure); | |
| }, | |
| }; | |
Xet Storage Details
- Size:
- 6.92 kB
- Xet hash:
- b507f9277413253f16591641c1587403b138ec4a60a92693d4c835dbb614ef99
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.