diff --git a/lib/createInlinePluginCreator.js b/lib/createInlinePluginCreator.js index 2ce23bc..400ecbf 100644 --- a/lib/createInlinePluginCreator.js +++ b/lib/createInlinePluginCreator.js @@ -188,6 +188,10 @@ function createInlinePluginCreator(packages, multiContext, synchronizer, flags) updateManifestDeps(pkg); pkg._depsUpdated = true; + // Set context.commits so analyzeCommits does correct analysis. + // We need to redo this because context is a different instance each time. + context.commits = commits; + const res = await plugins.prepare(context); pkg._prepared = true; diff --git a/test/helpers/git.js b/test/helpers/git.js index 69ee4d5..e615f8a 100644 --- a/test/helpers/git.js +++ b/test/helpers/git.js @@ -307,6 +307,22 @@ function gitGetConfig(cwd, name) { execa.sync("git", ["config", name], { cwd }).stdout; } +/** + * Get the commit message log of given commit SHA or branch name. + * + * @param {string} cwd The CWD of the Git repository. + * @param {integer} number Limit the number of commits to output. + * @param {string} hash The commit SHA or branch name. + * @return {Promise} Promise that resolve to commit log message. + */ +function gitGetLog(cwd, number, hash) { + check(cwd, "cwd: absolute"); + check(number, "number: integer"); + check(hash, "hash: string+"); + + // Run command. + return execa.sync("git", ["log", `-${number}`, hash], { cwd }).stdout; +} // Exports. module.exports = { gitInit, @@ -323,4 +339,5 @@ module.exports = { gitGetTagHash, gitConfig, gitGetConfig, + gitGetLog, }; diff --git a/test/lib/multiSemanticRelease.test.js b/test/lib/multiSemanticRelease.test.js index a935a69..cea6a19 100644 --- a/test/lib/multiSemanticRelease.test.js +++ b/test/lib/multiSemanticRelease.test.js @@ -12,6 +12,7 @@ const { gitPush, gitTag, gitGetTags, + gitGetLog, } = require("../helpers/git"); // Clear mocks before tests. @@ -925,6 +926,56 @@ describe("multiSemanticRelease()", () => { expect(plugin.success).toBeCalledTimes(1); expect(plugin.fail).not.toBeCalled(); }); + test("Bot commit release note should filetered", async () => { + // Create Git repo. + const cwd = gitInit(); + // Initial commit. + copyDirectory(`test/fixtures/yarnWorkspaces/`, cwd); + const sha1 = gitCommitAll(cwd, "feat: Initial release"); + gitTag(cwd, "msr-test-a@1.0.0"); + gitTag(cwd, "msr-test-b@1.0.0"); + gitTag(cwd, "msr-test-c@1.0.0"); + gitTag(cwd, "msr-test-d@1.0.0"); + // Second commit. + writeFileSync(`${cwd}/packages/a/aaa.txt`, "AAA"); + const sha2 = gitCommitAll(cwd, "feat(aaa): Add missing text file"); + + // Third commit. + writeFileSync(`${cwd}/packages/b/bbb.txt`, "BBB"); + const sha3 = gitCommitAll(cwd, "feat(bbb): Add missing text file"); + + const url = gitInitOrigin(cwd); + gitPush(cwd); + + // Capture output. + const stdout = new WritableStreamBuffer(); + const stderr = new WritableStreamBuffer(); + + // Call multiSemanticRelease() + // Include "@semantic-release/git" for made the git head changed + const multiSemanticRelease = require("../../"); + const result = await multiSemanticRelease( + [ + `packages/c/package.json`, + `packages/d/package.json`, + `packages/b/package.json`, + `packages/a/package.json`, + ], + { + plugins: [ + "@semantic-release/release-notes-generator", + "@semantic-release/changelog", + "@semantic-release/git", + ], + analyzeCommits: ["@semantic-release/commit-analyzer"], + }, + { cwd, stdout, stderr }, + { deps: {}, dryRun: false } + ); + + const logOutput = gitGetLog(cwd, 3, "HEAD"); + expect(logOutput).not.toMatch(/.*aaa.*Add missing text file.*\n.*bbb.*Add missing text file.*/); + }); test("Deep errors (e.g. in plugins) bubble up and out", async () => { // Create Git repo with copy of Yarn workspaces fixture. const cwd = gitInit();