@factorialco/gat
Advanced tools
Comparing version 0.0.2 to 0.0.3
import { Workflow } from "./workflow"; | ||
import { RunStep, UseStep, ConcurrencyGroup, JobOptions, Matrix, Service } from "./job"; | ||
export { Workflow, RunStep, UseStep, ConcurrencyGroup, JobOptions, Matrix, Service, }; | ||
import { ConcurrencyGroup, JobOptions, Matrix, Service } from "./job"; | ||
import { RunStep, UseStep, BaseStep } from "./step"; | ||
export { Workflow, RunStep, UseStep, BaseStep, ConcurrencyGroup, JobOptions, Matrix, Service, }; |
@@ -1,71 +0,1 @@ | ||
declare type Step = RunStep | { | ||
[Name in ActionName]: UseStep<Name>; | ||
}[ActionName]; | ||
interface BaseStep { | ||
id?: string; | ||
name?: string; | ||
env?: Record<string, string>; | ||
ifExpression?: string; | ||
workingDirectory?: string; | ||
} | ||
export interface RunStep extends BaseStep { | ||
run: string; | ||
} | ||
declare type ActionName = "actions/checkout@v3" | "actions/setup-node@v3" | "actions/upload-artifact@v3" | "actions/download-artifact@v3" | "ruby/setup-ruby@v1" | "dorny/paths-filter@v2" | "tespkg/actions-cache@v1" | "prewk/s3-cp-action@v2" | "chromaui/action@v1" | "rtCamp/action-slack-notify@v2" | "factorialco/delta-action@v3.0.0" | "factorialco/test-summary-action@v1.2.0"; | ||
export interface UseStep<T extends ActionName> extends BaseStep { | ||
uses: T; | ||
with?: StepOptions<T>; | ||
} | ||
declare type StepOptions<T extends ActionName> = T extends "actions/checkout@v3" ? { | ||
ref?: string; | ||
"fetch-depth"?: number; | ||
} : T extends "actions/setup-node@v3" ? { | ||
"node-version": string; | ||
} : T extends "actions/upload-artifact@v3" ? { | ||
name: string; | ||
path: string; | ||
} : T extends "ruby/setup-ruby@v1" ? { | ||
"ruby-version": string; | ||
"cache-version"?: number; | ||
"bundler-cache"?: boolean; | ||
"working-directory"?: string; | ||
} : T extends "dorny/paths-filter@v2" ? { | ||
filters: string; | ||
} : T extends "tespkg/actions-cache@v1" ? { | ||
endpoint: string; | ||
region: string; | ||
bucket: string; | ||
accessKey: string; | ||
secretKey: string; | ||
insecure: string; | ||
"use-fallback": boolean; | ||
path: string; | ||
key: string; | ||
"restore-keys": string; | ||
} : T extends "prewk/s3-cp-action@v2" ? { | ||
source: string; | ||
dest: string; | ||
aws_s3_endpoint: string; | ||
aws_region: string; | ||
aws_access_key_id: string; | ||
aws_secret_access_key: string; | ||
} : T extends "chromaui/action@v1" ? { | ||
workingDir: string; | ||
token: string; | ||
projectToken: string; | ||
exitZeroOnChanges?: boolean; | ||
autoAcceptChanges?: boolean; | ||
} : T extends "factorialco/delta-action@v3.0.0" ? { | ||
engine: "eslint" | "semgrep" | "rubocop"; | ||
main: string; | ||
branch: string; | ||
head_ref: string; | ||
forkpoint: string; | ||
monorepo_prefix: "frontend" | "backend"; | ||
} : T extends "factorialco/test-summary-action@v1.2.0" ? { | ||
engine: "jest" | "rspec"; | ||
reportFile: string; | ||
sha: string; | ||
} : never; | ||
declare type Runner = "standard" | "beefy" | "large" | "release" | "standard-aws" | "beefy-aws" | "large-aws" | "release-aws"; | ||
export interface ConcurrencyGroup { | ||
@@ -92,7 +22,7 @@ groupSuffix: string; | ||
} | ||
export interface JobOptions<JobNames = never> { | ||
export interface JobOptions<Step, Runner, Name> { | ||
ifExpression?: string; | ||
runsOn?: Runner; | ||
timeout?: number; | ||
dependsOn?: Array<JobNames>; | ||
dependsOn?: Array<Name>; | ||
services?: Record<string, Service>; | ||
@@ -105,6 +35,5 @@ env?: Record<string, string>; | ||
} | ||
export interface Job<JobNames> { | ||
export interface Job<Step, Runner, Name> { | ||
name: string; | ||
options: JobOptions<JobNames>; | ||
options: JobOptions<Step, Runner, Name>; | ||
} | ||
export {}; |
import { Job, JobOptions } from "./job"; | ||
import type { Event, EventName, EventOptions } from "./event"; | ||
import { BaseStep, Step } from "./step"; | ||
interface DefaultOptions { | ||
@@ -10,6 +11,6 @@ workingDirectory: string; | ||
} | ||
export declare class Workflow<JobNames = never> { | ||
export declare class Workflow<JobStep extends BaseStep = Step, Runner = "ubuntu-22.04", JobName = never> { | ||
name: string; | ||
events: Event[]; | ||
jobs: Array<Job<JobNames>>; | ||
jobs: Array<Job<JobStep, Runner, JobName>>; | ||
defaultOptions: DefaultOptions | null; | ||
@@ -20,7 +21,7 @@ env: EnvVar[]; | ||
addDefaults(options: DefaultOptions): this; | ||
addJob<JobName extends string>(name: JobName, options: JobOptions<JobNames>): Workflow<JobNames | JobName>; | ||
addMergeGatekeeperJob(dependsOn: Array<JobNames>): this; | ||
addJob<T extends string>(name: T, options: JobOptions<JobStep, Runner, JobName>): Workflow<JobStep, Runner, JobName | T>; | ||
setEnv(name: string, value: any): this; | ||
defaultRunner(): string; | ||
compile(): string; | ||
} | ||
export {}; |
@@ -29,23 +29,2 @@ "use strict"; | ||
} | ||
addMergeGatekeeperJob(dependsOn) { | ||
this.jobs = [ | ||
...this.jobs, | ||
{ | ||
name: "merge_gatekeeper", | ||
options: { | ||
ifExpression: "${{ always() }}", | ||
dependsOn, | ||
steps: [ | ||
{ | ||
workingDirectory: "${{ github.workspace }}", | ||
run: dependsOn | ||
.map((jobName) => `\${{ needs.${jobName}.result == 'success' || needs.${jobName}.result == 'skipped' }}`) | ||
.join(" && "), | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
return this; | ||
} | ||
setEnv(name, value) { | ||
@@ -55,2 +34,5 @@ this.env = [...this.env, { name, value }]; | ||
} | ||
defaultRunner() { | ||
return "ubuntu-22.04"; | ||
} | ||
compile() { | ||
@@ -74,3 +56,3 @@ const result = { | ||
if: ifExpression, | ||
"runs-on": ["self-hosted", `${runsOn ?? "standard-aws"}-runner`], | ||
"runs-on": runsOn ?? this.defaultRunner(), | ||
"timeout-minutes": timeout ?? 15, | ||
@@ -77,0 +59,0 @@ needs: dependsOn, |
@@ -11,7 +11,5 @@ "use strict"; | ||
.addJob("job1", { | ||
runsOn: "standard", | ||
steps: [{ name: "Do something", run: "exit 0" }], | ||
}) | ||
.addJob("job2", { | ||
runsOn: "standard", | ||
steps: [{ name: "Do something else", run: "exit 0" }], | ||
@@ -28,3 +26,2 @@ dependsOn: ["job1"], | ||
.addJob("job1", { | ||
runsOn: "standard", | ||
steps: [{ name: "Do something", run: "exit 0" }], | ||
@@ -42,3 +39,2 @@ }); | ||
.addJob("job1", { | ||
runsOn: "standard", | ||
steps: [{ name: "Do something", run: "exit 0" }], | ||
@@ -55,3 +51,2 @@ }); | ||
.addJob("job1", { | ||
runsOn: "standard", | ||
steps: [ | ||
@@ -66,25 +61,5 @@ { | ||
}); | ||
(0, vitest_1.it)("allows uses steps", () => { | ||
const workflow = new workflow_1.Workflow("Uses steps"); | ||
workflow | ||
.on("push") | ||
.setEnv("NODE_VERSION", "16") | ||
.setEnv("ENABLED", true) | ||
.addJob("job1", { | ||
runsOn: "standard", | ||
steps: [ | ||
{ | ||
uses: "actions/checkout@v3", | ||
with: { | ||
ref: "main", | ||
}, | ||
}, | ||
], | ||
}); | ||
(0, vitest_1.expect)(workflow.compile()).toMatchSnapshot(); | ||
}); | ||
(0, vitest_1.it)("allows using a concurrency group", () => { | ||
const workflow = new workflow_1.Workflow("Concurrency group"); | ||
workflow.on("push").addJob("job1", { | ||
runsOn: "standard", | ||
concurrency: { | ||
@@ -105,3 +80,2 @@ groupSuffix: "foo", | ||
workflow.on("push").addJob("job1", { | ||
runsOn: "standard", | ||
steps: [ | ||
@@ -161,2 +135,38 @@ { | ||
}); | ||
(0, vitest_1.it)("allows uses steps", () => { | ||
const workflow = new workflow_1.Workflow("Uses steps"); | ||
workflow | ||
.on("push") | ||
.setEnv("NODE_VERSION", "16") | ||
.setEnv("ENABLED", true) | ||
.addJob("job1", { | ||
steps: [ | ||
{ | ||
uses: "actions/checkout@v3", | ||
with: { | ||
ref: "main", | ||
}, | ||
}, | ||
], | ||
}); | ||
(0, vitest_1.expect)(workflow.compile()).toMatchSnapshot(); | ||
}); | ||
(0, vitest_1.it)("allows custom types in a workflow", () => { | ||
const workflow = new workflow_1.Workflow("With custom types"); | ||
workflow.on("push").addJob("job1", { | ||
runsOn: ["self-hosted", "standard-runner"], | ||
steps: [ | ||
{ | ||
run: "echo 'Do something'", | ||
}, | ||
{ | ||
uses: "custom-action", | ||
with: { | ||
foo: "bar", | ||
}, | ||
}, | ||
], | ||
}); | ||
(0, vitest_1.expect)(workflow.compile()).toMatchSnapshot(); | ||
}); | ||
}); |
{ | ||
"name": "@factorialco/gat", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "TODO", | ||
@@ -5,0 +5,0 @@ "bin": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16
15052
399