Skip to content
tag

GitHub Action

Compute Tag

v18 Latest version

Compute Tag

tag

Compute Tag

Compute the next tag based on the previous tag and the version scheme

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Compute Tag

uses: craig-day/compute-tag@v18

Learn more about this action in craig-day/compute-tag

Choose a version

compute-tag

Latest Release Example Runs

A Github action to compute the next version tag.

This can be helpful to automatically compute tags and pipe them to the create-release action.

Inputs

Parameter Description Required Default
github_token A Github token, usually ${{ github.token }}. Y N/A
tag The tag to compute the next version of. If not specified, the most recent tag in the repo. N Latest
branch The branch to find compute the tag for. This requires iteration of all tags for the repo and the commits for the branch to find a tag for a commit on the branch. For large repositories this can be very slow. It is highly recommended that github_token be supplied to prevent rate limit errors when searching. N N/A
version_scheme One of (continuous, semantic). N semantic
version_type One of (major, minor, patch, premajor, preminor, prepatch, prerelease). N prerelease
prerelease_suffix The suffix added to a prerelease tag, if none already exists. N beta
tag_fetch_depth The number of tags to fetch when searching for the previous tag. N 10

Output

  • next_tag The computed next tag.
  • previous_tag The tag used to compute next_tag.

Usage

steps:
  - id: compute_tag
    uses: craig-day/compute-tag@v15
    with:
      github_token: ${{ github.token }}

Examples

For an exhuastive list of every version_scheme+version_type combination, see the results from the Example Runs workflow

Tag each push to master as a semantic prerelease

name: Release

on:
  push:
    branches:
      - master

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - id: compute_tag
        uses: craig-day/compute-tag@v15
        with:
          github_token: ${{ github.token }}

Sample Logs:

Computing the next tag based on: v5.0.0-pre.4
Computed the next tag as: v5.0.0-pre.5

Tag each push to master as a semantic patch

name: Release

on:
  push:
    branches:
      - master

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - id: compute_tag
        uses: craig-day/compute-tag@v15
        with:
          github_token: ${{ github.token }}
          version_type: patch

Sample Logs:

Computing the next tag based on: v5.0.3
Computed the next tag as: v5.0.4

Tag each push to master as a continuous prerelease

name: Release

on:
  push:
    branches:
      - master

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - id: compute_tag
        uses: craig-day/compute-tag@v15
        with:
          github_token: ${{ github.token }}
          version_scheme: continuous
          version_type: prerelease

Sample Logs:

Computing the next tag based on: v5-pre.4
Computed the next tag as: v5-pre.5

Switching from continuous to semantic

name: Release

on:
  push:
    branches:
      - master

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - id: compute_tag
        uses: craig-day/compute-tag@v15
        with:
          github_token: ${{ github.token }}
          version_scheme: semantic

Sample Logs:

Computing the next tag based on: v5-pre.4
Computed the next tag as: v5.0.0-pre.5

Create a GitHub Release for each push to master

NOTE: Since actions/create-release is deprecated, this example uses softprops/action-gh-release which maintains a similar API and feature set.

name: Release

on:
  push:
    branches:
      - master

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - id: compute_tag
        uses: craig-day/compute-tag@v15
        with:
          github_token: ${{ github.token }}
          version_scheme: semantic

      - name: create release
        uses: softprops/action-gh-release@v1
        with:
          name: ${{ steps.compute_tag.outputs.next_tag }}
          tag_name: ${{ steps.compute_tag.outputs.next_tag }}
          generate_release_notes: true
          prerelease: true
        env:
          GITHUB_TOKEN: ${{ github.token }}