Streamlining Your Project's Changelog with GitHub Actions

Streamlining Your Project's Changelog with GitHub Actions

Learn how to automate changelog generation and save time with this step-by-step guide to using GitHub Actions

Introduction

GitHub Actions now supports CI/CD, free for public repositories

As software developers, keeping track of changes made to a project is crucial for communication and collaboration with others on the team. With multiple people working on a project, manually updating a changelog can become time-consuming and error-prone. Automating changelog generation can help simplify this process and ensure consistency.

One way to automate changelog generation is through GitHub Actions. GitHub Actions is a powerful automation tool that allows developers to automate their workflow and build, test, and deploy their projects. With GitHub Actions, you can create custom workflows to automate changelog generation every time you push changes to your repository.

In this blog, we will discuss how to set up a GitHub Action workflow to automate changelog generation. We will use a popular open-source tool called conventional-changelog to generate our changelog.

Steps to follow

Step 1: Set up a GitHub Actions Workflow

The first step is to create a new GitHub Actions workflow in your repository. This can be done by creating a new YAML file in the .github/workflows directory of your repository. To automate changelog generation, we will create a new workflow that runs whenever changes are pushed to the repository.

Here is an example of a basic workflow that runs on pushes to the main branch:

name: Generate Changelog

on:
  push:
    branches:
      - main

jobs:
  generate-changelog:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

Step 2: Install Conventional Changelog

The next step is to install the conventional-changelog tool. We can do this by using the npm install command in our workflow.

  - name: Install Conventional Changelog
    run: npm install -g conventional-changelog-cli

Step 3: Generate the Changelog

Once the conventional-changelog tool is installed, we can generate our changelog using the conventional-changelog command.

  - name: Generate Changelog
    run: conventional-changelog -p angular -i CHANGELOG.md -s

The -p flag specifies the preset to use for generating the changelog. The -i flag specifies the input file for the changelog, and the -s flag generates a summary of changes.

Step 4: Commit the Changelog

Finally, we need to commit the generated changelog to our repository. We can do this by using the git command in our workflow.

  - name: Commit Changelog
    run: |
      git config --global user.email "you@example.com"
      git config --global user.name "Your Name"
      git add CHANGELOG.md
      git commit -m "chore(changelog): Update changelog"

Here, we are configuring the git user email and name, adding the changelog file to the git stage, and committing the changes with a message.

Step 5: Push the Changes

  - name: Push Changes
    uses: ad-m/github-push-action@master
    with:
      github_token: ${{ secrets.GITHUB_TOKEN }}
      branch: main

In this step, we are using the ad-m/github-push-action to push the changes back to the main branch. The secrets.GITHUB_TOKEN is a built-in GitHub Actions secret that provides secure access to the repository.

That's it! We have now set up a GitHub Actions workflow to automate changelog generation. This workflow will run every time changes are pushed to the main branch, generate the changelog, commit the changes, and push the changes back to the repository. This will help save time and ensure consistency in your changelog updates.

Conclusion

Understanding GitHub Actions - GitHub Docs

In conclusion, automating changelog generation using GitHub Actions is a straightforward process that can greatly improve the efficiency and accuracy of your project's changelog updates. With the power of GitHub Actions, you can automate this process and ensure that your changelog is always up-to-date.

Did you find this article valuable?

Support Khushiyant Chauhan by becoming a sponsor. Any amount is appreciated!