This article contains a sample Github workflow for Home Assistant components that can be used to create versioned releases, generate changelogs, create Git tags and integrate with Home Assistant Community Store (HACS) via native Github Releases.
As my <a href="https://danielbkr.net/portfolio/entity-controller/">entity-controller</a>
custom component is gaining more popularity and people are beginning to contribute pull requests, I have decided to host the repository natively on Github. This required migrating the existing release automation over to a Github Actions workflow.
Preconditions
- Copy postbump.js, package.json from post linked above.
- Paste below workflow file in
.gitlab/workflows/master.yaml
in your repository - Refer to my Gitlab release automation post for clarification
Home Assistant Workflow Features
- When PRs are merged on to
master
branch, the workflow begins. - Bumb version numbers in source code file, package.json
- Use Standard Version to generate a Changelog based on commit messages
- Create tag and commit all local version bumbs and changelog.
- Create formal Github Release such that it is properly versioned in HACS (Home Assistant Community Store).
- Push to
master
and merge back intodevelop
for next iteration.
Github Actions Workflow for automatic release of custom components
name: Release HA component
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setting up Node
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Preparing release
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
npm install
npm run release
echo ::set-env name=PACKAGE_VERSION::$(node -p -e "require('./package.json').version")
env:
CI: true
- name: Push to master
uses: ad-m/github-push-action@v0.5.0
with:
github_token: $
- name: Merge back to develop
uses: ad-m/github-push-action@v0.5.0
with:
github_token: $
branch: develop
- name: Create Github Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: $ # This token is provided by Actions, you do not need to create your own token
with:
tag_name: v$
release_name: $
draft: false
prerelease: false
Challenges faced
- Gitlab would get stuck in an infinite loop when a releases
chore
commit is pushed back tomaster
anddevelop
, triggering further builds and releases. - Replacing static strings in files was difficult to make work with
standard-version
. I eventually compromised by having the aforementionedversion_bump.js
file output a commit message. - Having
standard-version
commit additional files was also difficult to figure out.
Conclusion
I hope this workflow serves as a suitable baseline for your own components. Please leave a comment below if you device to use it, I am interested in the integrations that people are working on!