Repository: commitizen-tools/commitizen

Issue:
Produce changelog with `cz bump --dry-run --changelog-to-stdout`
### Description

I'm using the commitizen pre-commit hook paired with renovate for automated dependency updates.

I'd like to test the commitizen functionality before merging the upgrade PR. One thing I'd like to see is if the changelog is being generated correctly.

### Issue: 
pairing the `--dry-run` arg with `--changelog-to-stdout` does not produce the changelog


### Steps to reproduce

1. checkout your repository at an older version tag `git checkout 1.0.0`
2. soft reset to a newer version `git reset --soft 1.1.0`
3. `cz bump --changelog-to-stdout --dry-run`

not sure if this matters, but `changelog_incremental = true`

### Current behavior

```
cz bump --changelog-to-stdout --dry-run
bump: version 1.0.0 → 1.1.0
tag to create: 9.6.0
increment detected: MINOR
```

### Desired behavior

```
cz bump --changelog-to-stdout --dry-run
bump: version 1.0.0 → 1.1.0
tag to create: 1.1.0
increment detected: MINOR

## 1.1.0 (2022-07-25)

### CHANGELOG SHOWS UP HERE
```

### Screenshots

_No response_

### Environment

```
cz version --report
Commitizen Version: 2.27.1
Python Version: 3.10.4 (main, May 26 2022, 14:56:41) [Clang 13.1.6 (clang-1316.0.21.2.5)]
Operating System: Darwin
```

Discussion:

Patch:
diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py
index 17f929bd..cbc5266d 100644
--- a/commitizen/commands/bump.py
+++ b/commitizen/commands/bump.py
@@ -180,17 +180,6 @@ class Bump:
                 "The commits found are not elegible to be bumped"
             )
 
-        # Do not perform operations over files or git.
-        if dry_run:
-            raise DryRunExit()
-
-        bump.update_version_in_files(
-            current_version,
-            str(new_version),
-            version_files,
-            check_consistency=self.check_consistency,
-        )
-
         if self.changelog:
             if self.changelog_to_stdout:
                 changelog_cmd = Changelog(
@@ -216,6 +205,17 @@ class Bump:
             changelog_cmd()
             c = cmd.run(f"git add {changelog_cmd.file_name} {' '.join(version_files)}")
 
+        # Do not perform operations over files or git.
+        if dry_run:
+            raise DryRunExit()
+
+        bump.update_version_in_files(
+            current_version,
+            str(new_version),
+            version_files,
+            check_consistency=self.check_consistency,
+        )
+
         self.config.set_key("version", str(new_version))
 
         if is_files_only:


Test patch:
diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py
index daf3d42b..927a7190 100644
--- a/tests/commands/test_bump_command.py
+++ b/tests/commands/test_bump_command.py
@@ -500,3 +500,21 @@ def test_bump_with_changelog_to_stdout_arg(mocker, capsys, changelog_path):
         out = f.read()
     assert out.startswith("#")
     assert "0.2.0" in out
+
+
+@pytest.mark.usefixtures("tmp_commitizen_project")
+def test_bump_with_changelog_to_stdout_dry_run_arg(mocker, capsys, changelog_path):
+    create_file_and_commit(
+        "feat(user): this should appear in stdout with dry-run enabled"
+    )
+    testargs = ["cz", "bump", "--yes", "--changelog-to-stdout", "--dry-run"]
+    mocker.patch.object(sys, "argv", testargs)
+    with pytest.raises(DryRunExit):
+        cli.main()
+    out, _ = capsys.readouterr()
+
+    tag_exists = git.tag_exist("0.2.0")
+    assert tag_exists is False
+    assert out.startswith("#")
+    assert "this should appear in stdout with dry-run enabled" in out
+    assert "0.2.0" in out