Skip to content

Commit

Permalink
chore: fix ci.yml canary releases to use nx, not lerna (#8962)
Browse files Browse the repository at this point in the history
* chore: fix ci.yml canary releases to use nx, not lerna

* chore: allow overriding major version for canaries

* fix lint

* nit: comment accuracy

* Update Releases.mdx for latest command

---------

Co-authored-by: “JamesHenry” <james@henry.sc>
  • Loading branch information
JoshuaKGoldberg and JamesHenry committed Apr 26, 2024
1 parent 3fd666f commit 4858afd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ jobs:
uses: ./.github/actions/prepare-build

- name: Figure out and apply the next canary version
run: npx nx run repo-tools:apply-canary-version
run: OVERRIDE_MAJOR_VERSION=8 npx nx run repo-tools:apply-canary-version

- name: Publish all packages to npm with the canary tag
# NOTE: this needs to be npx, rather than yarn, to make sure the authenticated npm registry is used
run: npx lerna publish premajor --loglevel=verbose --canary --exact --force-publish --yes --dist-tag rc-v8
run: npx nx release publish --tag rc-v8 --verbose
env:
NX_CLOUD_DISTRIBUTED_EXECUTION: false
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
8 changes: 3 additions & 5 deletions docs/maintenance/Releases.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ id: releases
title: Releases
---

<!-- TODO: update references to lerna to be `nx release instead` -->

[Users > Releases](../users/Releases.mdx) describes how our automatic releases are done.
There is generally no maintenance activity we need to take for the weekly releases.

Expand All @@ -26,15 +24,15 @@ Per [Users > Releases > Major Releases](../users/Releases.mdx#major-releases), w
- Under `push:` > `branches:` at the beginning of the file, add an `- v${major}` list item.
- Add a `publish_canary_version_v${major}` step the same as `publish_canary_version` except:
- Change the `if` condition's branch check to: `if: github.ref == 'refs/heads/v${major}'`.
- Its publish command should be `npx lerna publish premajor --loglevel=verbose --canary --exact --force-publish --yes --dist-tag rc-v${major}`.
- Its publish command should be `npx nx release publish --tag rc-v${major} --verbose`.
- Merge this into `main` once reviewed and rebase the `v${major}` branch.

### 2. Merging Breaking Changes

1. Send a PR from `v${major}` to `main` [example: [v6.0.0](https://github.com/typescript-eslint/typescript-eslint/pull/5886)].
1. Change all [breaking change PRs](https://github.com/typescript-eslint/typescript-eslint/issues?q=is%3Aissue+is%3Aopen+label%3A%22breaking+change%22) to target the `v${major}` branch.
- To signify these changes as breaking, the first line of the PR description must read as `BREAKING CHANGE:`, and second line should briefly summarize the changes.
- It is important to note that when merged the commit message must also include `BREAKING CHANGE:` as the first line in order for lerna to recognize it as a breaking change in the release notes. If you miss this it just means more manual work when writing the release documentation.
- It is important to note that when merged the commit message must also include `BREAKING CHANGE:` as the first line in order for nx to recognize it as a breaking change in the release notes. If you miss this it just means more manual work when writing the release documentation.
1. Wait until all required PRs have been merged
1. Let the release wait for **at least 1 week** to allow time for early adopters to help test it and discuss the changes.
- Promote it on the [`@tseslint`](https://twitter.com/tseslint) twitter to get some additional attention.
Expand All @@ -48,7 +46,7 @@ They don't need any special treatment.
### 3. Releasing the Version

1. Discuss with the maintainers to be ready for an [out-of-band](#out-of-band-releases) release. Doing this manually helps ensure someone is on-hand to action any issues that might arise from the major release.
1. Prepare the release notes. Lerna will automatically generate the release notes on GitHub, however this will be disorganized and unhelpful for users. We need to reorganize the release notes so that breaking changes are placed at the top to make them most visible. If any migrations are required, we must list the steps to make it easy for users.
1. Prepare the release notes. nx will automatically generate the release notes on GitHub, however this will be disorganized and unhelpful for users. We need to reorganize the release notes so that breaking changes are placed at the top to make them most visible. If any migrations are required, we must list the steps to make it easy for users.
- Example release notes: [`v5.0.0`](https://github.com/typescript-eslint/typescript-eslint/releases/tag/v5.0.0), [`v4.0.0`](https://github.com/typescript-eslint/typescript-eslint/releases/tag/v4.0.0), [`v3.0.0`](https://github.com/typescript-eslint/typescript-eslint/releases/tag/v3.0.0)
1. Finally, tweet the release on the `@tseslint` twitter with a link to the GitHub release. Make sure you include additional information about the highlights of the release!

Expand Down
81 changes: 54 additions & 27 deletions packages/repo-tools/src/apply-canary-version.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@ import { workspaceRoot } from '@nx/devkit';
import { execaSync } from 'execa';
import semver from 'semver';

// We are either releasing a canary version of the latest major version, or one for the next major.
const overrideMajorVersion = process.env.OVERRIDE_MAJOR_VERSION;

const preid = 'alpha';
const distTag = 'canary';

let distTag = 'canary';
if (overrideMajorVersion) {
console.log(
`Overriding canary major version base to v${overrideMajorVersion}`,
);
distTag = `rc-v${overrideMajorVersion}`;
}

const currentLatestVersion = execaSync('npm', [
'view',
'@typescript-eslint/eslint-plugin@latest',
'version',
]).stdout.trim();

const currentCanaryVersion = execaSync('npm', [
'view',
`@typescript-eslint/eslint-plugin@${distTag}`,
'version',
]).stdout.trim();
let currentCanaryVersion = null;
try {
currentCanaryVersion = execaSync('npm', [
'view',
`@typescript-eslint/eslint-plugin@${distTag}`,
'version',
]).stdout.trim();
} catch {
// (ignored - currentCanaryVersion can be null)
}

console.log('\nResolved current versions: ', {
currentLatestVersion,
Expand All @@ -24,28 +39,40 @@ console.log('\nResolved current versions: ', {

let nextCanaryVersion: string | null;

if (semver.gte(currentLatestVersion, currentCanaryVersion)) {
console.log(
'\nLatest version is greater than or equal to the current canary version, starting new prerelease base...',
);
// Determine next minor version above the currentLatestVersion
nextCanaryVersion = semver.inc(
currentLatestVersion,
'prerelease',
undefined,
preid,
);
if (overrideMajorVersion) {
nextCanaryVersion = currentCanaryVersion
? semver.inc(currentCanaryVersion, 'prerelease', undefined, preid)
: semver.inc(currentLatestVersion, 'premajor', undefined, preid);
} else {
console.log(
'\nLatest version is less than the current canary version, incrementing the existing prerelease base...',
);
// Determine next prerelease version above the currentCanaryVersion
nextCanaryVersion = semver.inc(
currentCanaryVersion,
'prerelease',
undefined,
preid,
);
if (!currentCanaryVersion) {
throw new Error(
'An unexpected error occurred, no current canary version could be read from the npm registry',
);
}

if (semver.gte(currentLatestVersion, currentCanaryVersion)) {
console.log(
'\nLatest version is greater than or equal to the current canary version, starting new prerelease base...',
);
// Determine next minor version above the currentLatestVersion
nextCanaryVersion = semver.inc(
currentLatestVersion,
'prerelease',
undefined,
preid,
);
} else {
console.log(
'\nLatest version is less than the current canary version, incrementing the existing prerelease base...',
);
// Determine next prerelease version above the currentCanaryVersion
nextCanaryVersion = semver.inc(
currentCanaryVersion,
'prerelease',
undefined,
preid,
);
}
}

if (!nextCanaryVersion) {
Expand Down

0 comments on commit 4858afd

Please sign in to comment.