This is a little Github Action’s workflow that, upon a push into your main branch, will create a new version tag, and then create a release with release notes.
It uses semantic versioning, and you can control whether it performs a patch, minor, or major release by putting a #patch, #minor, or #major note within any commit message.
A great use case for this sort of automated tagging is in Terraform modules to properly control versions like so:
module "rds-aurora" {
source = "git@github.com:maksystem-platform/terraform-aws-rds-aurora.git?ref=v0.3.0"
aws_region = var.aws_region
org_name = var.org_name
cust_name = var.cust_name
env = var.env
...
Just drop this into your repository’s .github/workflows/ folder, calling it something like tag-and-release.yaml, and then create the required secrets.
on:
workflow_dispatch:
push:
branches:
- main
name: tag-and-release
permissions:
contents: read
env:
GITHUB_USER_TOKEN: ${{ secrets.GITHUBTOKEN }}
GITHUB_USER_EMAIL: ${{ secrets.USEREMAIL }}
GITHUB_USER_NAME: ${{ secrets.GITHUBUSER }}
jobs:
tag-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Configure Git Credentials
run: |
git config --global url."https://${{ env.GITHUB_USER_TOKEN }}@github.com/".insteadOf ssh://git@github.com/
git config --global user.email ${{ env.GITHUB_USER_EMAIL }}
git config --global user.name ${{ env.GITHUB_USER_NAME }}
- name: Bump version and push tag
uses: anothrNick/github-tag-action@v1
id: tag
env:
GITHUB_TOKEN: ${{ env.GITHUB_USER_TOKEN }}
WITH_V: true
RELEASE_BRANCHES: main
- name: Tag and Create a Release
uses: softprops/action-gh-release@v2
with:
token: ${{ env.GITHUB_USER_TOKEN }}
tag_name: ${{ steps.tag.outputs.new_tag }}
generate_release_notes: true
make_latest: true
Enjoy!
Chris @ Cloudcauldron