Fully Automated Github Workflow for Home Assistant components

Github Actions Workflow Dashboard for automated releases created for Entity Controller

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

  1. When PRs are merged on to master branch, the workflow begins.
  2. Bumb version numbers in source code file, package.json
  3. Use Standard Version to generate a Changelog based on commit messages
  4. Create tag and commit all local version bumbs and changelog.
  5. Create formal Github Release such that it is properly versioned in HACS (Home Assistant Community Store).
  6. Push to master and merge back into develop 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 to master and develop, triggering further builds and releases.
  • Replacing static strings in files was difficult to make work with standard-version. I eventually compromised by having the aforementioned version_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!

Related posts

How to Optimize Docker Builds with Nexus OSS for Apt, Maven, Docker and NPM Dependencies

Docker could not find an available, non-overlapping IP address pool

Github Workflow for Electron React Boilerplate with Auto Updates

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More