Skip to content

Commit

Permalink
feat: let publish step run in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed May 21, 2020
1 parent df68c96 commit 4d5c451
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 52 deletions.
59 changes: 10 additions & 49 deletions lib/createInlinePluginCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ function createInlinePluginCreator(packages, multiContext) {
pkg._nextType = await plugins.analyzeCommits(context);

// Wait until all todo packages have been analyzed.
await waitFor("_nextType");
pkg._analyzed = true;
await waitFor("_analyzed");

// Make sure type is "patch" if the package has any deps that have changed.
if (!pkg._nextType && hasChangedDeep(pkg._localDeps)) pkg._nextType = "patch";
Expand Down Expand Up @@ -192,65 +193,25 @@ function createInlinePluginCreator(packages, multiContext) {
return notes.join("\n\n");
};

/**
* Prepare step.
* Responsible for preparing the release, for example creating or updating files such as package.json, CHANGELOG.md, documentation or compiled assets and pushing a commit.
*
* In multirelease: Writes current version of local dependencies to package.json, and serialises the publishing so it's not happening simultaneously.
*
* @param {object} pluginOptions Options to configure this plugin.
* @param {object} context The semantic-release context.
* @returns {Promise<void>} Promise that resolves when done.
*
* @internal
*/
const prepare = async (pluginOptions, context) => {
await plugins.prepare(context);

// Package is prepared.
const publish = async () => {
pkg._prepared = true;
};

// These steps just passthrough to plugins.
const verifyConditions = (pluginOptions, context) => plugins.verifyConditions(context);
const verifyRelease = (pluginOptions, context) => plugins.verifyRelease(context);
const publish = async (pluginOptions, context) => {
const result = await plugins.publish(context);
const nextPkgToProcess = todo().find((p) => !p._prepared);

// istanbul ignore next
return result.length ? result[0] : {};
};

const postProcess = async (context, cb) => {
pkg._processed = true;
const nextToPublish = todo().find((p) => !p._processed);

if (nextToPublish) {
context.logger.log("next package to process", nextToPublish.name);
ee.emit(nextToPublish.name);
} else {
context.logger.log("looks like there's no package to publish next");
if (nextPkgToProcess) {
ee.emit(nextPkgToProcess.name);
}

return cb(context);
// Wait for all packages to be `prepare`d and tagged by `semantic-release`
await waitFor("_prepared");

return {};
};
const success = async (pluginOptions, context) => postProcess(context, plugins.success);
// istanbul ignore next
const fail = (pluginOptions, context) => postProcess(context, plugins.fail);
// istanbul ignore next
const addChannel = (pluginOptions, context) => plugins.addChannel(context);

// Exports.
return {
verifyConditions,
analyzeCommits,
verifyRelease,
generateNotes,
prepare,
publish,
success,
fail,
addChannel,
};
}

Expand Down
13 changes: 12 additions & 1 deletion lib/multiSemanticRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,18 @@ async function releasePackage(pkg, createInlinePlugin, multiContext) {
// The inline plugin is the only plugin we call semanticRelease() with.
// The inline plugin functions then call e.g. plugins.analyzeCommits() manually and sometimes manipulate the responses.
const inlinePlugin = createInlinePlugin(pkg);
options.plugins = [inlinePlugin];

// If option step is defined `semrel` config resolver overrides the previous value set by `options.plugins`.
const joinedSteps = Object.keys(inlinePlugin).reduce((joined, type) => {
const a = inlinePlugin[type];
const b = options[type];

joined[type] = b ? [a].concat(b) : a;

return joined;
}, {});

Object.assign(options, joinedSteps);

// Call semanticRelease() on the directory and save result to pkg.
// Don't need to log out errors as semantic-release already does that.
Expand Down
2 changes: 0 additions & 2 deletions test/lib/multiSemanticRelease.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const {
gitTag,
gitGetTags,
} = require("../helpers/git");
const execa = require("execa");
const tempy = require("tempy");

// Clear mocks before tests.
beforeEach(() => {
Expand Down

0 comments on commit 4d5c451

Please sign in to comment.