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.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.
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.
release-drafter / release-drafter
Drafts your next release notes as pull requests are merged into master.
Drafts your next release notes as pull requests are merged into master. Built with Probot.
Usage
You can use the Release Drafter GitHub Action in a GitHub Actions Workflow by configuring a YAML-based workflow file, e.g. .github/workflows/release-drafter.yml
, with the following:
name: Release Drafter
on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
# pull_request event is required only for autolabeler
pull_request:
# Only following types are handled by the action, but one can default to all as well
types: [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: read
jobs:
update_release_draft:
permissions:
# write permission is required to create a github release
contents: 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.
open-sauced / open-sauced
🍕 This is a project to identify your next open source contribution.
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.
Top comments (0)