orhun / git-cliff

A highly customizable Changelog Generator that follows Conventional Commit specifications ⛰️
https://git-cliff.org
Apache License 2.0
9.27k stars 198 forks source link

feat: output generated changelog blurb to both stdout and file for further processing #643

Closed favna closed 5 months ago

favna commented 6 months ago

Is there an existing issue or pull request for this?

Feature description

Currently when --prepend is provided git-cliff will output the generated CHANGELOG section for the desired release to the file that is provided through --prepend. It would be nice if it could also be send to the STDOUT through a flag so it can be picked up for further processing. It should be noted that if --prepend is not provided then git-cliff does print to stdout.

The motivation for this feature is that I could then use it for @favware/cliff-jumper to capture it and send it to the body of a GitHub release when calling the Create Release API endpoint. Currently, my CLI stops after updating the changelog and creating the Git tag locally, but if I can capture the release body I can make it possible to push the Git tag to the remote repository and create a release from that tag so a full release flow can be automated.

Desired solution

  1. The least breaking way to achieve this would be a flag such as --stdout, which when paired with --prepend ./CHANGELOG.md will write to both the CHANGELOG.md to print to stdout. Documentation would be able to clarify what the behaviour is of combining these 2 options.
  2. A breaking way to achieve this would be to make it so the output always has to be provided, i.e. --output /dev/stdout/ --output ./CHANGELOG.md. The equivalent of only --prepend ./CHANGELOG.md would then be --prepend ./CHANGELOG.md --output ./CHANGELOG.md
    1. Alternatively a way to do this non-breaking would be that if --output is not provided the current behaviour is retained, however in my opinion this becomes confusing because then what is going to happen if the user provides options like --prepend ./CHANGELOG.md --output ./CHANGELOG.md
    2. What also concerns me with this solution is cross-platform compatibility. While Linux and MacOS will work with /dev/stdout/, I do not know for sure if this will work for Windows users. I would prefer if I do not have to do OS checking in @favware/cliff-jumper to account for this. With the former solution of --stdout the advantage is that as a user of git-cliff I do not need to think about how exactly I can write to stdout for my operating system as git-cliff will automatically do that.

Alternatives considered

Running git-cliff twice, first to print to stdout without --prepend and then to CHANGELOG.md file with --prepend. This is less ideal because of the "run twice" factor.

Additional context

Also discussed on Discord here: https://discord.com/channels/1093977388892819553/1093978266135707668/1237529889113112607

orhun commented 6 months ago

Thanks for the issue! The following command works if you want to both prepend and save it to a file:

$ git-cliff -p CHANGELOG.md -l -o OTHER.md

I am guessing if we support - for stdout then it will be even more convenient, e.g. git-cliff -p 1.md -l -o - > 2.md

What do you think of this?

favna commented 6 months ago

Hm that might work but I'd like to try it from a WIP branch to be sure because I'm not sure how execa from Node handles trailing - to send it to stdout.

orhun commented 6 months ago

Sure, I can implement it soon and you can probably check it out from the PR!

orhun commented 6 months ago

Boop boop #644