Skip to content

kiyoon/changelog-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace
 
 

Repository files navigation

Changelog from Conventional Commits - Github Action

This GitHub Action automatically generates a changelog based on all the Conventional Commits between the latest tag and the previous tag, or beween 2 specific tags.

Fork Notice

This is a fork of https://github.com/requarks/changelog-action

The main difference:

  • The original action required the tag to exist first, and it was designed to run whenever a version tag was pushed.
  • It doesn’t make sense that the tag already exists when the CHANGELOG.md file is not yet written, making the workflow extremely hard to fit in various pipelines.
  • This fork allows you to "mock" a tag, e.g. v0.2.0...v0.2.1 but the tag v0.2.1 doesn't exist yet (use a commit hash instead).

Along with a number of improvements:

  • Original action required two tags to be present, but this fork can generate from the initial commit, instead of failing when you deploy the first version.
  • Original action fetched two recent versions and compared them, prohibiting to create any other tag than a version tag, or deploying an older version (e.g. patch release). This fork correctly finds the correct previous tag.
  • Refactor with TypeScript, biome, bun.

Features

  • Generates the CHANGELOG changes in Markdown format
  • Turns PR ids into links and add the PR author.
  • Prepends a shortened commit SHA ID to the commit for quick access.
  • BREAKING CHANGE notes are added to the top of the changelog version along with the related commit.
  • Exports changelog to a variable that can used in a subsequent step to create a release changelog.
  • Automatically injects the changes into the CHANGELOG.md file or creates it if it doesn't exist yet. (optional)
  • Will not mess up with any header or instructions you already have at the top of your CHANGELOG.md.
  • Will not add duplicate version changes if it already exists in the CHANGELOG.md file.
  • Optionally exclude types from the CHANGELOG. (default: build,docs,other,style)

Example Workflows

1. Manually trigger to create a release PR

name: Deploy

on:
  workflow_dispatch:
    inputs:
      version-tag:
        description: Version tag
        required: true
        default: 'v0.1.0'
      dry-run:  # print the changelog without creating a PR.
        description: Dry run
        type: boolean
        default: false
      exclude-types:
        description: Commit types to exclude from the changelog
        required: false
        default: build,docs,style,other

jobs:
  changelog:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Get CHANGELOG
        id: changelog
        uses: kiyoon/changelog-action@v2
        with:
          new-version-tag-for-future: ${{ github.event.inputs.version-tag }}
          tag-prefix: v
          exclude-types: ${{ github.event.inputs.exclude-types }}
          write-to-file: true
          changelog-file-path: CHANGELOG.md

      - name: Display CHANGELOG
        env:
          CHANGES_BODY: ${{ steps.changelog.outputs.changes }}
        run: |
          echo "${CHANGES_BODY}"
          echo "${CHANGES_BODY}" > "$GITHUB_STEP_SUMMARY"

      - name: Create PR
        if: ${{ github.event.inputs.dry-run == 'false' }}
        uses: peter-evans/create-pull-request@v7
        with:
          commit-message: 'chore: release ${{ github.event.inputs.version-tag }}'
          title: 'chore: release ${{ github.event.inputs.version-tag }}'
          body: |
            :robot: The changelog was automatically generated by [kiyoon/changelog-action](https://github.com/kiyoon/changelog-action). :robot:
          branch: chore/release-${{ github.event.inputs.version-tag }}
          labels: |
            release

2. When the release PR is merged, create a Release

Follow the example in kiyoon/parse-changelog-action. It runs when CHANGELOG.md file is changed and with a commit message following chore: release vX.X.X format.

Inputs

Field Description Required Default
token Your GitHub token ${{ github.token }}
new-version-tag-for-future The version tag name but the tag doesn't have to exist already (e.g. v0.1.0)
new-version-ref Git ref (e.g. commit hash) up to which the changelog is to be determined (latest). Default is the commit sha of the action run, usually HEAD of a branch ${{ github.sha }}
previous-version-tag The tag up to which the changelog is to be determined (oldest). The tag must exist. If not set, automatically determined.
tag-prefix The prefix of tags to look up if previous-version-tag is not set (e.g. v for v0.1.0) ``
exclude-types A comma-separated list of commit types you want to exclude from the changelog (e.g. doc,chore,perf) build,docs,other,style
exclude-scopes A comma-separated list of commit scopes you want to include in the changelog (e.g. dev,release)
restrict-to-types A comma-separated list of commit types you want to restrict to for the changelog (e.g. feat,fix,refactor). Overrides excludeTypes if defined.
write-to-file Should CHANGELOG.md be updated with latest changelog false
changelog-file-path The CHANGELOG.md file path when write-to-file is true CHANGELOG.md
include-ref-issues Should the changelog include the issues referenced for each PR. true
use-gitmojis Should type headers be prepended with their related gitmoji true
include-invalid-commits Whether to include commits that don't respect the Conventional Commits format false
reverse-order List commits in reverse order (from newer to older) instead of the default (older to newer). false

Outputs

Field Description
changes Generated CHANGELOG changes for the latest tag, without the version / date header (for use in GitHub Releases).

About

GitHub Action to generate changelog from conventional commits

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%