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(version): add --changelog-skip-unstable option #3882

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -438,3 +438,285 @@ describe(`lerna publish --conventional-prerelease/graduate fixed w/ changelog`,
`);
});
});

describe(`lerna publish --conventional-prerelease/graduate fixed w/ stable changelog`, () => {
let cwd: string;

beforeAll(async () => {
({ cwd } = await cloneFixture("normal", "chore: init repo"));
await gitTag(cwd, "v1.0.0");
});

test(`release specified stable packages as prerelease, ignoring specified packages`, async () => {
const args = [
"publish",
"--conventional-commits",
"--conventional-prerelease",
"--yes",
];
await commitChangeToPackage(cwd, "package-1", "feat(package-1): Add foo", { foo: true });
await commitChangeToPackage(cwd, "package-2", "fix(package-2): Fix bar", { bar: true });
await commitChangeToPackage(
cwd,
"package-3",
`feat(package-3): Add baz feature${os.EOL}${os.EOL}BREAKING CHANGE: yup`,
{ baz: true }
);

const { stdout } = await cliRunner(cwd, env)(...args);
expect(stdout).toMatchInlineSnapshot(`

Changes:
- package-1: 1.0.0 => 2.0.0-alpha.0
- package-2: 1.0.0 => 2.0.0-alpha.0
- package-3: 1.0.0 => 2.0.0-alpha.0
- package-5: 1.0.0 => 2.0.0-alpha.0 (private)

Successfully published:
- package-1@2.0.0-alpha.0
- package-2@2.0.0-alpha.0
- package-3@2.0.0-alpha.0
`);
});

test(`graduate prerelease packages`, async () => {
const args = [
"publish",
"--conventional-commits",
"--conventional-graduate",
"--changelog-skip-unstable",
"--yes",
];
await commitChangeToPackage(cwd, "package-1", "feat(package-1): Add baz", { baz: true });

const { stdout } = await cliRunner(cwd, env)(...args);
// package-4 is bumped because the graduation to 2.0.0 is a breaking change
// Lerna bumps ALL packages when there is a breaking change when on fixed mode
expect(stdout).toMatchInlineSnapshot(`

Changes:
- package-1: 2.0.0-alpha.0 => 2.0.0
- package-2: 2.0.0-alpha.0 => 2.0.0
- package-3: 2.0.0-alpha.0 => 2.0.0
- package-4: 1.0.0 => 2.0.0
- package-5: 2.0.0-alpha.0 => 2.0.0 (private)

Successfully published:
- package-1@2.0.0
- package-2@2.0.0
- package-3@2.0.0
- package-4@2.0.0
`);
});

test(`generate accurate changelog`, async () => {
// ensure changelog header is not duplicated
const args = ["publish", "--conventional-commits", "--changelog-skip-unstable", "--yes"];
await commitChangeToPackage(cwd, "package-2", "fix(package-2): And another thing", { thing: true });
await cliRunner(cwd, env)(...args);

const changelogFilePaths = await globby(["**/CHANGELOG.md"], {
cwd,
absolute: true,
followSymbolicLinks: false,
});
const [rootChangelog, pkg1Changelog, pkg2Changelog, pkg3Changelog] =
await Promise.all(changelogFilePaths.sort().map((fp) => fs.readFile(fp, "utf8")));

/**
* ./CHANGELOG.md
*/
expect(rootChangelog).toMatchInlineSnapshot(`
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.0.1](/compare/v2.0.0...v2.0.1) (YYYY-MM-DD)


### Bug Fixes

* **package-2:** And another thing ([SHA](COMMIT_URL))





# [2.0.0](/compare/v1.0.0...v2.0.0) (YYYY-MM-DD)


### Features

* **package-1:** Add baz ([SHA](COMMIT_URL))



# 2.0.0-alpha.0 (YYYY-MM-DD)


### Bug Fixes

* **package-2:** Fix bar ([SHA](COMMIT_URL))


### Features

* **package-1:** Add foo ([SHA](COMMIT_URL))
* **package-3:** Add baz feature ([SHA](COMMIT_URL))


### BREAKING CHANGES

* **package-3:** yup





# [2.0.0-alpha.0](/compare/v1.0.0...v2.0.0-alpha.0) (YYYY-MM-DD)


### Bug Fixes

* **package-2:** Fix bar ([SHA](COMMIT_URL))


### Features

* **package-1:** Add foo ([SHA](COMMIT_URL))
* **package-3:** Add baz feature ([SHA](COMMIT_URL))


### BREAKING CHANGES

* **package-3:** yup

`);

expect(pkg1Changelog).toMatchInlineSnapshot(`
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [2.0.0](/compare/v1.0.0...v2.0.0) (YYYY-MM-DD)


### Features

* **package-1:** Add baz ([SHA](COMMIT_URL))



# 2.0.0-alpha.0 (YYYY-MM-DD)


### Features

* **package-1:** Add foo ([SHA](COMMIT_URL))





# [2.0.0-alpha.0](/compare/v1.0.0...v2.0.0-alpha.0) (YYYY-MM-DD)


### Features

* **package-1:** Add foo ([SHA](COMMIT_URL))

Comment on lines +612 to +629
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.0.0-alpha.0 appears twice in this markdown file. This shouldn't happen, as users looking at version 2.0.0 won't care which specific prerelease version the feature was added in. Instead, we should get the changes from all the prereleases aggregated together with the changes from 2.0.0 itself, so it would look like this:

# [2.0.0](/compare/v1.0.0...v2.0.0) (YYYY-MM-DD)


### Features

* **package-1:** Add baz ([SHA](COMMIT_URL))
* **package-1:** Add foo ([SHA](COMMIT_URL))


# [2.0.0-alpha.0](/compare/v1.0.0...v2.0.0-alpha.0) (YYYY-MM-DD)


### Features

* **package-1:** Add foo ([SHA](COMMIT_URL))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fahslaj I do agree that this is the expected markup.

conventional-changelog/conventional-changelog#675 suggests this is an issue with conventional-changelog. However, tests in this PR with independent versioning seem to be correct and the prerelease changes are properly aggregated see here. Any suggestions ?

`);

expect(pkg2Changelog).toMatchInlineSnapshot(`
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.0.1](/compare/v2.0.0...v2.0.1) (YYYY-MM-DD)


### Bug Fixes

* **package-2:** And another thing ([SHA](COMMIT_URL))





# [2.0.0](/compare/v1.0.0...v2.0.0) (YYYY-MM-DD)



# 2.0.0-alpha.0 (YYYY-MM-DD)


### Bug Fixes

* **package-2:** Fix bar ([SHA](COMMIT_URL))





# [2.0.0-alpha.0](/compare/v1.0.0...v2.0.0-alpha.0) (YYYY-MM-DD)


### Bug Fixes

* **package-2:** Fix bar ([SHA](COMMIT_URL))

`);

expect(pkg3Changelog).toMatchInlineSnapshot(`
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.0.1](/compare/v2.0.0...v2.0.1) (YYYY-MM-DD)

**Note:** Version bump only for package package-3





# [2.0.0](/compare/v1.0.0...v2.0.0) (YYYY-MM-DD)



# 2.0.0-alpha.0 (YYYY-MM-DD)


### Features

* **package-3:** Add baz feature ([SHA](COMMIT_URL))


### BREAKING CHANGES

* **package-3:** yup





# [2.0.0-alpha.0](/compare/v1.0.0...v2.0.0-alpha.0) (YYYY-MM-DD)


### Features

* **package-3:** Add baz feature ([SHA](COMMIT_URL))


### BREAKING CHANGES

* **package-3:** yup

`);
});

});