Skip to content

Commit 2e6f2e6

Browse files
feat: Support updates to previous major versions (#62)
* feat: Support updates to previous major versions * store markdown changelog in `.eslint-release-info.json` * update README * add Node.js 20 and 22 to ci matrix * add Node.js 18 Co-authored-by: Francesco Trotta <[email protected]> --------- Co-authored-by: Francesco Trotta <[email protected]>
1 parent 2135c05 commit 2e6f2e6

File tree

3 files changed

+56
-12
lines changed

3 files changed

+56
-12
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
matrix:
2727
os: [ubuntu-latest]
28-
node: [16.x, 15.x, 14.x, 13.x, 12.x, 10.x]
28+
node: [22.x, 20.x, 18.x, 16.x, 15.x, 14.x, 13.x, 12.x, 10.x]
2929
runs-on: ${{ matrix.os }}
3030
steps:
3131
- uses: actions/checkout@v2

README.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,51 @@ When you run the release tool for a regular release, the following steps take pl
6666
1. Calculates the next release version based on the [commit message format](http://eslint.org/docs/developer-guide/contributing/pull-requests#step-2-make-your-changes) of the changes since the last release
6767
1. Updates `CHANGELOG.md` and commits the changes
6868
1. Runs `npm version` to update the version
69-
1. Pushes the repository to origin/master with tags (only outside of CI release)
69+
1. Pushes the current branch to origin, with tags
70+
1. Creates GitHub release marked as Latest
7071
1. Converts all line endings to Unix style
7172
1. Publishes the package to npm
7273
1. Reverts any file changes
7374

74-
When you do a prerelease, the same steps are taken except that package is published to npm under the `next` tag instead of `latest`.
75+
When you do a prerelease, the same steps are taken except that package is published to npm under the `next` tag instead of `latest`, and the GitHub release is marked as Pre-release.
76+
77+
## API Usage
78+
79+
This package exports two functions:
80+
81+
* `generateRelease(prereleaseId, packageTag)` - This corresponds to the CLI command `eslint-generate-release` when `prereleaseId` is `undefined`, and the CLI command `eslint-generate-prerelease prereleaseId` when `prereleaseId` is a string value.
82+
* `publishRelease()` - This corresponds to the CLI command `eslint-publish-release`.
83+
84+
`packageTag` is used as the `--tag` value in the `npm publish` command. It's also used to determine whether a regular release will be marked as Latest on GitHub: it will be marked as Latest only if `packageTag` is `"latest"`. This parameter is optional and defaults to `"latest"` when `prereleaseId` is `undefined`, `"next"` otherwise.
85+
86+
### Examples
87+
88+
Publish a regular latest release:
89+
90+
```js
91+
const ReleaseOps = require("eslint-release");
92+
93+
ReleaseOps.generateRelease();
94+
ReleaseOps.publishRelease();
95+
```
96+
97+
Publish a regular release with `maintenance` tag:
98+
99+
```js
100+
const ReleaseOps = require("eslint-release");
101+
102+
ReleaseOps.generateRelease(undefined, "maintenance");
103+
ReleaseOps.publishRelease();
104+
```
105+
106+
Publish an `alpha` prerelease:
107+
108+
```js
109+
const ReleaseOps = require("eslint-release");
110+
111+
ReleaseOps.generateRelease("alpha");
112+
ReleaseOps.publishRelease();
113+
```
75114

76115
## Contributing
77116

lib/release-ops.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ function getPrereleaseVersion(currentVersion, prereleaseId, releaseType) {
139139
* @private
140140
*/
141141
function getVersionTags() {
142-
const tags = ShellOps.execSilent("git tag").trim().split("\n");
142+
143+
// Using `--merged` to only list tags whose commits are reachable from HEAD
144+
const tags = ShellOps.execSilent("git tag --merged").trim().split("\n");
143145

144146
return tags.reduce((list, tag) => {
145147
if (semver.valid(tag)) {
@@ -347,10 +349,12 @@ function writeChangelog(releaseInfo) {
347349
const now = new Date(),
348350
today = dateformat(now, "mmmm d, yyyy");
349351

352+
releaseInfo.markdownChangelog = `v${releaseInfo.version} - ${today}\n\n${releaseInfo.rawChangelog}\n\n`;
353+
350354
// output header and changelog
351355
fs.writeFileSync(
352356
"CHANGELOG.tmp",
353-
`v${releaseInfo.version} - ${today}\n\n${releaseInfo.rawChangelog}\n\n`
357+
releaseInfo.markdownChangelog
354358
);
355359

356360
// ensure there's a CHANGELOG.md file
@@ -370,9 +374,10 @@ function writeChangelog(releaseInfo) {
370374
* Creates a release version tag and pushes to origin and npm.
371375
* @param {string} [prereleaseId] The prerelease ID (alpha, beta, rc, etc.).
372376
* Only include when doing a prerelease.
377+
* @param {string} [packageTag] Tag added to the package submitted to the npm registry.
373378
* @returns {Object} The information about the release.
374379
*/
375-
function generateRelease(prereleaseId) {
380+
function generateRelease(prereleaseId, packageTag = prereleaseId ? "next" : "latest") {
376381

377382
validateSetup();
378383

@@ -382,7 +387,10 @@ function generateRelease(prereleaseId) {
382387
console.log("Calculating changes for release");
383388
const releaseInfo = calculateReleaseInfo(prereleaseId);
384389

390+
releaseInfo.packageTag = packageTag;
391+
385392
console.log("Release is %s", releaseInfo.version);
393+
console.log("Package tag is %s", releaseInfo.packageTag);
386394

387395
console.log("Generating changelog");
388396
writeChangelog(releaseInfo);
@@ -444,7 +452,8 @@ function publishReleaseToGitHub(releaseInfo) {
444452
return repo.createRelease({
445453
tag_name: tag, // eslint-disable-line camelcase
446454
body: generateReleaseBody(releaseInfo.changelog),
447-
prerelease: !!semver.prerelease(releaseInfo.version)
455+
prerelease: !!semver.prerelease(releaseInfo.version),
456+
make_latest: String(releaseInfo.packageTag === "latest") // eslint-disable-line camelcase
448457
}).then(() => {
449458
console.log("Posted release notes to GitHub");
450459
}).catch(ex => {
@@ -480,11 +489,7 @@ function publishRelease() {
480489
// if there's a prerelease ID, publish under "next" tag
481490
console.log("Publishing to npm");
482491

483-
let command = "npm publish";
484-
485-
if (semver.prerelease(releaseInfo.version)) {
486-
command += " --tag next";
487-
}
492+
let command = `npm publish --tag ${releaseInfo.packageTag}`;
488493

489494
if (process.env.NPM_OTP && /^\d+$/.test(process.env.NPM_OTP)) {
490495
command += ` --otp=${process.env.NPM_OTP}`;

0 commit comments

Comments
 (0)