Skip to content

Commit

Permalink
feat: Support updates to previous major versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Sep 3, 2024
1 parent 2135c05 commit f74751d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/release-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ function getPrereleaseVersion(currentVersion, prereleaseId, releaseType) {
* @private
*/
function getVersionTags() {
const tags = ShellOps.execSilent("git tag").trim().split("\n");

// Using `--merged` to only list tags whose commits are reachable from HEAD
const tags = ShellOps.execSilent("git tag --merged").trim().split("\n");

return tags.reduce((list, tag) => {
if (semver.valid(tag)) {
Expand Down Expand Up @@ -370,9 +372,10 @@ function writeChangelog(releaseInfo) {
* Creates a release version tag and pushes to origin and npm.
* @param {string} [prereleaseId] The prerelease ID (alpha, beta, rc, etc.).
* Only include when doing a prerelease.
* @param {string} [packageTag] Tag added to the package submitted to the npm registry.
* @returns {Object} The information about the release.
*/
function generateRelease(prereleaseId) {
function generateRelease(prereleaseId, packageTag = prereleaseId ? "next" : "latest") {

validateSetup();

Expand All @@ -382,7 +385,10 @@ function generateRelease(prereleaseId) {
console.log("Calculating changes for release");
const releaseInfo = calculateReleaseInfo(prereleaseId);

releaseInfo.packageTag = packageTag;

console.log("Release is %s", releaseInfo.version);
console.log("Package tag is %s", releaseInfo.packageTag);

console.log("Generating changelog");
writeChangelog(releaseInfo);
Expand Down Expand Up @@ -444,7 +450,8 @@ function publishReleaseToGitHub(releaseInfo) {
return repo.createRelease({
tag_name: tag, // eslint-disable-line camelcase
body: generateReleaseBody(releaseInfo.changelog),
prerelease: !!semver.prerelease(releaseInfo.version)
prerelease: !!semver.prerelease(releaseInfo.version),
make_latest: String(releaseInfo.packageTag === "latest") // eslint-disable-line camelcase
}).then(() => {
console.log("Posted release notes to GitHub");
}).catch(ex => {
Expand Down Expand Up @@ -480,11 +487,7 @@ function publishRelease() {
// if there's a prerelease ID, publish under "next" tag
console.log("Publishing to npm");

let command = "npm publish";

if (semver.prerelease(releaseInfo.version)) {
command += " --tag next";
}
let command = `npm publish --tag ${releaseInfo.packageTag}`;

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

0 comments on commit f74751d

Please sign in to comment.