export type ExpressionSource = { readonly id: string; }; /** Values that can appear in ternary `.then()` / `.else()` branches. */ export type TernaryValue = string | number | boolean | ExpressionValue; /** * An expression that resolves to a value inside a GitHub Actions workflow. * Supports fluent comparison methods that produce Conditions. */ export declare class ExpressionValue { #private; readonly source: ExpressionSource | undefined; constructor(expression: string, source?: ExpressionSource | ReadonlySet); /** all expression sources referenced by this value */ get allSources(): ReadonlySet; /** raw expression text without `${{ }}` wrapping */ get expression(): string; equals(value: string | number | boolean): Condition; notEquals(value: string | number | boolean): Condition; startsWith(prefix: string): Condition; contains(substring: string): Condition; not(): Condition; /** concatenate this value with additional strings, numbers, or expressions */ concat(...parts: ConcatPart[]): ExpressionValue; endsWith(suffix: string): Condition; greaterThan(value: number): Condition; greaterThanOrEqual(value: number): Condition; lessThan(value: number): Condition; lessThanOrEqual(value: number): Condition; /** serialize this value as JSON */ toJSON(): ExpressionValue; /** wrap in `${{ }}` for use in YAML */ toString(): string; } /** * A boolean condition used in `if` fields. Supports fluent `.and()`, `.or()`, * `.not()` composition. Tracks all ExpressionSources referenced so that * dependencies can be inferred automatically. */ export declare abstract class Condition { readonly sources: ReadonlySet; constructor(sources: ReadonlySet); and(other: Condition | boolean): Condition; or(other: Condition | boolean): Condition; not(): Condition; /** * Starts a ternary expression: `condition && trueValue || falseValue`. * * ```ts * const runner = os.equals("linux").then("ubuntu-latest").else("macos-latest"); * // => matrix.os == 'linux' && 'ubuntu-latest' || 'macos-latest' * ``` */ then(value: TernaryValue): ThenBuilder; /** * Returns the flat AND terms of this condition. Used by condition * simplification to detect absorption (A || A && B → A). */ getAndTerms(): string[]; /** returns the flat AND children of this condition as Condition objects */ flattenAnd(): Condition[]; /** returns the flat OR children of this condition as Condition objects */ flattenOr(): Condition[]; /** returns true if this condition always evaluates to true */ isAlwaysTrue(): boolean; /** returns true if this condition always evaluates to false */ isAlwaysFalse(): boolean; /** returns true if this condition could possibly evaluate to true */ isPossiblyTrue(): boolean; /** render without `${{ }}` wrapping */ abstract toExpression(): string; /** render wrapped in `${{ }}` for YAML `if` fields */ toString(): string; } /** comparison operators supported in GitHub Actions expressions */ export type ComparisonOp = "==" | "!=" | ">" | ">=" | "<" | "<="; /** `left op right` where op is ==, !=, >, >=, <, or <= */ export declare class ComparisonCondition extends Condition { #private; constructor(left: string, op: ComparisonOp, right: string | number | boolean, sources: ReadonlySet); not(): Condition; toExpression(): string; } /** `fn(arg1, arg2, ...)` */ export declare class FunctionCallCondition extends Condition { #private; constructor(fn: string, args: string[], sources: ReadonlySet); toExpression(): string; } /** wraps a raw expression string as a Condition */ export declare class RawCondition extends Condition { #private; constructor(expression: string, sources: ReadonlySet); isAlwaysTrue(): boolean; isAlwaysFalse(): boolean; not(): Condition; toExpression(): string; } /** Creates an ExpressionValue from a raw expression string. */ export declare function expr(expression: string): ExpressionValue; /** Common condition helpers for GitHub Actions workflows. */ export declare const conditions: { /** A condition that is always true. Simplifies away in `.and()` / `.or()`. */ readonly isTrue: () => Condition; /** A condition that is always false. Simplifies away in `.and()` / `.or()`. */ readonly isFalse: () => Condition; /** Status check functions for use in step/job `if` fields. */ readonly status: { /** Run regardless of previous step outcome. */ readonly always: () => Condition; /** Run only when all previous steps succeeded (default behavior). */ readonly success: () => Condition; /** Run only when a previous step has failed. */ readonly failure: () => Condition; /** Run only when the workflow was cancelled. */ readonly cancelled: () => Condition; }; /** * Check if the ref is a tag. Without arguments, matches any tag. * With a tag name, matches that specific tag. * * ```ts * conditions.isTag() // startsWith(github.ref, 'refs/tags/') * conditions.isTag("v1.0.0") // github.ref == 'refs/tags/v1.0.0' * ``` */ readonly isTag: (tag?: string) => Condition; /** * Check if the ref is a specific branch. * * ```ts * conditions.isBranch("main") // github.ref == 'refs/heads/main' * ``` */ readonly isBranch: (branch: string) => Condition; /** * Check the event that triggered the workflow. * * ```ts * conditions.isEvent("pull_request") // github.event_name == 'pull_request' * ``` */ readonly isEvent: (event: string) => Condition; /** * Check if the event is a pull request. * * ```ts * conditions.isPr() // github.event_name == 'pull_request' * ``` */ readonly isPr: () => Condition; /** * Check the repository (owner/name). * * ```ts * conditions.isRepository("denoland/deno") // github.repository == 'denoland/deno' * ``` */ readonly isRepository: (repo: string) => Condition; /** * Check if the pull request is a draft. * * ```ts * conditions.isDraftPr() // github.event.pull_request.draft == true * ``` */ readonly isDraftPr: () => Condition; /** * Check if the pull request has a specific label. * * ```ts * conditions.hasLabel("ci-full") // contains(github.event.pull_request.labels.*.name, 'ci-full') * ``` */ readonly hasPrLabel: (label: string) => Condition; /** * Check the runner operating system. * * ```ts * conditions.isRunnerOs("Linux") // runner.os == 'Linux' * conditions.isRunnerOs("macOS") // runner.os == 'macOS' * conditions.isRunnerOs("Windows") // runner.os == 'Windows' * ``` */ readonly isRunnerOs: (os: "Linux" | "macOS" | "Windows") => Condition; /** * Check the runner architecture. * * ```ts * conditions.isRunnerArch("X86") // runner.arch == 'X86' * conditions.isRunnerArch("X64") // runner.arch == 'X64' * conditions.isRunnerArch("ARM") // runner.arch == 'ARM' * conditions.isRunnerArch("ARM64") // runner.arch == 'ARM64' * ``` */ readonly isRunnerArch: (arch: "X86" | "X64" | "ARM" | "ARM64") => Condition; }; /** Checks if a condition-like value always evaluates to true. */ export declare function isAlwaysTrue(c: Condition | ExpressionValue | string): boolean; /** Checks if a condition-like value always evaluates to false. */ export declare function isAlwaysFalse(c: Condition | ExpressionValue | string): boolean; export declare function formatLiteral(value: string | number | boolean): string; export declare function sourcesFrom(...sourceables: ({ source?: ExpressionSource; } | Condition)[]): ReadonlySet; interface TernaryBranch { condition: Condition; value: TernaryValue; } /** * Intermediate builder after `.then(value)`. Call `.else()` to produce the * final `ExpressionValue`, or `.elseIf()` to add another branch. */ export declare class ThenBuilder { #private; constructor(branches: TernaryBranch[], sources: ReadonlySet); /** Add another conditional branch. */ elseIf(condition: Condition): ElseIfBuilder; /** * Finalize the ternary with a default value. * * ```ts * os.equals("linux").then("ubuntu-latest").else("macos-latest") * // => matrix.os == 'linux' && 'ubuntu-latest' || 'macos-latest' * ``` */ else(value: TernaryValue): ExpressionValue; } /** * Intermediate builder after `.elseIf(condition)`. Call `.then()` to provide * the value for this branch. */ export declare class ElseIfBuilder { #private; constructor(branches: TernaryBranch[], sources: Set, condition: Condition); /** Provide the value for this branch. */ then(value: TernaryValue): ThenBuilder; } /** a part of a concatenation: plain string, number, or expression */ export type ConcatPart = string | number | ExpressionValue; /** * Concatenates strings, numbers, and expressions into a single value. * Expression parts are wrapped in `${{ }}` when serialized for YAML, * and use the `format()` function when used inside expression contexts. * * ```ts * const name = concat("build-", expr("matrix.os")); * name.toString() // => "build-${{ matrix.os }}" * name.expression // => "format('build-{0}', matrix.os)" * * const full = concat("build-", expr("matrix.os"), "-", expr("matrix.arch")); * full.toString() // => "build-${{ matrix.os }}-${{ matrix.arch }}" * ``` */ export declare function concat(...parts: ConcatPart[]): ExpressionValue; /** * Parses a JSON string into an object/value. Wraps in `fromJSON()` in GitHub * Actions expression contexts. * * ```ts * const matrix = fromJSON(expr("needs.setup.outputs.matrix")); * matrix.toString() // => "${{ fromJSON(needs.setup.outputs.matrix) }}" * ``` */ export declare function fromJSON(value: string | ExpressionValue): ExpressionValue; /** * Serializes a value to JSON. Wraps in `toJSON()` in GitHub Actions expression * contexts. * * ```ts * const json = toJSON(expr("github.event")); * json.toString() // => "${{ toJSON(github.event) }}" * ``` */ export declare function toJSON(value: ExpressionValue): ExpressionValue; /** Computes a hash of files matching the given glob patterns. */ export declare function hashFiles(...patterns: (string | ExpressionValue)[]): ExpressionValue; /** * Joins an array expression with an optional separator. Wraps in `join()` in * GitHub Actions expression contexts. * * ```ts * const labels = join(expr("github.event.pull_request.labels.*.name"), ", "); * labels.toString() // => "${{ join(github.event.pull_request.labels.*.name, ', ') }}" * ``` */ export declare function join(value: ExpressionValue, separator?: string): ExpressionValue; /** Creates an ExpressionValue or Condition from a literal value. */ export declare function literal(value: boolean): Condition; export declare function literal(value: string | number): ExpressionValue; /** Maps a property type to Condition (for booleans/conditions) or ExpressionValue (for values). */ export type ExprOf = [T] extends [boolean | Condition] ? Condition : ExpressionValue; /** Maps all properties of an object to their expression/condition form. */ export type ExprMap> = { readonly [K in keyof T & string]: ExprOf; }; /** * Converts an object with plain values into an object with typed * Condition/ExpressionValue properties. Booleans become Conditions, * strings/numbers become ExpressionValues that serialize inline. */ export declare function defineExprObj>(obj: T): ExprMap; export {}; //# sourceMappingURL=expression.d.ts.map