Skip to content

Commit

Permalink
chore: restore ability to release maintenance version lines (#1386)
Browse files Browse the repository at this point in the history
Same as aws/jsii-compiler#998, but for
jsii-rosetta

This repo was using an automatic backport feature for repository config.
As part of daily upgrades, the projen config would be checked out from
`main` and applied to maintenance branches. However because we also
defined the current version in this config, this inadvertently changed
the current version for maintenance branches as well! In practice that
meant that the release tagging workflow tagged the wrong release lines.

This fix does two things: 
- Disable the automatic backport of configuration in favor of the new,
explicit label based backport feature (see it in action on this PR!)
- Add an explicit release line option to the tagging workflow, that will
be compared against the detected TypeScript version and fail if they
don't match.


---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
mrgrain committed May 20, 2024
1 parent e943c02 commit 08daef4
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 38 deletions.
2 changes: 0 additions & 2 deletions .backportrc.json

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

2 changes: 1 addition & 1 deletion .github/workflows/auto-tag-dev-v5.2.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/auto-tag-dev-v5.3.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/auto-tag-dev.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/auto-tag-releases-v5.2.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/auto-tag-releases-v5.3.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/auto-tag-releases.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/upgrade-maintenance-v5.2.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/upgrade-maintenance-v5.3.yml

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

46 changes: 23 additions & 23 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,44 +251,44 @@ new BuildWorkflow(project);
const supported = new SupportPolicy(project);
const releases = new ReleaseWorkflow(project)
.autoTag({
releaseLine: SUPPORT_POLICY.current,
preReleaseId: 'dev',
runName: 'Auto-Tag Prerelease (default branch)',
schedule: '0 0 * * 0,2-6', // Tuesday though sundays at midnight
})
.autoTag({
releaseLine: SUPPORT_POLICY.current,
runName: 'Auto-Tag Release (default branch)',
schedule: '0 0 * * 1', // Mondays at midnight
});

// We'll stagger release schedules so as to avoid everything going out at once.
let hour = 0;
for (const [version, until] of Object.entries(SUPPORT_POLICY.maintenance)) {
if (Date.now() <= until.getTime()) {
// Stagger schedules every 5 hours, rolling. 5 was selected because it's co-prime to 24.
hour = (hour + 5) % 24;

const tag = `v${version}`;

releases
.autoTag({
preReleaseId: 'dev',
runName: `Auto-Tag Prerelease (${tag})`,
schedule: `0 ${hour} * * 0,2-6`, // Tuesday though sundays
branch: supported.branches[version],
nameSuffix: tag,
})
.autoTag({
runName: `Auto-Tag Release (${tag})`,
schedule: `0 ${hour} * * 1`, // Mondays
branch: supported.branches[version],
nameSuffix: tag,
});
}
for (const [version, branch] of Object.entries(supported.activeBranches(false))) {
// Stagger schedules every 5 hours, rolling. 5 was selected because it's co-prime to 24.
hour = (hour + 5) % 24;
const tag = `v${version}`;
releases
.autoTag({
releaseLine: version,
preReleaseId: 'dev',
runName: `Auto-Tag Prerelease (${tag})`,
schedule: `0 ${hour} * * 0,2-6`, // Tuesday though sundays
branch,
nameSuffix: tag,
})
.autoTag({
releaseLine: version,
runName: `Auto-Tag Release (${tag})`,
schedule: `0 ${hour} * * 1`, // Mondays
branch,
nameSuffix: tag,
});
}

// Allow PR backports to all maintained versions
new PullRequestBackport(project, {
branches: Object.values(supported.branches),
branches: Object.values(supported.activeBranches()),
});

project.synth();
9 changes: 7 additions & 2 deletions projenrc/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ class TagReleaseTask {
}

interface AutoTagWorkflowProps {
/**
* The version used as the tagging base
*/
readonly releaseLine: string;

/**
* The branch on which to trigger this AutoTagWorkflow.
*
Expand Down Expand Up @@ -388,8 +393,8 @@ class AutoTagWorkflow {
{
name: `Tag ${props.preReleaseId ? 'PreRelease' : 'Release'}`,
run: `yarn tag-release --idempotent --no-sign --push ${
props.preReleaseId ? `--prerelease=${props.preReleaseId}` : ''
}`,
props.preReleaseId ? `--prerelease=${props.preReleaseId} ` : ''
}--release-line=${props.releaseLine}`,
},
],
});
Expand Down
18 changes: 18 additions & 0 deletions projenrc/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,22 @@ export class SupportPolicy {
readonly: true,
});
}

/**
* Get all actively maintained branches
*/
public activeBranches(includeCurrent = true): {
[version: string]: string;
} {
return Object.fromEntries(
Object.entries(this.branches).filter(([version]) => {
if (includeCurrent && version === SUPPORT_POLICY.current) {
return true;
}

// check if branch is still maintained
return Date.now() <= SUPPORT_POLICY.maintenance[version as any]?.getTime();
}),
);
}
}
16 changes: 14 additions & 2 deletions projenrc/tag-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function main(): Promise<void> {
remote,
sign,
verbose,
releaseLine,
} = await yargs
.scriptName('npx projen tag-release')
.option('idempotent', {
Expand Down Expand Up @@ -62,10 +63,21 @@ async function main(): Promise<void> {
desc: 'Do not actually create a tag, just determine what it would be',
default: false,
})
.option('release-line', {
alias: 'r',
type: 'string',
desc: 'The version line for this release. This will be checked against the actual available typescript version and fail if they do not match. If not provided the current typescript version will be released.',
default: versionMajorMinor,
})
.help().argv;

if (verbose) {
console.debug(`Current release line: ${versionMajorMinor}`);
console.debug(`Expected release line: ${releaseLine}`);
console.debug(`Detected release line: ${versionMajorMinor}`);
}

if (releaseLine !== versionMajorMinor) {
throw new Error(`Release line mismatch: expected ${releaseLine}, got ${versionMajorMinor}`);
}

// Shell out to a git command and ensure it returns successfully, and returns
Expand Down Expand Up @@ -119,7 +131,7 @@ async function main(): Promise<void> {
}

// Check if the work-tree is dirty or not...
const dirty = await git('diff', '--staged');
const dirty = await git('diff', '--cached');
if (dirty != '') {
if (ignoreDirty) {
console.warn('↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧↧');
Expand Down
2 changes: 1 addition & 1 deletion projenrc/upgrade-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class JsiiDependencyUpgrades extends Component {
JsonPatch.add('/jobs/upgrade/steps/3', {
name: 'Back-port projenrc changes from main',
env: { CI: 'false' },
run: 'git fetch origin main && git checkout FETCH_HEAD -- .projenrc.ts projenrc README.md && yarn projen',
run: 'git fetch origin main && git checkout FETCH_HEAD -- README.md && yarn projen',
}),
);
}
Expand Down

0 comments on commit 08daef4

Please sign in to comment.