dhoulb / multi-semantic-release

Proof of concept that wraps semantic-release to work with monorepos.
BSD Zero Clause License
202 stars 37 forks source link

How to release a beta version from a specific version? #94

Closed cesalberca closed 2 years ago

cesalberca commented 2 years ago

We are currently migrating a monorepo from Lerna + Yarn + Rollup to Parcel + NPM + Multi Semantic Release and we have previously published up until version 1.5.0. We now want to publish the 2.0.0 beta version with the new system, however MSR always resolves to version 1.0.0-beta.X. How could we specify we want to start from version 2.0.0?

The configuration is as follows:

{
  "branches": [
    {
      "name": "main"
    },
    {
      "name": "beta",
      "prerelease": true
    }
  ],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@semantic-release/npm",
    "@semantic-release/github",
    [
      "@semantic-release/git",
      {
        "assets": ["package.json", "CHANGELOG.md"],
        "message": "chore(release): ${nextRelease.version} [skip ci]"
      }
    ]
  ]
}

And the CLI command is the following:

multi-semantic-release --sequential-init --ignore-private-packages=true

We've tried tagging manually the following tags:

@archimedes/arch@2.0.0-beta.1
@archimedes/components@2.0.0-beta.1
@archimedes/utils@2.0.0-beta.1

But it still resolves the 1.0.0 beta version.

You can access the whole project here: https://github.com/archimedes-projects/archimedes-js/tree/beta

antongolub commented 2 years ago

@cesalberca, is your beta branch based on the latest master? Here's how msr tries to resolve a tag:

const getNextPreVersion = (pkg, tags) => {
    const tagFilters = [pkg._preRelease];
    const lastVersion = pkg._lastRelease && pkg._lastRelease.version;
    // Extract tags:
    // 1. Set filter to extract only package tags
    // 2. Get tags from a branch considering the filters established
    // 3. Resolve the versions from the tags
    // TODO: replace {cwd: '.'} with multiContext.cwd
    if (pkg.name) tagFilters.push(pkg.name);
    if (!tags || !tags.length) {
        tags = getTags(pkg._branch, { cwd: "." }, tagFilters);
    }
    const lastPreRelTag = getPreReleaseTag(lastVersion);
    const isNewPreRelTag = lastPreRelTag && lastPreRelTag !== pkg._preRelease;
    const versionToSet =
        isNewPreRelTag || !lastVersion
            ? `1.0.0-${pkg._preRelease}.1`
            : _nextPreVersionCases(
                    tags.map((tag) => getVersionFromTag(pkg, tag)).filter((tag) => tag),
                    lastVersion,
                    pkg._nextType,
                    pkg._preRelease
              );
    return versionToSet;
};
lyh543 commented 2 years ago

@cesalberca semantic-release does the same thing: they also fetched tags only on the specific branch.

https://github.com/semantic-release/semantic-release/blob/ab45ab1f8d0d0f728fb026a92ec191bcc88f51f1/lib/git.js#L21-L35

cesalberca commented 2 years ago

Sorry for the late reply, we fixed it in the end by manually removing one of the tags, now we fully moved from Lerna 😊

https://github.com/archimedes-projects/archimedes-js/tree/7150e1d2f3bfe4257cada110f80c0541d3dd859b