@codedrifters/configulator 0.0.422 → 0.0.424

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.js CHANGED
@@ -457,6 +457,7 @@ __export(index_exports, {
457
457
  renderFocusSection: () => renderFocusSection,
458
458
  renderGithubIssueTypeSection: () => renderGithubIssueTypeSection,
459
459
  renderGithubIssueTypeSectionLines: () => renderGithubIssueTypeSectionLines,
460
+ renderHomeRepositoryCondition: () => renderHomeRepositoryCondition,
460
461
  renderIssueTemplateLabelsCheckerScript: () => renderIssueTemplateLabelsCheckerScript,
461
462
  renderIssueTemplatesBundleHook: () => renderIssueTemplatesBundleHook,
462
463
  renderIssueTemplatesCheckerScript: () => renderIssueTemplatesCheckerScript,
@@ -37971,6 +37972,7 @@ var CdkCli = class _CdkCli extends import_projen11.Component {
37971
37972
  this.diffDefaults = options.diffDefaults ?? {};
37972
37973
  this.bootstrapDefaults = options.bootstrapDefaults ?? {};
37973
37974
  this.accountOverrides = options.accountOverrides ?? {};
37975
+ this.cliVersion = options.cliVersion ?? project.cdkDeps.cdkCliVersion;
37974
37976
  }
37975
37977
  /**
37976
37978
  * Resolve the `cdk deploy` options to use against a given target.
@@ -42292,7 +42294,25 @@ var import_projen26 = require("projen");
42292
42294
  var import_build = require("projen/lib/build");
42293
42295
  var import_github6 = require("projen/lib/github");
42294
42296
  var import_workflows_model5 = require("projen/lib/github/workflows-model");
42297
+
42298
+ // src/workflows/home-repository.ts
42299
+ var HOME_REPOSITORY_PATTERN = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
42300
+ var renderHomeRepositoryCondition = (homeRepository, componentName) => {
42301
+ if (homeRepository === void 0) {
42302
+ return void 0;
42303
+ }
42304
+ if (!HOME_REPOSITORY_PATTERN.test(homeRepository)) {
42305
+ throw new Error(
42306
+ `${componentName} requires \`homeRepository\` to be an \`owner/repo\` slug, got "${homeRepository}"`
42307
+ );
42308
+ }
42309
+ return `github.repository == '${homeRepository}'`;
42310
+ };
42311
+
42312
+ // src/workflows/aws-deploy-workflow.ts
42295
42313
  var PROD_DEPLOY_NAME = "prod-deploy";
42314
+ var DIFF_OUTPUT_FILE = "cdk-diff.txt";
42315
+ var DIFF_SUMMARY_BYTE_LIMIT = 9e5;
42296
42316
  var AwsDeployWorkflow = class _AwsDeployWorkflow extends import_projen26.Component {
42297
42317
  constructor(project, options = {}) {
42298
42318
  super(project);
@@ -42345,6 +42365,39 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends import_projen26.Compone
42345
42365
  target.region
42346
42366
  ].join("-");
42347
42367
  };
42368
+ /**
42369
+ * Build the deterministic GitHub Actions job name for a target's `cdk diff`
42370
+ * job. Mirrors {@link buildJobName} with a `diff` verb so the diff and deploy
42371
+ * jobs for one target sort next to each other in the run view.
42372
+ */
42373
+ this.buildDiffJobName = (target) => {
42374
+ return [
42375
+ target.awsStageType,
42376
+ target.deploymentTargetRole,
42377
+ "diff",
42378
+ target.project.name,
42379
+ target.account,
42380
+ target.region
42381
+ ].join("-");
42382
+ };
42383
+ /**
42384
+ * Build the CI artifact name for a target's captured diff.
42385
+ *
42386
+ * Carries every component that makes a target unique — including
42387
+ * `deploymentTargetRole`, which two otherwise-identical targets can differ
42388
+ * on. `actions/upload-artifact` v4+ treats artifacts as immutable and rejects
42389
+ * a duplicate name within a run, so parallel diff jobs cannot share one.
42390
+ */
42391
+ this.buildDiffArtifactName = (target) => {
42392
+ return [
42393
+ "cdk-diff",
42394
+ target.awsStageType,
42395
+ target.deploymentTargetRole,
42396
+ target.project.name,
42397
+ target.account,
42398
+ target.region
42399
+ ].join("-");
42400
+ };
42348
42401
  /**
42349
42402
  * Builds a GitHub Actions condition string that checks if the current branch
42350
42403
  * matches any of the provided branch patterns.
@@ -42383,17 +42436,18 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends import_projen26.Compone
42383
42436
  awsDeploymentConfig
42384
42437
  } = target;
42385
42438
  const { roleArn, stackPattern } = ciDeploymentConfig ?? {};
42386
- const { rootCdkOut } = awsDeploymentConfig;
42439
+ const { rootCdkOut, cdkCli } = awsDeploymentConfig;
42387
42440
  const deployJobName = this.buildJobName(target);
42388
42441
  return [
42389
42442
  ...this.setupPnpm(),
42390
42443
  ...this.setupNode(),
42391
42444
  /**
42392
- * Install CDK
42445
+ * Install CDK, pinned to the same version that synthesized the cloud
42446
+ * assembly being deployed. See {@link CdkCli.cliVersion}.
42393
42447
  */
42394
42448
  {
42395
42449
  name: "Install CDK",
42396
- run: "pnpm add aws-cdk"
42450
+ run: `pnpm add "aws-cdk@${cdkCli.cliVersion}"`
42397
42451
  },
42398
42452
  /**
42399
42453
  * Configure AWS creds.
@@ -42413,8 +42467,8 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends import_projen26.Compone
42413
42467
  */
42414
42468
  {
42415
42469
  name: `Deploy ${awsStageType}/${deploymentTargetRole}/${account}/${region}`,
42416
- run: `pnpm dlx aws-cdk ${renderCdkDeploy({
42417
- ...awsDeploymentConfig.cdkCli.deployOptionsFor(target),
42470
+ run: `pnpm dlx "aws-cdk@${cdkCli.cliVersion}" ${renderCdkDeploy({
42471
+ ...cdkCli.deployOptionsFor(target),
42418
42472
  app: rootCdkOut,
42419
42473
  stackPatterns: stackPattern ? [stackPattern] : void 0
42420
42474
  })} --outputs-file cdk-outputs.json`
@@ -42462,6 +42516,128 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends import_projen26.Compone
42462
42516
  }
42463
42517
  ];
42464
42518
  };
42519
+ /**
42520
+ * Steps for a target's optional `cdk diff` job.
42521
+ *
42522
+ * Mirrors {@link deploySteps}' toolchain and credential setup — same pnpm /
42523
+ * Node setup, same version-pinned `aws-cdk` install, same OIDC role — so a
42524
+ * diff is computed by the same CLI that will run the deploy.
42525
+ *
42526
+ * The `cdk diff` flags come from the {@link CdkCli} precedence chain via
42527
+ * `diffOptionsFor(target)`, so `method`, `securityOnly`, `fail`, and the rest
42528
+ * are consumer-controlled per stage, per account, or per target. Four options
42529
+ * are pinned at the call site because the capture mechanism depends on them:
42530
+ * `app` and `stackPatterns` target the built cloud assembly, and `ci` /
42531
+ * `noColor` force the human-readable diff onto stdout without ANSI escapes
42532
+ * (without `--ci` the CLI interleaves it into stderr alongside logs).
42533
+ */
42534
+ this.diffSteps = (target) => {
42535
+ const {
42536
+ awsStageType,
42537
+ deploymentTargetRole,
42538
+ account,
42539
+ region,
42540
+ ciDeploymentConfig,
42541
+ awsDeploymentConfig
42542
+ } = target;
42543
+ const { roleArn, stackPattern } = ciDeploymentConfig ?? {};
42544
+ const { rootCdkOut, cdkCli } = awsDeploymentConfig;
42545
+ const label = `${awsStageType}/${deploymentTargetRole}/${account}/${region}`;
42546
+ const artifactName = this.buildDiffArtifactName(target);
42547
+ const capturedFileGuard = `always() && hashFiles('${DIFF_OUTPUT_FILE}') != ''`;
42548
+ const runUrl = "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}";
42549
+ return [
42550
+ ...this.setupPnpm(),
42551
+ ...this.setupNode(),
42552
+ /**
42553
+ * Install CDK, pinned to the same version that synthesized the cloud
42554
+ * assembly being diffed. See {@link CdkCli.cliVersion}.
42555
+ */
42556
+ {
42557
+ name: "Install CDK",
42558
+ run: `pnpm add "aws-cdk@${cdkCli.cliVersion}"`
42559
+ },
42560
+ /**
42561
+ * Configure AWS creds.
42562
+ */
42563
+ {
42564
+ name: `AWS Creds ${label}`,
42565
+ uses: "aws-actions/configure-aws-credentials@v6",
42566
+ with: {
42567
+ "role-to-assume": roleArn,
42568
+ "aws-region": region,
42569
+ "role-duration-seconds": 900
42570
+ // 15 minutes
42571
+ }
42572
+ },
42573
+ /**
42574
+ * Run CDK Diff, capturing the output while leaving it visible in the job
42575
+ * log. `pipefail` keeps the CLI's exit code from being masked by `tee`.
42576
+ */
42577
+ {
42578
+ name: `Diff ${label}`,
42579
+ shell: "bash",
42580
+ run: [
42581
+ "set -o pipefail",
42582
+ `pnpm dlx "aws-cdk@${cdkCli.cliVersion}" ${renderCdkDiff({
42583
+ ...cdkCli.diffOptionsFor(target),
42584
+ app: rootCdkOut,
42585
+ ci: true,
42586
+ noColor: true,
42587
+ stackPatterns: stackPattern ? [stackPattern] : void 0
42588
+ })} 2>&1 | tee ${DIFF_OUTPUT_FILE}`
42589
+ ].join("\n")
42590
+ },
42591
+ /**
42592
+ * Render the captured diff into the job summary inside a collapsed
42593
+ * `<details>` block, truncated below GitHub's 1 MiB per-step cap — a
42594
+ * summary that exceeds the cap is dropped in full rather than clipped.
42595
+ */
42596
+ ...this.diffOptions.summary ? [
42597
+ {
42598
+ name: `Render diff summary ${label}`,
42599
+ if: capturedFileGuard,
42600
+ shell: "bash",
42601
+ run: [
42602
+ `size=$(wc -c < ${DIFF_OUTPUT_FILE})`,
42603
+ "{",
42604
+ ` echo '## cdk diff \u2014 ${label}'`,
42605
+ ' echo ""',
42606
+ " echo '<details><summary>cdk diff output</summary>'",
42607
+ ' echo ""',
42608
+ " echo '```'",
42609
+ ` if [ "$size" -gt ${DIFF_SUMMARY_BYTE_LIMIT} ]; then`,
42610
+ ` head -c ${DIFF_SUMMARY_BYTE_LIMIT} ${DIFF_OUTPUT_FILE}`,
42611
+ ` printf '\\n... truncated at ${DIFF_SUMMARY_BYTE_LIMIT} bytes ...\\n'`,
42612
+ " else",
42613
+ ` cat ${DIFF_OUTPUT_FILE}`,
42614
+ " fi",
42615
+ " echo '```'",
42616
+ ' echo ""',
42617
+ " echo '</details>'",
42618
+ ...this.diffOptions.artifact ? [
42619
+ ' echo ""',
42620
+ ` echo 'Full diff: the \`${artifactName}\` artifact on [this run](${runUrl}).'`
42621
+ ] : [],
42622
+ '} >> "$GITHUB_STEP_SUMMARY"'
42623
+ ].join("\n")
42624
+ }
42625
+ ] : [],
42626
+ /**
42627
+ * Upload the untruncated diff as a per-run artifact.
42628
+ */
42629
+ ...this.diffOptions.artifact ? [
42630
+ import_github6.WorkflowSteps.uploadArtifact({
42631
+ name: `Upload diff ${label}`,
42632
+ if: capturedFileGuard,
42633
+ with: {
42634
+ name: artifactName,
42635
+ path: DIFF_OUTPUT_FILE
42636
+ }
42637
+ })
42638
+ ] : []
42639
+ ];
42640
+ };
42465
42641
  if (!(project.root instanceof MonorepoProject)) {
42466
42642
  throw new Error(
42467
42643
  "AwsDeployWorkflow requires the root project to be a MonorepoProject"
@@ -42481,6 +42657,16 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends import_projen26.Compone
42481
42657
  (target) => target.awsStageType === this.awsStageType && target.ciDeployment
42482
42658
  ) ?? [];
42483
42659
  this.deployAfterTargets = options.deployAfterTargets ?? [];
42660
+ this.diffOptions = {
42661
+ enabled: options.diff?.enabled ?? false,
42662
+ artifact: options.diff?.artifact ?? true,
42663
+ summary: options.diff?.summary ?? true
42664
+ };
42665
+ this.homeRepository = options.homeRepository;
42666
+ const homeRepositoryCondition = renderHomeRepositoryCondition(
42667
+ this.homeRepository,
42668
+ "AwsDeployWorkflow"
42669
+ );
42484
42670
  if (options.buildWorkflow && options.buildWorkflowOptions) {
42485
42671
  throw new Error(
42486
42672
  "Cannot provide both buildWorkflow and buildWorkflowOptions"
@@ -42558,10 +42744,11 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends import_projen26.Compone
42558
42744
  const branchFilterCondition = this.buildBranchFilterCondition(
42559
42745
  target.branches
42560
42746
  );
42561
- const jobCondition = branchFilterCondition ? "${{ " + [
42747
+ const jobCondition = "${{ " + [
42562
42748
  "!needs.build.outputs.self_mutation_happened",
42563
- `(${branchFilterCondition})`
42564
- ].join(" && ") + " }}" : "${{ !needs.build.outputs.self_mutation_happened }}";
42749
+ ...homeRepositoryCondition ? [homeRepositoryCondition] : [],
42750
+ ...branchFilterCondition ? [`(${branchFilterCondition})`] : []
42751
+ ].join(" && ") + " }}";
42565
42752
  this.buildWorkflow.addPostBuildJob(deployJobName, {
42566
42753
  name: `Deploy ${this.project.name} ${target.awsStageType}/${target.deploymentTargetRole}/${target.account}/${target.region}`,
42567
42754
  needs: [
@@ -42580,6 +42767,20 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends import_projen26.Compone
42580
42767
  if: jobCondition,
42581
42768
  steps: [...this.deploySteps(target)]
42582
42769
  });
42770
+ if (this.diffOptions.enabled) {
42771
+ const diffJobName = this.buildDiffJobName(target);
42772
+ this.buildWorkflow.addPostBuildJob(diffJobName, {
42773
+ name: `Diff ${this.project.name} ${target.awsStageType}/${target.deploymentTargetRole}/${target.account}/${target.region}`,
42774
+ needs: ["build"],
42775
+ runsOn: ["ubuntu-latest"],
42776
+ permissions: {
42777
+ contents: import_workflows_model5.JobPermission.READ,
42778
+ idToken: import_workflows_model5.JobPermission.WRITE
42779
+ },
42780
+ if: jobCondition,
42781
+ steps: [...this.diffSteps(target)]
42782
+ });
42783
+ }
42583
42784
  });
42584
42785
  addBuildCompleteJob(this.buildWorkflow);
42585
42786
  }
@@ -42642,7 +42843,8 @@ var AwsTeardownWorkflow = class extends import_projen27.Component {
42642
42843
  stageTypeTagName,
42643
42844
  environmentTypeTagName,
42644
42845
  branchNameTagName,
42645
- deleteBranchPatterns
42846
+ deleteBranchPatterns,
42847
+ homeRepository
42646
42848
  } = options;
42647
42849
  if (!repoTagName) {
42648
42850
  throw new Error("AwsTeardownWorkflow requires `repoTagName`");
@@ -42671,6 +42873,10 @@ var AwsTeardownWorkflow = class extends import_projen27.Component {
42671
42873
  deleteBranchPatterns,
42672
42874
  awsDestructionTargets
42673
42875
  );
42876
+ const homeRepositoryCondition = renderHomeRepositoryCondition(
42877
+ homeRepository,
42878
+ "AwsTeardownWorkflow"
42879
+ );
42674
42880
  const workflow = new import_github7.GithubWorkflow(github, "teardown-dev");
42675
42881
  workflow.on({
42676
42882
  workflowDispatch: {},
@@ -42697,6 +42903,7 @@ var AwsTeardownWorkflow = class extends import_projen27.Component {
42697
42903
  {
42698
42904
  name: `Teardown Stacks in ${awsStageType}/${deploymentTargetRole}/${account}/${region}`,
42699
42905
  runsOn: ["ubuntu-latest"],
42906
+ ...homeRepositoryCondition ? { if: `\${{ ${homeRepositoryCondition} }}` } : {},
42700
42907
  permissions: {
42701
42908
  contents: import_workflows_model6.JobPermission.READ,
42702
42909
  idToken: import_workflows_model6.JobPermission.WRITE
@@ -43731,6 +43938,7 @@ export const collections = {
43731
43938
  renderFocusSection,
43732
43939
  renderGithubIssueTypeSection,
43733
43940
  renderGithubIssueTypeSectionLines,
43941
+ renderHomeRepositoryCondition,
43734
43942
  renderIssueTemplateLabelsCheckerScript,
43735
43943
  renderIssueTemplatesBundleHook,
43736
43944
  renderIssueTemplatesCheckerScript,