Skip to content

Commit

Permalink
ci: always use version named branches (backport #752) (#754)
Browse files Browse the repository at this point in the history
This is an automatic backport of pull request #752 done by [Mergify](https://mergify.com).

---


<details>
<summary>Mergify commands and options</summary>

<br />

More conditions and actions can be found in the [documentation](https://docs.mergify.com/).

You can also trigger Mergify actions by commenting on this pull request:

- `@Mergifyio refresh` will re-evaluate the rules
- `@Mergifyio rebase` will rebase this PR on its base branch
- `@Mergifyio update` will merge the base branch into this PR
- `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch

Additionally, on Mergify [dashboard](https://dashboard.mergify.com) you can:

- look at your merge queues
- generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com
</details>
  • Loading branch information
mergify[bot] authored Sep 9, 2023
1 parent 2871dd8 commit c809de1
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions .github/workflows/release.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projen/files.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ import { IntegrationTests } from './projenrc/IntegrationTests';
import { Esbuild } from './src/private/esbuild-source';

const releaseBranches: StableReleaseBranches = {
main: {
v4: {
isCurrent: true,
majorVersion: 4,
cdkVersion: '2.12.0',
minNodeVersion: '16.x', // should be 14.x but that version doesn't build anymore
releaseSchedule: '0 5 15 * *',
jsiiVersion: '1.x',
typescriptVersion: '4.9.x',
},
v3: {
majorVersion: 3,
cdkVersion: '2.0.0',
syntheticsVersion: '2.0.0-alpha.11',
minNodeVersion: '16.x', // should be 14.x but that version doesn't build anymore
releaseSchedule: '0 5 15 * *',
jsiiVersion: '1.x',
typescriptVersion: '4.9.x',
},
};

Expand Down Expand Up @@ -95,9 +101,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
},

// Dependencies
cdkVersion: releaseBranches.main.cdkVersion,
devDeps: [
`@aws-cdk/aws-synthetics-alpha@${releaseBranches.main.cdkVersion}-alpha.0`,
'@types/eslint',
Esbuild.spec,
'jest-mock',
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 31 additions & 9 deletions projenrc/ReleaseBranches.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Component, JsonPatch, release, typescript } from 'projen';

export interface StableReleaseBranchOptions extends Omit<release.BranchOptions, 'npmDistTag'> {
isCurrent?: boolean;
minNodeVersion: string;
releaseSchedule: string;
npmDistTags?: string[];
cdkVersion: string;
jsiiVersion: string;
typescriptVersion: string;
syntheticsVersion?: string;
}

export interface StableReleaseBranches {
Expand All @@ -14,15 +18,20 @@ export interface StableReleaseBranches {
export class StableReleases extends Component {
public project: typescript.TypeScriptProject;

public constructor(project: typescript.TypeScriptProject, options: StableReleaseBranches) {
public constructor(project: typescript.TypeScriptProject, public readonly branches: StableReleaseBranches) {
super(project);
this.project = project;

for (const branch of project.release?.branches ?? []) {
const opts = options[branch];
const isDefaultBranch = this.isDefaultBranch(branch);
const opts = branches[branch];
const isCurrentBranch = this.isCurrentBranch(branch);
const releaseWorkflow = this.getReleaseWorkflow(branch);

// Features only for current branch
if (isCurrentBranch) {
project.addDevDeps( `@aws-cdk/aws-synthetics-alpha@${opts.syntheticsVersion ?? opts.cdkVersion + '-alpha.0'}`);
}

// Release schedule
releaseWorkflow?.patch(JsonPatch.replace('/on/schedule', [{ cron: opts.releaseSchedule }]));

Expand All @@ -38,7 +47,7 @@ export class StableReleases extends Component {
gitBranch: branch,
});
const publishChangelogTask = ['publish', 'git'];
if (!isDefaultBranch) {
if (!isCurrentBranch) {
publishChangelogTask.push(branch);
}
releaseWorkflow?.patch(JsonPatch.add('/jobs/release/steps/-', {
Expand All @@ -62,12 +71,13 @@ export class StableReleases extends Component {
}
}

private isDefaultBranch(branch: string): boolean {
return branch === 'main';
private isCurrentBranch(branch: string): boolean {
const [currentBranch] = Object.entries(this.branches).find(([_, options]) => options.isCurrent) || [];
return branch === currentBranch;
}

private getReleaseWorkflow(branch: string) {
if (this.isDefaultBranch(branch)) {
if (this.isCurrentBranch(branch)) {
return this.project.tryFindObjectFile('.github/workflows/release.yml');
}

Expand All @@ -90,20 +100,32 @@ export class StableReleases extends Component {

}

export function releaseOptions(branches: StableReleaseBranches, currentBranch = 'main'): {
export function releaseOptions(branches: StableReleaseBranches): {
npmDistTag: string;
defaultReleaseBranch: string;
majorVersion: number;
prerelease?: string;
releaseBranches: StableReleaseBranches;
workflowNodeVersion: string;
releaseTrigger: release.ReleaseTrigger;
cdkVersion: string;
jsiiVersion: string;
typescriptVersion: string;
} {
const current = branches[currentBranch];
const [currentBranch, current] = Object.entries(branches).find(([_, options]) => options.isCurrent) || [];
if (!currentBranch || !current) {
throw Error('Exactly one branch must be the current version');
}

return {
npmDistTag: 'latest',
defaultReleaseBranch: currentBranch,
majorVersion: current.majorVersion,
workflowNodeVersion: current.minNodeVersion,
prerelease: current.prerelease,
cdkVersion: current.cdkVersion,
jsiiVersion: current.jsiiVersion,
typescriptVersion: current.typescriptVersion,
releaseBranches: Object.fromEntries(
Object.entries(branches)
.filter(([b]) => b !== currentBranch)
Expand Down

0 comments on commit c809de1

Please sign in to comment.