import { Component, awscdk } from 'projen'; import { PipelineEngine } from '../engine'; import { PipelineStep } from '../steps'; import { VersioningConfig } from '../versioning'; /** * The Environment interface is designed to hold AWS related information * for a specific deployment environment within your infrastructure. * Each environment requires a specific account and region for its resources. */ export interface Environment { /** * The AWS Account ID associated with the environment. It's important because * different services or features could have distinct permissions and settings * in different accounts. */ readonly account: string; /** * The AWS Region for the environment. This determines where your resources * are created and where your application will run. It can affect latency, * availability, and pricing. */ readonly region: string; } export declare enum CdkDiffType { /** Do not perform a diff */ NONE = 0, /** Perform a fast template diff (--no-changeset) */ FAST = 1, /** Perform a full CloudFormation diff (--changeset) */ FULL = 2 } /** * Options for stages that are part of the pipeline */ export interface DeploymentStage extends NamedStageOptions { readonly manualApproval?: boolean; } /** * Options for stages that are not part of the pipeline */ export interface IndependentStage extends NamedStageOptions { /** * This specifies whether the stage should be deployed on push * * @default false */ readonly deployOnPush?: boolean; } /** * Options for a CDK stage with a name */ export interface NamedStageOptions extends StageOptions { readonly name: string; /** * The name of the GitHub environment to use for this stage. * If not specified, the stage name will be used as the GitHub environment name. * * @default - the stage name */ readonly githubEnvironment?: string; readonly watchable?: boolean; readonly diffType?: CdkDiffType; readonly postDiffSteps?: PipelineStep[]; readonly postDeploySteps?: PipelineStep[]; } /** * Options for a CDK stage like the target environment */ export interface StageOptions { readonly env: Environment; } /** * Configuration interface for IAM roles used in the CDK pipeline. */ export interface IamRoleConfig { /** Default IAM role ARN used if no specific role is provided. */ readonly default?: string; /** IAM role ARN for the synthesis step. */ readonly synth?: string; /** IAM role ARN for the asset publishing step. */ readonly assetPublishing?: string; /** IAM role ARN for the asset publishing step for a specific stage. */ readonly assetPublishingPerStage?: { [stage: string]: string; }; /** IAM role ARNs for different diff stages. */ readonly diff?: { [stage: string]: string; }; /** IAM role ARNs for different deployment stages. */ readonly deployment?: { [stage: string]: string; }; /** * IAM role ARNs for using a "jump" role to assume the deploy role in a different AWS account using Role Chaining. * https://github.com/aws-actions/configure-aws-credentials?tab=readme-ov-file#assumerole-with-role-previously-assumed-by-action-in-same-workflow * */ readonly jump?: { [stage: string]: string; }; } /** * The CDKPipelineOptions interface is designed to provide configuration * options for a CDK (Cloud Development Kit) pipeline. It allows the definition * of settings such as the stack prefix and package namespace to be used in the * AWS stack, along with the environments configuration to be used. */ export interface CDKPipelineOptions { /** * A unique name for this pipeline, used as a prefix for workflow files, * concurrency groups, and artifact names to prevent collisions in monorepos. * * @default - the project name if the project has a parent (monorepo subproject), otherwise no prefix */ readonly pipelineName?: string; /** * the name of the branch to deploy from * @default main */ readonly branchName?: string; /** * File path patterns that should trigger the pipeline when changed. * This is useful for monorepos where you only want to run the pipeline * when files in a specific subproject are modified. * * For GitHub, these are used as `on.push.paths` and `on.pull_request.paths` filters. * For GitLab, these are used as `only.changes` filters. * * @example ['packages/my-app/**', 'shared-libs/**'] * @default - all paths trigger the pipeline */ readonly paths?: string[]; /** * This field is used to define a prefix for the AWS Stack resources created * during the pipeline's operation. * * @default project name */ readonly stackPrefix?: string; /** * If set to true all CDK actions will also include /* to deploy/diff/destroy sub stacks of the main stack. * You can use this to deploy CDk applications containing multiple stacks. * * @default false */ readonly deploySubStacks?: boolean; /** * This field determines the NPM namespace to be used when packaging CDK cloud * assemblies. A namespace helps group related resources together, providing * better organization and ease of management. * * This is only needed if you need to version and upload the cloud assembly to a package repository. * * @default - */ readonly pkgNamespace?: string; /** IAM config */ readonly iamRoleArns: IamRoleConfig; /** * This field specifies a list of stages that should be deployed using a CI/CD pipeline */ readonly stages: DeploymentStage[]; /** This specifies details for independent stages */ readonly independentStages?: IndependentStage[]; /** This specifies details for a personal stage */ readonly personalStage?: StageOptions; /** This specifies details for feature stages */ readonly featureStages?: StageOptions; readonly preInstallCommands?: string[]; readonly preSynthCommands?: string[]; readonly postSynthCommands?: string[]; readonly preInstallSteps?: PipelineStep[]; readonly preSynthSteps?: PipelineStep[]; readonly postSynthSteps?: PipelineStep[]; /** * The working directory for the pipeline relative to the repository root. * This is automatically computed for subprojects but can be explicitly set. * * When set, CI jobs will run commands in this directory, and artifact paths * will be prefixed accordingly. * * @default - automatically computed from the project's position in the monorepo (empty string for root projects) */ readonly workingDirectory?: string; /** * A command to run before the build step, executed from the repository root. * When a workingDirectory is set (monorepo subproject), the command is * automatically wrapped to execute from the repository root regardless of * the job's working directory setting. * * For pnpm workspaces: `pnpm -r --filter ^... run build` * For npm workspaces: `npm run build --workspaces --if-present` * For yarn workspaces: `yarn workspaces foreach -Rt run build` * * @default - no pre-build command */ readonly preBuildCommand?: string; /** * Versioning configuration */ readonly versioning?: VersioningConfig; } /** * The CDKPipeline class extends the Component class and sets up the necessary configuration for deploying AWS CDK (Cloud Development Kit) applications across multiple stages. * It also manages tasks such as publishing CDK assets, bumping version based on git tags, and cleaning up conflicting tasks. */ export declare abstract class CDKPipeline extends Component { protected app: awscdk.AwsCdkTypeScriptApp; protected baseOptions: CDKPipelineOptions; readonly stackPrefix: string; readonly branchName: string; /** Prefix for workflow files, concurrency groups, and artifact names to prevent collisions in monorepos. */ protected readonly namePrefix: string; /** * The working directory relative to the repository root for this pipeline. * Undefined when the pipeline is at the repository root. */ protected readonly workingDirectory: string | undefined; constructor(app: awscdk.AwsCdkTypeScriptApp, baseOptions: CDKPipelineOptions); abstract engineType(): PipelineEngine; protected provideInstallStep(): PipelineStep; protected provideSynthStep(): PipelineStep; /** * Returns the preBuildCommand wrapped to execute from the repository root. * When workingDirectory is set, the command is prefixed with a cd to the * repo root using engine-appropriate environment variables. */ private preBuildCommandWrapped; protected provideAssetUploadStep(stageName?: string): PipelineStep; protected provideAssemblyUploadStep(): PipelineStep; protected provideDeployStep(stage: NamedStageOptions): PipelineStep; protected provideDiffStep(stage: NamedStageOptions, fast?: boolean): PipelineStep; protected renderInstallPackageCommands(packageName: string, runPreInstallCommands?: boolean): string[]; protected createSafeStageName(name: string): string; /** * This method generates the entry point for the application, including interfaces and classes * necessary to set up the pipeline and define the AWS CDK stacks for different environments. */ protected createApplicationEntrypoint(): void; /** * This method sets up tasks to publish CDK assets to all accounts and handle versioning, including bumping the version * based on the latest git tag and pushing the CDK assembly to the package repository. */ protected createReleaseTasks(): void; /** * This method sets up tasks for the personal deployment stage, including deployment, watching for changes, * comparing changes (diff), and destroying the stack when no longer needed. */ protected createPersonalStage(): void; /** * This method sets up tasks for the feature deployment stage, including deployment, comparing changes (diff), * and destroying the stack when no longer needed. */ protected createFeatureStage(): void; /** * This method sets up tasks for the general pipeline stages (dev, prod), including deployment and comparing changes (diff). * @param {DeployStageOptions} stage - The stage to create */ protected createPipelineStage(stage: DeploymentStage): void; /** * This method sets up tasks for the independent stages including deployment and comparing changes (diff). * @param {NamedStageOptions} stage - The stage to create */ protected createIndependentStage(stage: IndependentStage): void; protected getCliStackPattern(stage: string): string; /** * Create version:fetch: task to fetch version data from deployed stack */ protected createVersionFetchTask(stage: NamedStageOptions): void; /** * Generate CDK application code for versioning */ generateVersioningAppCode(config: VersioningConfig): string; /** * Generate versioning imports for CDK application */ generateVersioningImports(): string; /** * Generate versioning utility functions for CDK application */ generateVersioningUtilities(): string; }