orhun / git-cliff-action

GitHub action to generate a changelog based on the Git history
https://github.com/orhun/git-cliff
Apache License 2.0
117 stars 14 forks source link

Write changelog to a file in the repo #13

Closed amitav13 closed 8 months ago

amitav13 commented 9 months ago

Hi, Might be doing something dumb, but - is there no way to write the changelog to a CHANGELOG.md within the repo itself? Is that not something that's usual?

Thanks for the action!

orhun commented 9 months ago

Hello!

You can probably do something like this:

jobs:
  changelog:
    name: Generate changelog
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Generate a changelog
        uses: orhun/git-cliff-action@v2
        with:
          config: cliff.toml
          args: --verbose
        env:
          OUTPUT: CHANGELOG.md

      - name: Commit
        run: |
          git config user.name 'github-actions[bot]'
          git config user.email 'github-actions[bot]@users.noreply.github.com'
          set +e
          git add CHANGELOG.md
          git commit -m "Update changelog"
          git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git upstream

First it creates the changelog as CHANGELOG.md and commits it to the repo as GitHub Actions bot user.

I hope this is helpful 🐻 let me know if it works for you and we can probably mention this in README.md

amitav13 commented 9 months ago

Hey no, getting this error: CleanShot 2023-12-06 at 19 09 10

Was getting the same one when I had the ${GITHUB_REPOSITORY} tag as well.

Here's my action yaml:

name: "Tagged release"

on:
  push:
    tags:
      - "[0-9].[0-9].[0-9]*"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  changelog:
    name: Generate changelog
    runs-on: ubuntu-latest
    outputs:
      release_body: ${{ steps.git-cliff.outputs.content }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Generate a changelog
        uses: orhun/git-cliff-action@v2
        id: git-cliff
        with:
          config: cliff.toml
          args: --latest --strip header
        env:
          OUTPUT: CHANGELOG.md
      - name: Commit changes to changelog
        run: |
          git config user.name 'github-actions[bot]'
          git config user.email 'github-actions[bot]@users.noreply.github.com'
          set +e
          git add CHANGELOG.md
          git commit -m "ci: Update changelog"
          git push https://${{ secrets.GITHUB_TOKEN }}@github.com/Get-Salesmonk/saasmonk-chat.git upstream
orhun commented 9 months ago

Wait I made a mistake while sharing the example workflow, upstream should actually match the name of the branch that you want to push to (e.g. main).

Can you try again with the correct branch name?

realfabecker commented 8 months ago

It worked perfectly for my use case, thank you very much!

orhun commented 8 months ago

Thanks for confirming! I added this example to the README.md in 9f1ad1d8d071d219d67918b2262a5658c703a7b6