Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: ignore packages to be released with workspaces and CLI #42

Merged
merged 66 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
fd8fcad
feat(helpers/file): added file creation on list of folders
davikawasaki Dec 23, 2020
da7b781
feat(helpers/git): added release branch creation on git init origin e…
davikawasaki Dec 23, 2020
4850de3
feat(prerelease): enabled correct prerelease updates on dependencies
davikawasaki Dec 23, 2020
de5265e
chore(update-deps): reducing cognitive complexity
davikawasaki Dec 23, 2020
fa57c5a
test(update-deps): setting nextVersion as last param on test cases
davikawasaki Dec 23, 2020
eedf2f2
Merge branch 'master' of https://github.com/qiwi/multi-semantic-relea…
davikawasaki Dec 30, 2020
fc378b4
test: added fixture for 2 packages only
davikawasaki Dec 30, 2020
a8e40c8
chore: updated package lock
davikawasaki Dec 30, 2020
cadc3a8
fix: avoid local dep bump when it's not updated
davikawasaki Dec 30, 2020
d6b4ed2
chore: package update + changelog merge
davikawasaki Jan 4, 2021
54c7af8
feat: branch name available at pkg level
davikawasaki Jan 4, 2021
ac4962b
feat: git module to get filtered tags from a branch
davikawasaki Jan 4, 2021
7d299d8
feat: tweak utils from semantic-release
davikawasaki Jan 4, 2021
a654af5
fix: getNextPreVersion updated to cover edge cases
davikawasaki Jan 4, 2021
a1fedc7
test: covers semantic release on a release-prerelease branch change
davikawasaki Jan 4, 2021
2632492
chore: reducing code complexity
davikawasaki Jan 4, 2021
97c21aa
fix: refactor validateSubstr fn
davikawasaki Jan 5, 2021
5533a08
fix: refactor highest/lowest fn, fail fast on tagsToVersions
davikawasaki Jan 5, 2021
4f55c95
fix: reducing code cognitive complexity on getNextPreVersion
davikawasaki Jan 5, 2021
ef4a351
fix: refactor nextPreVersion to reduce code complexity
davikawasaki Jan 5, 2021
1f6bc2b
chore: merging from upstream
davikawasaki Jan 5, 2021
ed6c89b
chore: todo to replace cwd on getNextPreVersion
davikawasaki Jan 5, 2021
9311ad6
Merge branch 'master' of git://github.com/qiwi/multi-semantic-release…
davikawasaki Jan 5, 2021
4e49378
Merge remote-tracking branch 'upstream/master' into master
davikawasaki Jan 26, 2021
639f5b9
chore: yarnWorkspace fixtures with ! ignore packages
davikawasaki Feb 2, 2021
d2fee0d
feat: replaced bash-glob to node-glob
davikawasaki Feb 2, 2021
9cb2f55
feat: getWorkspacesYarn with CLI and package.json ignorePackages
davikawasaki Feb 2, 2021
ba7652e
test: getWorkspacesYarn with ignored packages cases
davikawasaki Feb 2, 2021
0fa992e
feat: ignorePackages flag on cli
davikawasaki Feb 2, 2021
6ec871d
test: cli test to filter 2 packages
davikawasaki Feb 2, 2021
13f5946
feat: runner passing ignorePackages flag from CLI
davikawasaki Feb 2, 2021
cd6a28b
chore: replaced bash-glob with glob
davikawasaki Feb 2, 2021
b965c72
fix: flags ignorePackages or null
davikawasaki Feb 2, 2021
f703e0e
docs: cli options on readme
davikawasaki Feb 2, 2021
4030ae6
Merge remote-tracking branch 'upstream/master' into master
davikawasaki Feb 2, 2021
3783d68
Merge branch 'master' into feat/ignorePckgs
davikawasaki Feb 2, 2021
f6d3224
fix: reduce cognitive complexity
davikawasaki Feb 2, 2021
8ac4bf2
feat(prerelease): enabled correct prerelease updates on dependencies
davikawasaki Dec 23, 2020
d922940
chore(update-deps): reducing cognitive complexity
davikawasaki Dec 23, 2020
66269ef
chore: updated package lock
davikawasaki Dec 30, 2020
9834cca
chore: reducing code complexity
davikawasaki Jan 4, 2021
dd73624
fix: refactor highest/lowest fn, fail fast on tagsToVersions
davikawasaki Jan 5, 2021
147e7fb
fix: reducing code cognitive complexity on getNextPreVersion
davikawasaki Jan 5, 2021
7aa052c
fix: refactor nextPreVersion to reduce code complexity
davikawasaki Jan 5, 2021
c3e14ed
chore: yarnWorkspace fixtures with ! ignore packages
davikawasaki Feb 2, 2021
1893927
feat: replaced bash-glob to node-glob
davikawasaki Feb 2, 2021
2038f8c
feat: getWorkspacesYarn with CLI and package.json ignorePackages
davikawasaki Feb 2, 2021
9fe8830
test: getWorkspacesYarn with ignored packages cases
davikawasaki Feb 2, 2021
928de24
feat: ignorePackages flag on cli
davikawasaki Feb 2, 2021
6ff3616
test: cli test to filter 2 packages
davikawasaki Feb 2, 2021
3e1f0a8
feat: runner passing ignorePackages flag from CLI
davikawasaki Feb 2, 2021
e445530
chore: replaced bash-glob with glob
davikawasaki Feb 2, 2021
8b06c57
fix: flags ignorePackages or null
davikawasaki Feb 2, 2021
2e8a184
docs: cli options on readme
davikawasaki Feb 2, 2021
ece0a2d
fix: reduce cognitive complexity
davikawasaki Feb 2, 2021
dc339e9
Merge branch 'feat/ignorePckgs' of github.com:davikawasaki/multi-sema…
davikawasaki Feb 2, 2021
5a5c181
chore: rebase problems
davikawasaki Feb 2, 2021
61387a8
fix: change node-glob to globby
davikawasaki Feb 2, 2021
b986ca8
fix: globby on lib/glob and change glob realpath option to absolute
davikawasaki Feb 2, 2021
1938977
fix: remove unnecessary null validation
davikawasaki Feb 2, 2021
06de972
chore: ignore node_modules with globstar
davikawasaki Feb 2, 2021
35ff621
refactor: ignore packages inside method and running glob.sync once
davikawasaki Feb 2, 2021
11fdada
feat: removed ignore, added gitignore and added cli packages to be ig…
davikawasaki Feb 3, 2021
40e971b
test: increased test timeouts on full msr prerelease process
davikawasaki Feb 3, 2021
42103fc
fix: combine cli options with workspaces instead of overriding them
davikawasaki Feb 4, 2021
2347995
docs: enhance docs with ignore options
davikawasaki Feb 4, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/node_modules/
**/node_modules/**
/coverage/
*.log
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ yarn add @qiwi/multi-semantic-release --dev
multi-semantic-release
```

CLI flag options:

```sh
Options
--dry-run Dry run mode.
--debug Output debugging information.
--sequential-init Avoid hypothetical concurrent initialization collisions.
--first-parent Apply commit filtering to current branch only.
--deps.bump Define deps version updating rule. Allowed: override, satisfy, inherit.
--deps.release Define release type for dependent package if any of its deps changes. Supported values: patch, minor, major, inherit.
--ignore-packages Packages list to be ignored on bumping process (append to the ones that already exist at package.json workspaces)
--help Help info.

Examples
$ multi-semantic-release --debug
$ multi-semantic-release --deps.bump=satisfy --deps.release=patch
$ multi-semantic-release --ignore-packages=packages/a/**,packages/b/**
```

## Configuration
**MSR** requires **semrel** config to be added [in any supported format](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration) for each package or/and declared in repo root (`globalConfig` is extremely useful if all the modules have the same strategy of release).
NOTE config resolver joins `globalConfig` and `packageConfig` during execution.
Expand All @@ -34,6 +53,41 @@ const { options: pkgOptions } = await getConfig(dir);
const finalOptions = Object.assign({}, globalOptions, pkgOptions);
```

Make sure to have a `workspaces` attribute inside your `package.json` project file. In there, you can set a list of packages that you might want to process in the msr process, as well as ignore others. For example, let's say your project has 4 packages (i.e. a, b, c and d) and you want to process only a and d (ignore b and c). You can set the following structure in your `package.json` file:

```json
{
"name": "msr-test-yarn",
"author": "Dave Houlbrooke <dave@shax.com",
"version": "0.0.0-semantically-released",
"private": true,
"license": "0BSD",
"engines": {
"node": ">=8.3"
},
"workspaces": [
"packages/*",
"!packages/b/**",
"!packages/c/**"
],
"release": {
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator"
],
"noCi": true
}
}
```

You can also ignore it with the CLI:

```bash
$ multi-semantic-release --ignore-packages=packages/b/**,packages/c/**
```

You can also combine the CLI ignore options with the `!` operator at each package inside `workspaces` attribute. Even though you can use the CLI to ignore options, you can't use it to set which packages to be released – i.e. you still need to set the `workspaces` attribute inside the `package.json`.

## Verified examples
We use this tool to release our JS platform code inhouse (GitHub Enterprise + JB TeamCity) and for our OSS (GitHub + Travis CI). Guaranteed working configurations available in projects.
* [qiwi/substrate](https://github.com/qiwi/substrate)
Expand Down
16 changes: 13 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ const cli = meow(
--sequential-init Avoid hypothetical concurrent initialization collisions.
--first-parent Apply commit filtering to current branch only.
--deps.bump Define deps version updating rule. Allowed: override, satisfy, inherit.
--deps.release Define release type for dependent package if any of its deps changes. Supported values: patch, minor, major, inherit.
--deps.release Define release type for dependent package if any of its deps changes. Supported values: patch, minor, major, inherit.
--ignore-packages Packages' list to be ignored on bumping process
--help Help info.

Examples
$ multi-semantic-release --debug
$ multi-semantic-release --deps.bump=satisfy --deps.release=patch
$ multi-semantic-release --deps.bump=satisfy --deps.release=patch
$ multi-semantic-release --ignore-packages=packages/a/**,packages/b/**
`,
{
flags: {
Expand All @@ -40,13 +42,21 @@ const cli = meow(
type: "string",
default: "patch",
},
ignorePackages: {
type: "string",
},
dryRun: {
type: "boolean",
},
},
}
);

const processFlags = (flags) => toPairs(flags).reduce((m, [k, v]) => set(m, k, v), {});
const processFlags = (flags) => {
return toPairs(flags).reduce((m, [k, v]) => {
if (k === "ignorePackages" && v) return set(m, k, v.split(","));
return set(m, k, v);
}, {});
};

runner(processFlags(cli.flags));
2 changes: 1 addition & 1 deletion bin/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = (flags) => {
console.log(`flags: ${JSON.stringify(flags, null, 2)}`);

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

// Do multirelease (log out any errors).
Expand Down
10 changes: 7 additions & 3 deletions lib/getWorkspacesYarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const { checker } = require("./blork");
* Return array of package.json for Yarn workspaces.
*
* @param {string} cwd The current working directory where a package.json file can be found.
* @param {string[]|null} ignorePackages (Optional) Packages to be ignored passed via cli.
* @returns {string[]} An array of package.json files corresponding to the workspaces setting in package.json
*/
function getWorkspacesYarn(cwd) {
function getWorkspacesYarn(cwd, ignorePackages = null) {
// Load package.json
const manifest = getManifest(`${cwd}/package.json`);

Expand All @@ -22,13 +23,16 @@ function getWorkspacesYarn(cwd) {
throw new TypeError("package.json: workspaces or workspaces.packages: Must be non-empty array of string");
}

// If packages to be ignored come from CLI, we need to combine them with the ones from manifest workspaces
if (Array.isArray(ignorePackages)) packages.push(...ignorePackages.map((p) => `!${p}`));

// Turn workspaces into list of package.json files.
const workspaces = glob(
packages.map((p) => p.replace(/\/?$/, "/package.json")),
{
cwd: cwd,
realpath: true,
ignore: "**/node_modules/**",
absolute: true,
gitignore: true,
}
);

Expand Down
9 changes: 3 additions & 6 deletions lib/glob.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const bashGlob = require("bash-glob");
const bashPath = require("bash-path");
const globby = require("globby");

module.exports = (...args) => {
if (!bashPath) {
throw new TypeError("`bash` must be installed"); // TODO move this check to bash-glob
}
const [pattern, ...options] = args;

return bashGlob.sync(...args);
return globby.sync(pattern, ...options);
};
1 change: 0 additions & 1 deletion lib/updateDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const getVersionFromTag = (pkg, tag) => (pkg.name ? tag.replace(`${pkg.name}@`,
const getNextPreVersion = (pkg, tags) => {
const tagFilters = [pkg._preRelease];
const lastVersion = pkg._lastRelease && pkg._lastRelease.version;
const version = `1.0.0-${pkg._preRelease}.1`;

// Extract tags:
// 1. Set filter to extract only package tags
Expand Down
Loading