Complete reference for the DotGitHub TypeScript API.
- Core Types
- Construct Interface
- Workflow Constructs
- Action Constructs
- Utility Functions
- Configuration Types
The base class that all constructs extend.
abstract class GitHubConstruct {
readonly name: string;
readonly version?: string;
readonly description?: string;
validate?(stack: GitHubStack): void | Promise<void>;
describe?(): ConstructDescription | Promise<ConstructDescription>;
synthesize(stack: GitHubStack): Promise<void>;
}Represents a stack configuration and provides context for construct execution.
interface GitHubStack {
readonly name: string;
readonly config: Record<string, any>;
readonly constructs: string[];
}Metadata about a construct.
interface ConstructDescription {
name: string;
version?: string;
description?: string;
author?: string;
repository?: string;
license?: string;
keywords?: string[];
category?: string;
tags?: string[];
minDotGithubVersion?: string;
configSchema?: z.ZodSchema;
}Validates the stack configuration. Should throw an error if the configuration is invalid.
validate(stack: GitHubStack): void {
const schema = z.object({
environment: z.enum(['development', 'staging', 'production']),
timeout: z.number().min(1).max(60).default(10)
});
schema.parse(stack.config);
}Returns metadata about the construct.
describe(): ConstructDescription {
return {
name: this.name,
version: this.version,
description: this.description,
author: 'Your Name',
repository: 'https://github.com/yourusername/yourrepo',
license: 'MIT',
keywords: ['ci', 'github-actions'],
category: 'ci',
tags: ['ci', 'testing'],
minDotGithubVersion: '1.0.0'
};
}Generates workflow content for the stack.
async synthesize(stack: GitHubStack): Promise<void> {
const wf = new WorkflowConstruct(stack, 'ci', {
name: 'CI Workflow',
on: { push: { branches: ['main'] } },
jobs: {}
});
// Add jobs and steps...
}Creates and configures GitHub workflows.
class WorkflowConstruct {
constructor(stack: GitHubStack, id: string, props: WorkflowProps);
}interface WorkflowProps {
name: string;
on: WorkflowTrigger;
jobs: Record<string, JobDefinition>;
env?: Record<string, string>;
defaults?: WorkflowDefaults;
concurrency?: ConcurrencyConfig;
}interface WorkflowTrigger {
push?: {
branches?: string[];
tags?: string[];
paths?: string[];
pathsIgnore?: string[];
};
pull_request?: {
branches?: string[];
paths?: string[];
pathsIgnore?: string[];
};
schedule?: Array<{
cron: string;
}>;
workflow_dispatch?: {
inputs?: Record<string, WorkflowInput>;
};
repository_dispatch?: {
types?: string[];
};
// ... other trigger types
}Creates and configures workflow jobs.
class JobConstruct {
constructor(workflow: WorkflowConstruct, id: string, props: JobProps);
}interface JobProps {
'runs-on': string | string[];
needs?: string | string[];
if?: string;
steps: Step[];
strategy?: StrategyConfig;
env?: Record<string, string>;
defaults?: JobDefaults;
timeoutMinutes?: number;
continueOnError?: boolean;
container?: ContainerConfig;
services?: Record<string, ServiceConfig>;
}interface StrategyConfig {
matrix: Record<string, any[]>;
failFast?: boolean;
maxParallel?: number;
}Provides type-safe access to GitHub Actions.
class Actions {
constructor(stack: GitHubStack, id: string);
// Generated methods for each action
checkout(name: string, inputs?: CheckoutInputs): ActionConstruct;
setupNode(name: string, inputs?: SetupNodeInputs): ActionConstruct;
// ... other actions
}Base class for all action wrappers.
class ActionConstruct {
constructor(name: string, inputs?: Record<string, any>);
toStep(): Step;
withInputs(inputs: Record<string, any>): ActionConstruct;
}Represents a workflow step.
interface Step {
name: string;
uses?: string;
with?: Record<string, any>;
run?: string;
shell?: string;
env?: Record<string, string>;
if?: string;
continueOnError?: boolean;
timeoutMinutes?: number;
}Creates a custom step.
function createStep(
name: string,
run: string,
options?: {
shell?: string;
env?: Record<string, string>;
if?: string;
continueOnError?: boolean;
timeoutMinutes?: number;
}
): Step;Creates a run step.
function run(
name: string,
command: string,
options?: {
shell?: string;
env?: Record<string, string>;
if?: string;
continueOnError?: boolean;
timeoutMinutes?: number;
}
): Step;Creates reusable workflow definitions.
class SharedWorkflowConstruct {
constructor(stack: GitHubStack, id: string, props: SharedWorkflowProps);
}interface SharedWorkflowProps {
name: string;
description?: string;
inputs?: Record<string, WorkflowInput>;
outputs?: Record<string, WorkflowOutput>;
secrets?: Record<string, WorkflowSecret>;
jobs: Record<string, JobDefinition>;
}Main configuration interface.
interface DotGithubConfig {
version: string;
rootDir: string;
outputDir: string;
actions: DotGithubAction[];
constructs: ConstructConfig[];
stacks: StackConfig[];
options?: DotGithubOptions;
pins?: PinsConfig;
}Action configuration.
interface DotGithubAction {
orgRepo: string;
ref: string;
versionRef: string;
actionName: string;
outputPath: string;
actionPath?: string;
generateCode?: boolean;
}Construct configuration.
interface ConstructConfig {
name: string;
package: string;
config: Record<string, any>;
enabled: boolean;
}Stack configuration.
interface StackConfig {
name: string;
constructs: string[];
config: Record<string, any>;
}Action pinning configuration.
interface PinsConfig {
constructs?: Record<string, Record<string, string>>;
stacks?: Record<string, Record<string, string>>;
}interface GitHubWorkflowInput {
description: string;
required?: boolean;
default?: string | number | boolean;
type?: 'string' | 'number' | 'boolean';
}interface GitHubWorkflowOutput {
description: string;
value: string;
}interface GitHubWorkflowSecret {
description: string;
required?: boolean;
}interface CheckoutInputs {
repository?: string;
ref?: string;
token?: string;
'ssh-key'?: string;
'ssh-known-hosts'?: string;
'ssh-strict'?: boolean;
'persist-credentials'?: boolean;
path?: string;
clean?: boolean;
'fetch-depth'?: number;
lfs?: boolean;
submodules?: boolean | 'recursive';
'set-safe-directory'?: boolean;
}interface SetupNodeInputs {
'node-version'?: string;
'node-version-file'?: string;
cache?: string;
'cache-dependency-path'?: string;
'check-latest'?: boolean;
'always-auth'?: boolean;
'registry-url'?: string;
scope?: string;
token?: string;
}interface SetupPythonInputs {
'python-version'?: string;
'python-version-file'?: string;
cache?: string;
'cache-dependency-path'?: string;
token?: string;
architecture?: string;
'update-environment'?: boolean;
}Thrown when configuration validation fails.
class ValidationError extends Error {
constructor(message: string, details?: any);
}Thrown when workflow synthesis fails.
class SynthesisError extends Error {
constructor(message: string, details?: any);
}function isGitHubConstruct(obj: any): obj is GitHubConstruct;function isWorkflowConstruct(obj: any): obj is WorkflowConstruct;function isJobConstruct(obj: any): obj is JobConstruct;const DEFAULT_NODE_VERSION = '18';
const DEFAULT_PYTHON_VERSION = '3.10';
const DEFAULT_RUNNER = 'ubuntu-latest';const SUPPORTED_RUNNERS = [
'ubuntu-latest',
'ubuntu-22.04',
'ubuntu-20.04',
'windows-latest',
'windows-2022',
'macos-latest',
'macos-13',
'macos-12',
];import {
GitHubConstruct,
GitHubStack,
WorkflowConstruct,
JobConstruct,
} from '@dotgithub/core';
export class BasicConstruct extends GitHubConstruct {
readonly name = 'basic-construct';
readonly version = '1.0.0';
readonly description = 'A basic construct example';
validate(stack: GitHubStack): void {
// No validation needed
}
describe() {
return {
name: this.name,
version: this.version,
description: this.description,
};
}
async synthesize(stack: GitHubStack): Promise<void> {
const wf = new WorkflowConstruct(stack, 'ci', {
name: 'CI Workflow',
on: { push: { branches: ['main'] } },
jobs: {},
});
new JobConstruct(wf, 'test', {
'runs-on': 'ubuntu-latest',
steps: [
{
name: 'Checkout',
uses: 'actions/checkout@v4',
},
{
name: 'Run tests',
run: 'npm test',
},
],
});
}
}
export default new BasicConstruct();import { z } from 'zod';
import {
GitHubConstruct,
GitHubStack,
WorkflowConstruct,
JobConstruct,
Actions,
} from '@dotgithub/core';
export class AdvancedConstruct extends GitHubConstruct {
readonly name = 'advanced-construct';
readonly version = '1.0.0';
readonly description = 'An advanced construct with configuration';
private readonly configSchema = z.object({
environment: z.enum(['development', 'staging', 'production']),
nodeVersion: z.string().default('18'),
testCommand: z.string().default('npm test'),
deployCommand: z.string().default('npm run deploy'),
});
validate(stack: GitHubStack): void {
this.configSchema.parse(stack.config);
}
describe() {
return {
name: this.name,
version: this.version,
description: this.description,
configSchema: this.configSchema,
};
}
async synthesize(stack: GitHubStack): Promise<void> {
const config = this.configSchema.parse(stack.config);
const { checkout, setupNode } = new Actions(stack, 'actions');
const wf = new WorkflowConstruct(stack, 'ci', {
name: 'CI/CD Workflow',
on: {
push: { branches: ['main'] },
pull_request: {},
},
jobs: {},
});
// Test job
new JobConstruct(wf, 'test', {
'runs-on': 'ubuntu-latest',
steps: [
checkout('Checkout code').toStep(),
setupNode('Setup Node.js', {
'node-version': config.nodeVersion,
}).toStep(),
{
name: 'Install dependencies',
run: 'npm install',
},
{
name: 'Run tests',
run: config.testCommand,
},
],
});
// Deploy job (only on main branch)
if (config.environment === 'production') {
new JobConstruct(wf, 'deploy', {
'runs-on': 'ubuntu-latest',
needs: ['test'],
if: "github.ref == 'refs/heads/main'",
steps: [
checkout('Checkout code').toStep(),
setupNode('Setup Node.js', {
'node-version': config.nodeVersion,
}).toStep(),
{
name: 'Deploy',
run: config.deployCommand,
env: {
NODE_ENV: config.environment,
},
},
],
});
}
}
}
export default new AdvancedConstruct();