Automatic releases using GitHub Actions

Create a release when merging a pull request using a simple naming convention

Posted by Eirik Tenold on Sunday, March 29, 2020

GitHub Actions is an awesome new feature for GitHub users who want to automate some parts of their workflow. As proof of concept, I created a workflow that will do the following:

  • When a Pull Request is closed create a new release if certain conditions are met:
    1. The pull request must have been merged (i.e. not just closed without merge)
    2. The pull request is from a branch with a name release/-prefix
  • Create a new tag using the name from the pull request’s title
  • Create a new release associated with the newly created tag
    • The release’s name is the same as the tag and is from the pull request’s title
    • The release’s body if the body from the pull request

Example workflow: .github/workflows/main.yml:

name: Create release
on:
  pull_request:
    types: [closed]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Create Release
      if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/')
      uses: actions/create-release@latest
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.event.pull_request.title }}
        release_name: ${{ github.event.pull_request.title }}
        body: ${{ github.event.pull_request.body }}

Ideas for future changes:

  • Instead a using a branch name prefix, check for the existance of a label
  • Auto create tag name (semantic versioning, increase by one, etc)

References: