Skip to content

Commit 727f88d

Browse files
Leo10GamaLeonardo Gama
and
Leonardo Gama
authored
fix: allow dep upgrade options (#842)
* Fix dependencies not working * Revert cron job time --------- Co-authored-by: Leonardo Gama <[email protected]>
1 parent 61160a3 commit 727f88d

6 files changed

+121
-19
lines changed

.projenrc.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { UpgradeDependenciesSchedule } from 'projen/lib/javascript';
21
import { generateCdkCommonOptions } from './projenrc/cdk-common-options';
32
import { generateCdkConstructLibraryOptions } from './projenrc/cdk-construct-library-options';
43
import { generateCdkJsiiOptions } from './projenrc/cdk-jsii-options';
@@ -20,11 +19,6 @@ const project = new CdklabsJsiiProject({
2019
cdklabsPublishingDefaults: false,
2120
upgradeCdklabsProjenProjectTypes: false, // that is this project!
2221
setNodeEngineVersion: false,
23-
depsUpgradeOptions: {
24-
workflowOptions: {
25-
schedule: UpgradeDependenciesSchedule.WEEKLY,
26-
},
27-
},
2822
peerDependencyOptions: {
2923
pinnedDevDependency: false,
3024
},

API.md

+60
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projenrc/cdk-construct-library-options.ts

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ export function generateCdkConstructLibraryOptions(project: typescript.TypeScrip
2323
},
2424
},
2525
},
26-
omitProps: [
27-
// These properties are ignored; a CdkLabsConstructLibrary does what it wants anyway.
28-
'depsUpgrade', 'depsUpgradeOptions',
29-
],
3026
properties: [
3127
...COMMON_OPTIONS,
3228
{

src/cdk-construct-library-options.ts

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common-options.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function withCommonOptionsDefaults<T extends ProjectOptions>(options: T):
6464
return deepMerge([{}, options, common]) as T & ConfiguredCommonOptions;
6565
}
6666

67-
export function configureCommonComponents(project: typescript.TypeScriptProject, opts: CdkCommonOptions & Pick<javascript.NodeProjectOptions, 'autoApproveUpgrades' | 'autoApproveOptions'>) {
67+
export function configureCommonComponents(project: typescript.TypeScriptProject, opts: CdkCommonOptions & Pick<javascript.NodeProjectOptions, 'autoApproveUpgrades' | 'autoApproveOptions' | 'depsUpgradeOptions'>) {
6868
if (opts.private) {
6969
new Private(project);
7070
}
@@ -86,6 +86,13 @@ export function configureCommonComponents(project: typescript.TypeScriptProject,
8686
// Run at 18:00Z once a week (on Monday)
8787
const upgradeSchedule = javascript.UpgradeDependenciesSchedule.expressions(['0 18 * * 1']);
8888

89+
// Get branch configuration from depsUpgradeOptions if available
90+
const workflowOptions = {
91+
labels,
92+
schedule: upgradeSchedule,
93+
...(opts.depsUpgradeOptions?.workflowOptions ?? {}),
94+
};
95+
8996
new javascript.UpgradeDependencies(project, {
9097
taskName: 'upgrade',
9198
// NOTE: we explicitly do NOT upgrade PEER dependencies. We want the widest range of compatibility possible,
@@ -95,10 +102,7 @@ export function configureCommonComponents(project: typescript.TypeScriptProject,
95102
types: [DependencyType.RUNTIME, DependencyType.BUNDLED],
96103
exclude,
97104
semanticCommit: 'fix',
98-
workflowOptions: {
99-
labels,
100-
schedule: upgradeSchedule,
101-
},
105+
workflowOptions,
102106
});
103107

104108
new javascript.UpgradeDependencies(project, {
@@ -107,10 +111,7 @@ export function configureCommonComponents(project: typescript.TypeScriptProject,
107111
exclude,
108112
semanticCommit: 'chore',
109113
pullRequestTitle: 'upgrade dev dependencies',
110-
workflowOptions: {
111-
labels,
112-
schedule: upgradeSchedule,
113-
},
114+
workflowOptions,
114115
});
115116
}
116117

test/cdklabs.test.ts

+40
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,46 @@ describe('CdklabsConstructLibrary', () => {
219219
expect(workflow).toMatchSnapshot();
220220
});
221221
});
222+
223+
test('respects branch configuration with custom upgrade tasks', () => {
224+
const testBranches = ['branch1/main', 'branch2/main'];
225+
226+
const project = new TestCdkLabsConstructLibrary({
227+
depsUpgradeOptions: {
228+
workflowOptions: {
229+
branches: testBranches,
230+
},
231+
},
232+
});
233+
234+
const outdir = Testing.synth(project);
235+
// Verify upgrade workflows exist in the outdir
236+
expect(outdir['.github/workflows/upgrade-branch1-main.yml']).toBeDefined();
237+
expect(outdir['.github/workflows/upgrade-branch2-main.yml']).toBeDefined();
238+
expect(outdir['.github/workflows/upgrade-dev-deps-branch1-main.yml']).toBeDefined();
239+
expect(outdir['.github/workflows/upgrade-dev-deps-branch2-main.yml']).toBeDefined();
240+
241+
// Verify the checkout refs in each workflow
242+
expect(
243+
YAML.parse(outdir['.github/workflows/upgrade-branch1-main.yml']).jobs.upgrade.steps
244+
.find((step: any) => step.uses === 'actions/checkout@v4').with.ref,
245+
).toBe('branch1/main');
246+
247+
expect(
248+
YAML.parse(outdir['.github/workflows/upgrade-branch2-main.yml']).jobs.upgrade.steps
249+
.find((step: any) => step.uses === 'actions/checkout@v4').with.ref,
250+
).toBe('branch2/main');
251+
252+
expect(
253+
YAML.parse(outdir['.github/workflows/upgrade-dev-deps-branch1-main.yml']).jobs.upgrade.steps
254+
.find((step: any) => step.uses === 'actions/checkout@v4').with.ref,
255+
).toBe('branch1/main');
256+
257+
expect(
258+
YAML.parse(outdir['.github/workflows/upgrade-dev-deps-branch2-main.yml']).jobs.upgrade.steps
259+
.find((step: any) => step.uses === 'actions/checkout@v4').with.ref,
260+
).toBe('branch2/main');
261+
});
222262
});
223263

224264
describe('CdklabsTypeScriptProject', () => {

0 commit comments

Comments
 (0)