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 CI coincidentally started using recently.
One of the responses to the tweet actually came from Ben (aka @benmvp) and pointed to his GitHub Action workflow to do just that.
One of the benefits of GitHub Actions is that the majority of its users open-source their workflows by default.
// https://github.com/benmvp/url-lib/blob/master/.github/workflows/release.ymlname:Releaseon:push:branches:-masterjobs:main:name:NPM Releaseruns-on:ubuntu-lateststeps:-name:Checkoutuses:actions/checkout@v1-name:Use Node v12uses:actions/setup-node@v1with:node-version:12-name:Install dependenciesrun:npm ci-name:Double-check unit testsrun:npm testenv:CI:true-name:Double-check integration testsrun:npm run integrateenv:CI:true-name:Build packagerun:npm run build-name:Release new version to NPMenv: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.
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, but it is also open-sourced as well.
name: Release Drafteron:
push:
# branches to consider in the event; optional, defaults to allbranches:
- master# pull_request event is required only for autolabelerpull_request:
# Only following types are handled by the action, but one can default to all as welltypes: [opened, reopened, synchronize]# pull_request_target event is required for autolabeler to support PRs from forks# pull_request_target:# types: [opened, reopened, synchronize]permissions:
contents: readjobs:
update_release_draft:
permissions:
# write permission is required to create a github releasecontents: write# write permission is required for autolabeler# otherwise, read
If you want to learn more about GitHub Action workflows environments, check out the docs.github.com.
If you are interested in seeing this in the wild, go ahead and give my Open Sauced workflows for a peak on GitHub. All my release notes and changelog generate when a PR is merged.