Generate semantic-release notes with GitHub Actions
Tags: github, devops, githubactions
Published: 2021-02-04 15:01:06

So I saw a tweet about doing semantic-release in GitHub Actions. When I responded, I also noticed there were already answers all pointing to one library, [semantic-release](https://github.com/semantic-release/semantic-release) CI coincidentally started using recently.

{% twitter 1323458984825638912 %}

One of the responses to the tweet actually came from Ben (aka @benmvp) and pointed to his [GitHub Action workflow](https://github.com/benmvp/url-lib/blob/master/.github/workflows/release.yml) to do just that. 

_One of the benefits of GitHub Actions is that the majority of its users open-source their workflows by default._

```yml
// https://github.com/benmvp/url-lib/blob/master/.github/workflows/release.yml

name: Release

on:
  push:
    branches:
      - master

jobs:
  main:
    name: NPM Release
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Use Node v12
        uses: actions/setup-node@v1
        with:
          node-version: 12

      - name: Install dependencies
        run: npm ci

      - name: Double-check unit tests
        run: npm test
        env:
          CI: true

      - name: Double-check integration tests
        run: npm run integrate
        env:
          CI: true

      - name: Build package
        run: npm run build

      - name: Release new version to NPM
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npx semantic-release
```

If you take a look at the workflow, you can see at the bottom, and he's using the npx command to leverage Semantic release. GitHub Actions workflows allow you to run set environments and run. That solves the one problem, but I'm a big fan of actually automating my changelog as well.

_Ben has set his environment to ubuntu, which has node installed by default. This gives him access to npm and which provides access to the [npx command](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b)._

I leverage actions to generate my release in my projects, thanks to Ben for sharing his workflow. I discovered that it provides a changelog and bumps the version number in package.json file. 

I'm also doing a little extra and leveraging Release Drafter's tool to draft my release notes. I wouldn't say I like the process of trying to comb commits merged to the main branch for release notes. It is much easier to keep track of when that happens, and that is what Release Drafter does for me. You can find that action here on [GitHub Marketplace](https://github.com/marketplace/actions/release-drafter), but it is also open-sourced as well.

{% github https://github.com/release-drafter/release-drafter %}

If you want to learn more about GitHub Action workflows environments, check out the [docs.github.com](https://docs.github.com/en/actions).

If you are interested in seeing this in the wild, go ahead and give my [Open Sauced workflows](https://github.com/open-sauced/open-sauced/tree/main/.github/workflows) for a peak on GitHub. All my release notes and changelog generate when a PR is merged.

{% github https://github.com/open-sauced/open-sauced no-readme %}

_This is part of my 28 days of Actions series. To get notified of more GitHub Action tips, follow the GitHub organization right here on Dev._

{% link https://dev.to/github/running-github-actions-ci-cd-triggers-on-specific-branches-5e6m %}