Read Anthropic’s case study about Graphite Reviewer

How to automate tagging and release workflows in GitHub

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Automating tagging and release workflows in GitHub can significantly streamline the process of deploying software, ensuring consistency and reliability while reducing the likelihood of human error. This guide explores how to set up automation for tagging and managing releases in GitHub, using built-in features like GitHub Actions.

Automating these workflows offers several advantages:

  • Consistency: Automation ensures that every release follows the same steps and standards, reducing the chances of mistakes.
  • Efficiency: Reduces the time and effort required to prepare and execute releases.
  • Traceability: Automatic tagging and releasing help in maintaining a clear record of changes, facilitating easier rollback and history tracking.

Before automating the process, clearly define the conditions under which a new tag is created and a release is made. Common triggers include:

  • Merging a pull request into the main branch.
  • Pushing a commit with a specific commit message format.
  • Manually triggering via GitHub's UI when a release candidate is ready.

GitHub Actions can automate the creation of tags based on your triggers. Here's how you can set up an action to tag commits:

  1. Create a new GitHub Actions workflow file in your repository under .github/workflows, for example, tagging.yml.

  2. Define the workflow trigger. For example, trigger on push (a merge will also trigger a push event) to the main branch:

Terminal
name: Automated Tagging
on:
push:
branches:
- main
  1. Add steps to create a tag. You can use the Git CLI or other actions available in the marketplace:
Terminal
jobs:
tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Create Tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -a "v${{ github.run_number }}" -m "Release v${{ github.run_number }}"
git push origin "v${{ github.run_number }}"

This script configures git, creates a tag based on the run number of the workflow, and pushes it back to the repository.

Once a tag is created, you can then automate the release process:

  1. Extend the GitHub Actions workflow to include release creation after tagging:
Terminal
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: 'v${{ github.run_number }}'
release_name: 'Release v${{ github.run_number }}'
body: 'Description of the changes in this release'

As an example, this GitHub Actions step creates a new release in the repository, automatically names and tags it based on the workflow's run number, and includes a description of the changes in the release body.

  1. Customize the release step by specifying the tag name, release name, and body of the release note.

By automating the tagging and release workflows in GitHub, you not only save time and effort but also improve the overall reliability of your deployment process. This setup ensures that all releases are consistent and traceable, providing a robust framework for managing software deployments efficiently and effectively.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2