@codedrifters/configulator 0.0.422 → 0.0.423
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.mts +78 -1
- package/lib/index.d.ts +78 -1
- package/lib/index.js +175 -0
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +175 -0
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/index.mjs
CHANGED
|
@@ -41931,6 +41931,8 @@ import { BuildWorkflow } from "projen/lib/build";
|
|
|
41931
41931
|
import { GitHub as GitHub5, WorkflowSteps as WorkflowSteps2 } from "projen/lib/github";
|
|
41932
41932
|
import { JobPermission as JobPermission5 } from "projen/lib/github/workflows-model";
|
|
41933
41933
|
var PROD_DEPLOY_NAME = "prod-deploy";
|
|
41934
|
+
var DIFF_OUTPUT_FILE = "cdk-diff.txt";
|
|
41935
|
+
var DIFF_SUMMARY_BYTE_LIMIT = 9e5;
|
|
41934
41936
|
var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component22 {
|
|
41935
41937
|
constructor(project, options = {}) {
|
|
41936
41938
|
super(project);
|
|
@@ -41983,6 +41985,39 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component22 {
|
|
|
41983
41985
|
target.region
|
|
41984
41986
|
].join("-");
|
|
41985
41987
|
};
|
|
41988
|
+
/**
|
|
41989
|
+
* Build the deterministic GitHub Actions job name for a target's `cdk diff`
|
|
41990
|
+
* job. Mirrors {@link buildJobName} with a `diff` verb so the diff and deploy
|
|
41991
|
+
* jobs for one target sort next to each other in the run view.
|
|
41992
|
+
*/
|
|
41993
|
+
this.buildDiffJobName = (target) => {
|
|
41994
|
+
return [
|
|
41995
|
+
target.awsStageType,
|
|
41996
|
+
target.deploymentTargetRole,
|
|
41997
|
+
"diff",
|
|
41998
|
+
target.project.name,
|
|
41999
|
+
target.account,
|
|
42000
|
+
target.region
|
|
42001
|
+
].join("-");
|
|
42002
|
+
};
|
|
42003
|
+
/**
|
|
42004
|
+
* Build the CI artifact name for a target's captured diff.
|
|
42005
|
+
*
|
|
42006
|
+
* Carries every component that makes a target unique — including
|
|
42007
|
+
* `deploymentTargetRole`, which two otherwise-identical targets can differ
|
|
42008
|
+
* on. `actions/upload-artifact` v4+ treats artifacts as immutable and rejects
|
|
42009
|
+
* a duplicate name within a run, so parallel diff jobs cannot share one.
|
|
42010
|
+
*/
|
|
42011
|
+
this.buildDiffArtifactName = (target) => {
|
|
42012
|
+
return [
|
|
42013
|
+
"cdk-diff",
|
|
42014
|
+
target.awsStageType,
|
|
42015
|
+
target.deploymentTargetRole,
|
|
42016
|
+
target.project.name,
|
|
42017
|
+
target.account,
|
|
42018
|
+
target.region
|
|
42019
|
+
].join("-");
|
|
42020
|
+
};
|
|
41986
42021
|
/**
|
|
41987
42022
|
* Builds a GitHub Actions condition string that checks if the current branch
|
|
41988
42023
|
* matches any of the provided branch patterns.
|
|
@@ -42100,6 +42135,127 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component22 {
|
|
|
42100
42135
|
}
|
|
42101
42136
|
];
|
|
42102
42137
|
};
|
|
42138
|
+
/**
|
|
42139
|
+
* Steps for a target's optional `cdk diff` job.
|
|
42140
|
+
*
|
|
42141
|
+
* Mirrors {@link deploySteps}' toolchain and credential setup — same pnpm /
|
|
42142
|
+
* Node setup, same floating `aws-cdk` install, same OIDC role — so both jobs
|
|
42143
|
+
* move together when the CLI version is pinned.
|
|
42144
|
+
*
|
|
42145
|
+
* The `cdk diff` flags come from the {@link CdkCli} precedence chain via
|
|
42146
|
+
* `diffOptionsFor(target)`, so `method`, `securityOnly`, `fail`, and the rest
|
|
42147
|
+
* are consumer-controlled per stage, per account, or per target. Four options
|
|
42148
|
+
* are pinned at the call site because the capture mechanism depends on them:
|
|
42149
|
+
* `app` and `stackPatterns` target the built cloud assembly, and `ci` /
|
|
42150
|
+
* `noColor` force the human-readable diff onto stdout without ANSI escapes
|
|
42151
|
+
* (without `--ci` the CLI interleaves it into stderr alongside logs).
|
|
42152
|
+
*/
|
|
42153
|
+
this.diffSteps = (target) => {
|
|
42154
|
+
const {
|
|
42155
|
+
awsStageType,
|
|
42156
|
+
deploymentTargetRole,
|
|
42157
|
+
account,
|
|
42158
|
+
region,
|
|
42159
|
+
ciDeploymentConfig,
|
|
42160
|
+
awsDeploymentConfig
|
|
42161
|
+
} = target;
|
|
42162
|
+
const { roleArn, stackPattern } = ciDeploymentConfig ?? {};
|
|
42163
|
+
const { rootCdkOut } = awsDeploymentConfig;
|
|
42164
|
+
const label = `${awsStageType}/${deploymentTargetRole}/${account}/${region}`;
|
|
42165
|
+
const artifactName = this.buildDiffArtifactName(target);
|
|
42166
|
+
const capturedFileGuard = `always() && hashFiles('${DIFF_OUTPUT_FILE}') != ''`;
|
|
42167
|
+
const runUrl = "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}";
|
|
42168
|
+
return [
|
|
42169
|
+
...this.setupPnpm(),
|
|
42170
|
+
...this.setupNode(),
|
|
42171
|
+
/**
|
|
42172
|
+
* Install CDK
|
|
42173
|
+
*/
|
|
42174
|
+
{
|
|
42175
|
+
name: "Install CDK",
|
|
42176
|
+
run: "pnpm add aws-cdk"
|
|
42177
|
+
},
|
|
42178
|
+
/**
|
|
42179
|
+
* Configure AWS creds.
|
|
42180
|
+
*/
|
|
42181
|
+
{
|
|
42182
|
+
name: `AWS Creds ${label}`,
|
|
42183
|
+
uses: "aws-actions/configure-aws-credentials@v6",
|
|
42184
|
+
with: {
|
|
42185
|
+
"role-to-assume": roleArn,
|
|
42186
|
+
"aws-region": region,
|
|
42187
|
+
"role-duration-seconds": 900
|
|
42188
|
+
// 15 minutes
|
|
42189
|
+
}
|
|
42190
|
+
},
|
|
42191
|
+
/**
|
|
42192
|
+
* Run CDK Diff, capturing the output while leaving it visible in the job
|
|
42193
|
+
* log. `pipefail` keeps the CLI's exit code from being masked by `tee`.
|
|
42194
|
+
*/
|
|
42195
|
+
{
|
|
42196
|
+
name: `Diff ${label}`,
|
|
42197
|
+
shell: "bash",
|
|
42198
|
+
run: [
|
|
42199
|
+
"set -o pipefail",
|
|
42200
|
+
`pnpm dlx aws-cdk ${renderCdkDiff({
|
|
42201
|
+
...awsDeploymentConfig.cdkCli.diffOptionsFor(target),
|
|
42202
|
+
app: rootCdkOut,
|
|
42203
|
+
ci: true,
|
|
42204
|
+
noColor: true,
|
|
42205
|
+
stackPatterns: stackPattern ? [stackPattern] : void 0
|
|
42206
|
+
})} 2>&1 | tee ${DIFF_OUTPUT_FILE}`
|
|
42207
|
+
].join("\n")
|
|
42208
|
+
},
|
|
42209
|
+
/**
|
|
42210
|
+
* Render the captured diff into the job summary inside a collapsed
|
|
42211
|
+
* `<details>` block, truncated below GitHub's 1 MiB per-step cap — a
|
|
42212
|
+
* summary that exceeds the cap is dropped in full rather than clipped.
|
|
42213
|
+
*/
|
|
42214
|
+
...this.diffOptions.summary ? [
|
|
42215
|
+
{
|
|
42216
|
+
name: `Render diff summary ${label}`,
|
|
42217
|
+
if: capturedFileGuard,
|
|
42218
|
+
shell: "bash",
|
|
42219
|
+
run: [
|
|
42220
|
+
`size=$(wc -c < ${DIFF_OUTPUT_FILE})`,
|
|
42221
|
+
"{",
|
|
42222
|
+
` echo '## cdk diff \u2014 ${label}'`,
|
|
42223
|
+
' echo ""',
|
|
42224
|
+
" echo '<details><summary>cdk diff output</summary>'",
|
|
42225
|
+
' echo ""',
|
|
42226
|
+
" echo '```'",
|
|
42227
|
+
` if [ "$size" -gt ${DIFF_SUMMARY_BYTE_LIMIT} ]; then`,
|
|
42228
|
+
` head -c ${DIFF_SUMMARY_BYTE_LIMIT} ${DIFF_OUTPUT_FILE}`,
|
|
42229
|
+
` printf '\\n... truncated at ${DIFF_SUMMARY_BYTE_LIMIT} bytes ...\\n'`,
|
|
42230
|
+
" else",
|
|
42231
|
+
` cat ${DIFF_OUTPUT_FILE}`,
|
|
42232
|
+
" fi",
|
|
42233
|
+
" echo '```'",
|
|
42234
|
+
' echo ""',
|
|
42235
|
+
" echo '</details>'",
|
|
42236
|
+
...this.diffOptions.artifact ? [
|
|
42237
|
+
' echo ""',
|
|
42238
|
+
` echo 'Full diff: the \`${artifactName}\` artifact on [this run](${runUrl}).'`
|
|
42239
|
+
] : [],
|
|
42240
|
+
'} >> "$GITHUB_STEP_SUMMARY"'
|
|
42241
|
+
].join("\n")
|
|
42242
|
+
}
|
|
42243
|
+
] : [],
|
|
42244
|
+
/**
|
|
42245
|
+
* Upload the untruncated diff as a per-run artifact.
|
|
42246
|
+
*/
|
|
42247
|
+
...this.diffOptions.artifact ? [
|
|
42248
|
+
WorkflowSteps2.uploadArtifact({
|
|
42249
|
+
name: `Upload diff ${label}`,
|
|
42250
|
+
if: capturedFileGuard,
|
|
42251
|
+
with: {
|
|
42252
|
+
name: artifactName,
|
|
42253
|
+
path: DIFF_OUTPUT_FILE
|
|
42254
|
+
}
|
|
42255
|
+
})
|
|
42256
|
+
] : []
|
|
42257
|
+
];
|
|
42258
|
+
};
|
|
42103
42259
|
if (!(project.root instanceof MonorepoProject)) {
|
|
42104
42260
|
throw new Error(
|
|
42105
42261
|
"AwsDeployWorkflow requires the root project to be a MonorepoProject"
|
|
@@ -42119,6 +42275,11 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component22 {
|
|
|
42119
42275
|
(target) => target.awsStageType === this.awsStageType && target.ciDeployment
|
|
42120
42276
|
) ?? [];
|
|
42121
42277
|
this.deployAfterTargets = options.deployAfterTargets ?? [];
|
|
42278
|
+
this.diffOptions = {
|
|
42279
|
+
enabled: options.diff?.enabled ?? false,
|
|
42280
|
+
artifact: options.diff?.artifact ?? true,
|
|
42281
|
+
summary: options.diff?.summary ?? true
|
|
42282
|
+
};
|
|
42122
42283
|
if (options.buildWorkflow && options.buildWorkflowOptions) {
|
|
42123
42284
|
throw new Error(
|
|
42124
42285
|
"Cannot provide both buildWorkflow and buildWorkflowOptions"
|
|
@@ -42218,6 +42379,20 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component22 {
|
|
|
42218
42379
|
if: jobCondition,
|
|
42219
42380
|
steps: [...this.deploySteps(target)]
|
|
42220
42381
|
});
|
|
42382
|
+
if (this.diffOptions.enabled) {
|
|
42383
|
+
const diffJobName = this.buildDiffJobName(target);
|
|
42384
|
+
this.buildWorkflow.addPostBuildJob(diffJobName, {
|
|
42385
|
+
name: `Diff ${this.project.name} ${target.awsStageType}/${target.deploymentTargetRole}/${target.account}/${target.region}`,
|
|
42386
|
+
needs: ["build"],
|
|
42387
|
+
runsOn: ["ubuntu-latest"],
|
|
42388
|
+
permissions: {
|
|
42389
|
+
contents: JobPermission5.READ,
|
|
42390
|
+
idToken: JobPermission5.WRITE
|
|
42391
|
+
},
|
|
42392
|
+
if: jobCondition,
|
|
42393
|
+
steps: [...this.diffSteps(target)]
|
|
42394
|
+
});
|
|
42395
|
+
}
|
|
42221
42396
|
});
|
|
42222
42397
|
addBuildCompleteJob(this.buildWorkflow);
|
|
42223
42398
|
}
|