Individually release different artifacts from monorepo with GitHub Actions using tags
For the Projektor open-source test reporting project I wanted to keep all the code in a single mono repo to make it easy to work on and manage. But over time as the project evolved it grew into multiple deployable artifacts, and I wanted to be able to release each of those components independently as needed:
- Server .jar deployed to GitHub releases
- Gradle plugin deployed to the Gradle plugin portal
- Node package deployed to the NPM registry
The project is built with GitHub Actions, and after some digging I found that GitHub Actions supports executing different actions based on the format of a tag.
Using that capability, I've set up three different actions in the code mono repo that each release on a different tag format:
For example, this Gradle plugin release action trigger allows me to release the plugin any time I create a tag that starts with
gradle_, such as
1on: 2 push: 3 # Sequence of patterns matched against refs/tags 4 tags: 5 - 'gradle_*' # Push events to matching gradle_*, i.e. gradle_1.0.0 6 7jobs: 8 # Build and release steps
Or the server release action that triggers on a tag starting with
v, such as
1on: 2 push: 3 # Sequence of patterns matched against refs/tags 4 tags: 5 - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 6 7jobs: 8 # Build and release steps
Kudos to the GitHub team, this flexible capability to perform different actions based on the format of the tag makes it easy to independently release multiple artifacts from the same code repo. And this regex matching capability also works for other triggers as well, such as branch names.