qiwi / multi-semantic-release

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

Ignore certain packages to go through the workflow #37

Closed davikawasaki closed 3 years ago

davikawasaki commented 3 years ago

@antongolub do we have a feature that enable the semantic release workflow to fully ignore packages we want? For instance, I have three packages:

What I'd want to have is have only app and admin be bumped and released, whilst the lib to maintain in the same version. If not, can you walk me through which points in the code should we tweak to enable such functionality?

antongolub commented 3 years ago

@davikawasaki,

by default msr relies on package.json.workspaces value, but it's very easy override with custom glob pattern. I suggest to introduce workspaces CLI flag / JS API option and handle this value in getWorkspaces.

["packages/*"] — include all
["packages/*", "!packages/app"] — exclude `app`
["packages/admin"] — include `admin` only

meow parser supports "array-like" args notation, I've checked: https://github.com/imagemin/imagemin-cli/pull/23/files

bin/runner.js

    // Imports.
    const getWorkspacesYarn = require("../lib/getWorkspacesYarn");
    const multiSemanticRelease = require("../lib/multiSemanticRelease");
    const multisemrelPkgJson = require("../package.json");
    const semrelPkgJson = require("semantic-release/package.json");

    // Get directory.
    const cwd = process.cwd();

    // Catch errors.
    try {
        console.log(`multi-semantic-release version: ${multisemrelPkgJson.version}`);
        console.log(`semantic-release version: ${semrelPkgJson.version}`);
        console.log(`flags: ${JSON.stringify(flags, null, 2)}`);

        // Get list of package.json paths according to Yarn workspaces.
        const paths = getWorkspaces(cwd, flags.workspaces);
        console.log("yarn paths", paths);

lib/getWorkspacesYarn.js

/**
 * Return array of package.json for Yarn workspaces.
 *
 * @param {string} cwd The current working directory where a package.json file can be found.
 * @returns {string[]} An array of package.json files corresponding to the workspaces setting in package.json
 */
function getWorkspacesYarn(cwd, workspaces) {
    // Load package.json
    const manifest = getManifest(`${cwd}/package.json`);

    let packages = manifest.workspaces;
    if (packages && packages.packages) {
        packages = packages.packages;
    }
davikawasaki commented 3 years ago

@antongolub so basically what's needed is parsing the package.json.workspaces value?

antongolub commented 3 years ago

Yep, it's just needed to override this value in some way.

davikawasaki commented 3 years ago

Thanks, I'll have something done and send here.

davikawasaki commented 3 years ago

Working after #42 is merged. Closing.