From ff3a1f3876b6cb9c49628428723e0428174f57e4 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Wed, 8 Apr 2026 13:11:33 +0100 Subject: [PATCH] refactor: use projen primitives for custom workflow definitions Replace hardcoded setup-node, install, and command steps in custom workflow definitions with projen's renderWorkflowSetup() and runTaskCommand() primitives. Create a proper publish-to-adc projen task. --- .github/workflows/codecov.yml | 5 +++-- .github/workflows/integ.yml | 6 +++--- .github/workflows/release.yml | 6 ++++-- .projen/tasks.json | 8 ++++++++ package.json | 1 + projenrc/adc-publishing.ts | 17 ++++++----------- projenrc/cdk-cli-integ-tests.ts | 20 ++++++-------------- projenrc/codecov.ts | 12 +----------- 8 files changed, 32 insertions(+), 43 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 0a784ba94..12e39c68a 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -17,10 +17,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 - - name: Set up Node - uses: actions/setup-node@v4 + - name: Setup Node.js + uses: actions/setup-node@v6 with: node-version: lts/* + package-manager-cache: false - name: Install dependencies run: yarn install --check-files --frozen-lockfile - name: Reset coverage thresholds diff --git a/.github/workflows/integ.yml b/.github/workflows/integ.yml index 04b11e96c..69080c8d6 100644 --- a/.github/workflows/integ.yml +++ b/.github/workflows/integ.yml @@ -45,16 +45,16 @@ jobs: git remote add upstream https://github.com/aws/aws-cdk-cli.git git fetch upstream 'refs/tags/*:refs/tags/*' - name: Setup Node.js - uses: actions/setup-node@v4 + uses: actions/setup-node@v6 with: node-version: lts/* - cache: npm + package-manager-cache: false - name: Install dependencies run: yarn install --check-files --frozen-lockfile - name: Bump to realistic versions env: TESTING_CANDIDATE: "true" - run: yarn workspaces run bump + run: npx projen run bump - name: build env: RELEASE: "true" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4804e3477..867a03819 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1046,9 +1046,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 - - uses: actions/setup-node@v4 + - name: Setup Node.js + uses: actions/setup-node@v6 with: node-version: lts/* + package-manager-cache: false - name: Install dependencies run: yarn install --check-files --frozen-lockfile - name: Download build artifacts @@ -1069,7 +1071,7 @@ jobs: env: PUBLISHING_ROLE_ARN: ${{ vars.PUBLISHING_ROLE_ARN }} TARGET_BUCKETS: ${{ vars.TARGET_BUCKETS }} - run: npx tsx projenrc/publish-to-adc.task.ts + run: npx projen publish-to-adc record_timestamp: name: "aws-cdk: Record publishing timestamp" needs: release diff --git a/.projen/tasks.json b/.projen/tasks.json index 360f7b9b3..87a45a9a0 100644 --- a/.projen/tasks.json +++ b/.projen/tasks.json @@ -126,6 +126,14 @@ "name": "post-upgrade", "description": "Runs after upgrading dependencies" }, + "publish-to-adc": { + "name": "publish-to-adc", + "steps": [ + { + "exec": "tsx projenrc/publish-to-adc.task.ts" + } + ] + }, "release": { "name": "release", "description": "Prepare a release from all monorepo packages", diff --git a/package.json b/package.json index 2b4107a71..fb58d4894 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "git-secrets-scan": "npx projen git-secrets-scan", "package": "npx projen package", "post-upgrade": "npx projen post-upgrade", + "publish-to-adc": "npx projen publish-to-adc", "release": "npx projen release", "run": "npx projen run", "test": "npx projen test", diff --git a/projenrc/adc-publishing.ts b/projenrc/adc-publishing.ts index 36df2173d..217e0d48a 100644 --- a/projenrc/adc-publishing.ts +++ b/projenrc/adc-publishing.ts @@ -12,6 +12,10 @@ export class AdcPublishing extends Component { this.project.tasks.tryFind(taskName)?.exec('tsx projenrc/build-standalone-zip.task.ts'); } + const publishToAdcTask = this.project_.tasks.tryFind('publish-to-adc') ?? this.project_.addTask('publish-to-adc', { + exec: 'tsx projenrc/publish-to-adc.task.ts', + }); + const releaseWf = this.project_.github?.tryFindWorkflow('release'); if (!releaseWf) { throw new Error('Could not find release workflow'); @@ -40,16 +44,7 @@ export class AdcPublishing extends Component { if: '${{ needs.release.outputs.latest_commit == github.sha }}', steps: [ github.WorkflowSteps.checkout(), - { - uses: 'actions/setup-node@v4', - with: { - 'node-version': 'lts/*', - }, - }, - { - name: 'Install dependencies', - run: 'yarn install --check-files --frozen-lockfile', - }, + ...this.project_.renderWorkflowSetup(), { name: 'Download build artifacts', uses: 'actions/download-artifact@v4', @@ -76,7 +71,7 @@ export class AdcPublishing extends Component { PUBLISHING_ROLE_ARN: '${{ vars.PUBLISHING_ROLE_ARN }}', TARGET_BUCKETS: '${{ vars.TARGET_BUCKETS }}', }, - run: 'npx tsx projenrc/publish-to-adc.task.ts', + run: this.project_.runTaskCommand(publishToAdcTask), }, ], }); diff --git a/projenrc/cdk-cli-integ-tests.ts b/projenrc/cdk-cli-integ-tests.ts index 886588aa9..8b53bc4cc 100644 --- a/projenrc/cdk-cli-integ-tests.ts +++ b/projenrc/cdk-cli-integ-tests.ts @@ -239,8 +239,11 @@ export class CdkCliIntegTestsWorkflow extends Component { private readonly JOB_PREPARE = 'prepare'; private readonly maxWorkersArg: string = ''; + public readonly project: javascript.NodeProject; + constructor(repo: javascript.NodeProject, private readonly props: CdkCliIntegTestsWorkflowProps) { super(repo); + this.project = repo; const buildWorkflow = repo.buildWorkflow; this.workflow = repo.github?.addWorkflow('integ')!; @@ -413,28 +416,17 @@ export class CdkCliIntegTestsWorkflow extends Component { 'git fetch upstream \'refs/tags/*:refs/tags/*\'', ].join('\n'), }, - { - name: 'Setup Node.js', - uses: 'actions/setup-node@v4', - with: { - 'node-version': 'lts/*', - 'cache': 'npm', - }, - }, - { - name: 'Install dependencies', - run: repo.package.installCommand, - }, + ...this.project.renderWorkflowSetup(), { name: 'Bump to realistic versions', - run: 'yarn workspaces run bump', + run: `${this.project.runTaskCommand(this.project.tasks.tryFind('run')!)} bump`, env: { TESTING_CANDIDATE: 'true', }, }, { name: 'build', - run: 'npx projen build', + run: this.project.runTaskCommand(this.project.buildTask), env: { // This is necessary to prevent projen from resetting the version numbers to // 0.0.0 during its synthesis. diff --git a/projenrc/codecov.ts b/projenrc/codecov.ts index a1e8fda30..5444076ec 100644 --- a/projenrc/codecov.ts +++ b/projenrc/codecov.ts @@ -29,17 +29,7 @@ export class CodeCovWorkflow extends Component { if: props.restrictToRepos.map(r => `github.repository == '${r}'`).join(' || '), steps: [ github.WorkflowSteps.checkout(), - { - name: 'Set up Node', - uses: 'actions/setup-node@v4', - with: { - 'node-version': 'lts/*', - }, - }, - { - name: 'Install dependencies', - run: repo.package.installCommand, - }, + ...repo.renderWorkflowSetup(), { name: 'Reset coverage thresholds', run: 'find . -name "jest.config.json" -type f -exec chmod +w {} \\; -exec node -e "const fs=require(\'fs\'); const file=process.argv[1]; const data=JSON.parse(fs.readFileSync(file)); data.coverageThreshold={ }; fs.writeFileSync(file, JSON.stringify(data, null, 2));" {} \\;',