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:
- The pull request must have been merged (i.e. not just closed without merge)
- 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:
- Event Types & Payloads - developer.github.com
- GitHub Action - Releases API - github.com