(Part 2) Full automation of release with GitHub Actions and Conventional Commits for non-JS projects

Lukasz Gornicki

·6 min read

tl;dr Here you can find the first blog post about automated releasing. The purpose of this blog post is to show how you can do the same automation in non-JavaScript projects. Even if JavaScript community created tooling, you can still use it in other projects and don't freak out.

This post and the previous one come from our experience we gained when working on full automation for all tools maintained by AsyncaPI Initiative.

AsyncAPI is a specification that you use to create machine-readable definitions of your event-driven APIs.

The previous post focused on JavaScript as the first library that we automated was our generator. It covered publishing to NPM and usage of the JavaScript community ecosystem. Now we have automation rolled out to all our libraries, Go-written too.

What I need to automate release?

To automate a release efficiently, you need two things:

  • Machine-readable information that allows you to identify if a given commit should trigger a release or not.
  • Tooling that you can easily plug in and configure without the need to write everything from scratch.

This automation is possible thanks to the following:

  • The Conventional Commits specification. The purpose of Conventional Commits is to make commits machine-readable but also human-readable. It defines a set of commit prefixes that can be easily parsed and analyzed by tooling and looks good to the human eye too.
  • The Semantic Release package and related plugins that support Conventional Commits and publishing to different channels like GitHub, NPM, Slack, and others.

Where's the catch?

This blog post is about the automation of releases for non-JavaScript projects. Let me be honest though, solutions I mentioned in the previous chapter come from the JavaScript community.

The problem is, there are people who Hate JavaScript, they truly hate it like it is a living thing. Although, I'm personally proud to be an idiot that has a programming language that I can use.

Conventional Commits specification is heavily inspired by Angular Commit Guidelines. The Semantic Release package and its plugins ecosystem are all Node.js packages.

If you have Java or Go project, you can still use these tools. You do not have to keep package.json in your repository, so don't worry, you can keep your repository clean. The great folks from Semantic Release thought about you too.

Using Semantic Release with GitHub Action in Go project

One of the projects where we use this JavaScript tools is our parser for AsyncAPI documents. It is a Go parser.

Semantic Release configuration

The Semantic Release package supports configuration files in different formats and file types. You are not bound to package.json. We chose to use .releaserc file in YAML format but there are other options too.

3- master
5- - "@semantic-release/commit-analyzer"
6  - preset: conventionalcommits
7- - "@semantic-release/release-notes-generator"
8  - preset: conventionalcommits
9- - "@semantic-release/github"
10  - assets:
11    - path: asyncapi-parser.darwin.amd64
12      label: Binary - Darwin AMD64
13    - path: asyncapi-parser.linux.amd64
14      label: Binary - Linux AMD64
15    - path: asyncapi-parser.windows.amd64.exe
16      label: Binary - Windows AMD64

Our configuration uses plugins to:

  • Analyze Git commits with Conventional Commits specification.
  • Create a Git tag and generate changelog for release notes.
  • Publish a release with additional assets. We compile our parser as binaries that are compatible with many platforms and we want to have them easily accessible with each release.

We place the configuration under .github/workflows/, next to our GitHub Action release workflow file: release.yml. It indicates that it is for release only, nothing else.

Release workflow

Let us have a look at the differences between this workflow and the workflow I described for a typical JavaScript project here.

First, you define a test job with the Go environment to trigger tests with different versions of Go.

2  name: 'Testing'
3  runs-on: ubuntu-latest
4  strategy:
5    matrix:
6      go: 
7        - '1.14'
8        - '1.13'
9        - '1.12' 
10  steps:
11    - name: Checkout repo
12      uses: actions/checkout@v2
13    - name: Setup Go
14      uses: actions/setup-go@v1.1.2
15      with:
16        go-version: '${{ matrix.go }}'
17    - name: Invoking go test
18      run: go test ./...

The next step is the release job, where you can differentiate two core steps. The first part is the generation of the binaries that you want to expose in the GitHub release.

1- name: Setup Go
2  uses: actions/setup-go@v1.1.2
3  with:
4    go-version: '1.14'
5- name: Invoking go vet and binaries generation
6  run: |
7    go vet ./...
8    GOOS=darwin GOARCH=amd64 go build -o=.github/workflows/asyncapi-parser.darwin.amd64 ./cmd/api-parser/main.go
9    GOOS=linux GOARCH=amd64 go build -o=.github/workflows/asyncapi-parser.linux.amd64 ./cmd/api-parser/main.go
10    GOOS=windows GOARCH=amd64 go build -o=.github/workflows/asyncapi-parser.windows.amd64.exe ./cmd/api-parser/main.go

So far, it is all Go-related operations. How about the release? For the release, you need to set up a Node.js environment to run Semantic Release. Node.js community has this excellent package, npx, that allows you to run a package without installing it, and this is what you can do here in the workflow.

1- name: Setup Node.js
2  uses: actions/setup-node@v1
3  with:
4    node-version: 13
5- name: Add plugin for conventional commits
6  run: npm install conventional-changelog-conventionalcommits
7  working-directory: ./.github/workflows
8- name: Release to GitHub
9  working-directory: ./.github/workflows
10  env:
11    GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
12    GIT_AUTHOR_NAME: asyncapi-bot
13    GIT_AUTHOR_EMAIL: info@asyncapi.io
14    GIT_COMMITTER_NAME: asyncapi-bot
15    GIT_COMMITTER_EMAIL: info@asyncapi.io
16  run: npx semantic-release

You only have to install conventional-changelog-conventionalcommits explicitly if you want to use conventionalcommits preset when analyzing Git commits and generating the changelog:

2- - "@semantic-release/commit-analyzer"
3  - preset: conventionalcommits
4- - "@semantic-release/release-notes-generator"
5  - preset: conventionalcommits

Take a look at full release workflow for reference:

1name: Release
4  push:
5    branches:
6      - master
9  test:
10    name: 'Testing'
11    runs-on: ubuntu-latest
12    strategy:
13      matrix:
14        go: 
15          - '1.14'
16          - '1.13'
17          - '1.12' 
18    steps:
19      - name: Checkout repo
20        uses: actions/checkout@v2
21      - name: Setup Go
22        uses: actions/setup-go@v1.1.2
23        with:
24          go-version: '${{ matrix.go }}'
25      - name: Invoking go test
26        run: go test ./...
28  release:
29    name: 'Release to GitHub'
30    runs-on: ubuntu-latest
31    needs: 
32      - test
33    steps:
34      - name: Checkout repo
35        uses: actions/checkout@v2
36      - name: Setup Go
37        uses: actions/setup-go@v1.1.2
38        with:
39          go-version: '1.14'
40      - name: Invoking go vet and binaries generation
41        run: |
42          go vet ./...
43          GOOS=darwin GOARCH=amd64 go build -o=.github/workflows/asyncapi-parser.darwin.amd64 ./cmd/api-parser/main.go
44          GOOS=linux GOARCH=amd64 go build -o=.github/workflows/asyncapi-parser.linux.amd64 ./cmd/api-parser/main.go
45          GOOS=windows GOARCH=amd64 go build -o=.github/workflows/asyncapi-parser.windows.amd64.exe ./cmd/api-parser/main.go
46      - name: Setup Node.js
47        uses: actions/setup-node@v1
48        with:
49          node-version: 13
50      - name: Add plugin for conventional commits
51        run: npm install conventional-changelog-conventionalcommits
52        working-directory: ./.github/workflows
53      - name: Release to GitHub
54        working-directory: ./.github/workflows
55        env:
56          GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
57          GIT_AUTHOR_NAME: asyncapi-bot
58          GIT_AUTHOR_EMAIL: info@asyncapi.io
59          GIT_COMMITTER_NAME: asyncapi-bot
60          GIT_COMMITTER_EMAIL: info@asyncapi.io
61        run: npx semantic-release

You see, you can still have your project "clean" from any JavaScript-specific files and references. Everything you need for running your release with the JavaScript community tooling is only in the release-related configuration.


I don't think I can ever understand this "hate" towards JavaScript. I think, though, that you can "hate" the language, but if you see some amazing tooling built with it, that can increase your productivity, grit your teeth, put bias aside, and enjoy life. Especially, if in exchange you get this excellent feature, notification about release under the Issue and Pull Request:

pr info about release

In case you want to have more explanation on the release automation subject, I recommend reading the first part of the automation story. You can also join our Slack for further discussion.

* Cover photo by Rock'n Roll Monkey on Unsplash