Skip to content

Commit

Permalink
fix(release): default changelog git commit and tag true (#21129)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored Jan 16, 2024
1 parent 16b3f14 commit f024923
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 176 deletions.
157 changes: 40 additions & 117 deletions e2e/release/src/independent-projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ describe('nx release - independent projects', () => {
+ This was a version bump only for {project-name} to align it with other projects, there were no code changes.
> NX Committing changes with git
> NX Tagging commit with git
`);

// pkg2
Expand All @@ -436,6 +442,12 @@ describe('nx release - independent projects', () => {
+ This was a version bump only for {project-name} to align it with other projects, there were no code changes.
> NX Committing changes with git
> NX Tagging commit with git
`);

// pkg3
Expand All @@ -457,30 +469,23 @@ describe('nx release - independent projects', () => {
+ This was a version bump only for {project-name} to align it with other projects, there were no code changes.
> NX Committing changes with git
> NX Tagging commit with git
`);
}, 500000);

it('should support automated git operations after changelog when configured', async () => {
it('should support automated git operations after changelog by default', async () => {
// No project changelog yet
expect(exists(joinPathFragments(pkg1, 'CHANGELOG.md'))).toEqual(false);

const headSHA = runCommand(`git rev-parse HEAD`).trim();
runCLI(
`release changelog 999.9.9-changelog-git-operations-test.1 -p ${pkg1}`
);
// No git operations should have been performed by the previous command because not yet configured in nx.json nor passed as a flag
expect(runCommand(`git rev-parse HEAD`).trim()).toEqual(headSHA);

expect(readFile(joinPathFragments(pkg1, 'CHANGELOG.md')))
.toMatchInlineSnapshot(`
## 999.9.9-changelog-git-operations-test.1 (YYYY-MM-DD)
This was a version bump only for {project-name} to align it with other projects, there were no code changes.
`);

// Enable git commit and tag operations via CLI flags
const versionWithGitActionsCLIOutput = runCLI(
`release changelog 999.9.9-changelog-git-operations-test.2 -p ${pkg1} --git-commit --git-tag --verbose` // add verbose so we get richer output
`release changelog 999.9.9-changelog-git-operations-test.1 -p ${pkg1} --verbose`
);
expect(versionWithGitActionsCLIOutput).toMatchInlineSnapshot(`
Expand All @@ -489,16 +494,12 @@ describe('nx release - independent projects', () => {
- {project-name}
> NX Generating an entry in {project-name}/CHANGELOG.md for {project-name}@999.9.9-changelog-git-operations-test.2
> NX Generating an entry in {project-name}/CHANGELOG.md for {project-name}@999.9.9-changelog-git-operations-test.1
+ ## 999.9.9-changelog-git-operations-test.2 (YYYY-MM-DD)
+ ## 999.9.9-changelog-git-operations-test.1 (YYYY-MM-DD)
+
+ This was a version bump only for {project-name} to align it with other projects, there were no code changes.
+
## 999.9.9-changelog-git-operations-test.1 (YYYY-MM-DD)
This was a version bump only for {project-name} to align it with other projects, there were no code changes.
> NX Committing changes with git
Expand All @@ -507,12 +508,12 @@ describe('nx release - independent projects', () => {
git add {project-name}/CHANGELOG.md
Committing files in git with the following command:
git commit --message chore(release): publish --message - project: {project-name} 999.9.9-changelog-git-operations-test.2
git commit --message chore(release): publish --message - project: {project-name} 999.9.9-changelog-git-operations-test.1
> NX Tagging commit with git
Tagging the current commit in git with the following command:
git tag --annotate {project-name}@999.9.9-changelog-git-operations-test.2 --message {project-name}@999.9.9-changelog-git-operations-test.2
git tag --annotate {project-name}@999.9.9-changelog-git-operations-test.1 --message {project-name}@999.9.9-changelog-git-operations-test.1
`);

Expand All @@ -523,26 +524,30 @@ describe('nx release - independent projects', () => {
.toMatchInlineSnapshot(`
chore(release): publish
- project: {project-name} 999.9.9-changelog-git-operations-test.2
- project: {project-name} 999.9.9-changelog-git-operations-test.1
`);
// Tags
expect(runCommand('git tag --points-at HEAD')).toMatchInlineSnapshot(`
{project-name}@999.9.9-changelog-git-operations-test.2
{project-name}@999.9.9-changelog-git-operations-test.1
`);

expect(readFile(joinPathFragments(pkg1, 'CHANGELOG.md')))
.toMatchInlineSnapshot(`
## 999.9.9-changelog-git-operations-test.2 (YYYY-MM-DD)
This was a version bump only for {project-name} to align it with other projects, there were no code changes.
## 999.9.9-changelog-git-operations-test.1 (YYYY-MM-DD)
This was a version bump only for {project-name} to align it with other projects, there were no code changes.
`);

// Enable git commit and tag operations for the changelog command via config
const updatedHeadSHA = runCommand(`git rev-parse HEAD`).trim();
// Disable git commit and tag operations via CLI flags
runCLI(
`release changelog 999.9.9-changelog-git-operations-test.2 -p ${pkg1} --git-commit=false --git-tag=false --verbose` // add verbose so we get richer output
);
// No git operations should have been performed by the previous command
expect(runCommand(`git rev-parse HEAD`).trim()).toEqual(updatedHeadSHA);

// Disable git commit and tag operations for the changelog command via config
updateJson('nx.json', (json) => {
return {
...json,
Expand All @@ -551,8 +556,8 @@ describe('nx release - independent projects', () => {
changelog: {
...json.release.changelog,
git: {
commit: true,
tag: true,
commit: false,
tag: false,
},
},
// Configure multiple release groups with different relationships to capture differences in commit body
Expand All @@ -570,94 +575,12 @@ describe('nx release - independent projects', () => {
};
});

const versionWithGitActionsConfigOutput = runCLI(
runCLI(
`release changelog 999.9.9-changelog-git-operations-test.3 --verbose` // add verbose so we get richer output
);
expect(versionWithGitActionsConfigOutput).toMatchInlineSnapshot(`
> NX Generating an entry in {project-name}/CHANGELOG.md for {project-name}@999.9.9-changelog-git-operations-test.3
+ ## 999.9.9-changelog-git-operations-test.3 (YYYY-MM-DD)
+
+ This was a version bump only for {project-name} to align it with other projects, there were no code changes.
+
## 999.9.9-changelog-git-operations-test.2 (YYYY-MM-DD)
This was a version bump only for {project-name} to align it with other projects, there were no code changes.

> NX Generating an entry in {project-name}/CHANGELOG.md for {project-name}@999.9.9-changelog-git-operations-test.3
+ ## 999.9.9-changelog-git-operations-test.3 (YYYY-MM-DD)
+
+ This was a version bump only for {project-name} to align it with other projects, there were no code changes.
> NX Generating an entry in {project-name}/CHANGELOG.md for v999.9.9-changelog-git-operations-test.3
+ ## 999.9.9-changelog-git-operations-test.3 (YYYY-MM-DD)
+
+ This was a version bump only for {project-name} to align it with other projects, there were no code changes.
> NX Committing changes with git
Staging files in git with the following command:
git add {project-name}/CHANGELOG.md {project-name}/CHANGELOG.md {project-name}/CHANGELOG.md
Committing files in git with the following command:
git commit --message chore(release): publish --message - project: {project-name} 999.9.9-changelog-git-operations-test.3 --message - project: {project-name} 999.9.9-changelog-git-operations-test.3 --message - release-group: fixed 999.9.9-changelog-git-operations-test.3
> NX Tagging commit with git
Tagging the current commit in git with the following command:
git tag --annotate {project-name}@999.9.9-changelog-git-operations-test.3 --message {project-name}@999.9.9-changelog-git-operations-test.3
Tagging the current commit in git with the following command:
git tag --annotate {project-name}@999.9.9-changelog-git-operations-test.3 --message {project-name}@999.9.9-changelog-git-operations-test.3
Tagging the current commit in git with the following command:
git tag --annotate v999.9.9-changelog-git-operations-test.3 --message v999.9.9-changelog-git-operations-test.3
`);

// Ensure the git operations were performed
expect(runCommand(`git rev-parse HEAD`).trim()).not.toEqual(headSHA);
// Commit
expect(runCommand(`git --no-pager log -1 --pretty=format:%B`).trim())
.toMatchInlineSnapshot(`
chore(release): publish
- project: {project-name} 999.9.9-changelog-git-operations-test.3
- project: {project-name} 999.9.9-changelog-git-operations-test.3
- release-group: fixed 999.9.9-changelog-git-operations-test.3
`);
// Tags
expect(runCommand('git tag --points-at HEAD')).toMatchInlineSnapshot(`
{project-name}@999.9.9-changelog-git-operations-test.3
{project-name}@999.9.9-changelog-git-operations-test.3
v999.9.9-changelog-git-operations-test.3
`);

expect(readFile(joinPathFragments(pkg1, 'CHANGELOG.md')))
.toMatchInlineSnapshot(`
## 999.9.9-changelog-git-operations-test.3 (YYYY-MM-DD)
This was a version bump only for {project-name} to align it with other projects, there were no code changes.
## 999.9.9-changelog-git-operations-test.2 (YYYY-MM-DD)
This was a version bump only for {project-name} to align it with other projects, there were no code changes.
## 999.9.9-changelog-git-operations-test.1 (YYYY-MM-DD)
This was a version bump only for {project-name} to align it with other projects, there were no code changes.
`);
// Ensure no git operations were performed
expect(runCommand(`git rev-parse HEAD`).trim()).toEqual(updatedHeadSHA);
});
});

Expand Down
36 changes: 16 additions & 20 deletions e2e/release/src/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ ${JSON.stringify(
+ - Test @{COMMIT_AUTHOR}
> NX Committing changes with git
> NX Tagging commit with git
`);

expect(readFile('CHANGELOG.md')).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -713,14 +719,7 @@ ${JSON.stringify(
+ ## 1000.0.0-next.0 (YYYY-MM-DD)
+
+
+ ### 🚀 Features
+
+ - an awesome new feature ([{COMMIT_SHA}](https://github.com/nrwl/fake-repo/commit/{COMMIT_SHA}))
+
+ ### ❤️ Thank You
+
+ - Test @{COMMIT_AUTHOR}
+ This was a version bump only, there were no code changes.
+
## 999.9.9 (YYYY-MM-DD)
Expand All @@ -732,32 +731,29 @@ ${JSON.stringify(
+ ## 1000.0.0-next.0
+
+
+ ### 🚀 Features
+
+ - an awesome new feature
+ This was a version bump only for {project-name} to align it with other projects, there were no code changes.
> NX Previewing a GitHub release and an entry in {project-name}/CHANGELOG.md for v1000.0.0-next.0
+ ## 1000.0.0-next.0
+
+
+ ### 🚀 Features
+
+ - an awesome new feature
+ This was a version bump only for {project-name} to align it with other projects, there were no code changes.
> NX Previewing a GitHub release and an entry in {project-name}/CHANGELOG.md for v1000.0.0-next.0
+ ## 1000.0.0-next.0
+
+
+ ### 🚀 Features
+
+ - an awesome new feature
+ This was a version bump only for {project-name} to align it with other projects, there were no code changes.
> NX Committing changes with git
> NX Tagging commit with git
`);
Expand Down
Loading

0 comments on commit f024923

Please sign in to comment.