anothrNick / github-tag-action

A Github Action to tag a repo on merge.
MIT License
754 stars 374 forks source link
hacktoberfest

github-tag-action

A GitHub Action to automatically bump and tag master, on merge, with the latest SemVer formatted version.

Build Status Stable Version Latest Release

Medium Post: Creating A GitHub Action to Tag Commits

📣 This project is seeking maintainers! 📣

Usage

Note: We don't recommend using the @master version unless you're happy to test the latest changes.

# example 1: on push to master
name: Bump version
on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-22.04
    permissions:
      contents: write
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: '0'

    - name: Bump version and push tag
      uses: anothrNick/github-tag-action@v1 # Don't use @master or @v1 unless you're happy to test the latest version
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # if you don't want to set write permissions use a PAT token
        WITH_V: false
# example 2: on merge to master from pull request (recommended)
name: Bump version
on:
  pull_request:
    types:
      - closed
    branches:
      - master

jobs:
  build:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-22.04
    permissions:
      contents: write
    steps:
    - uses: actions/checkout@v4
      with:
        ref: ${{ github.event.pull_request.merge_commit_sha }}
        fetch-depth: '0'

    - name: Bump version and push tag
      uses: anothrNick/github-tag-action@v1 # Don't use @master or @v1 unless you're happy to test the latest version
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # if you don't want to set write permissions use a PAT token
        WITH_V: true
        PRERELEASE: true

Depending if you choose example 1 or example 2 is how crafted version bumps operate when reading the commit log.

Is recommended to use on pull_request instead of on commit to master/main.

NOTE: set the fetch-depth for actions/checkout@v2 or newer to be sure you retrieve all commits to look for the semver commit message.

Options

Environment Variables

Outputs

Note: This action creates a lightweight tag.

Bumping

Manual Bumping: Any commit message that includes #major, #minor, #patch, or #none will trigger the respective version bump. If two or more are present, the highest-ranking one will take precedence. If #none is contained in the merge commit message, it will skip bumping regardless DEFAULT_BUMP.

Automatic Bumping: If no #major, #minor or #patch tag is contained in the merge commit message, it will bump whichever DEFAULT_BUMP is set to (which is minor by default). Disable this by setting DEFAULT_BUMP to none.

Note: This action will not bump the tag if the HEAD commit has already been tagged.

Workflow

Contributing

See CONTRIBUTING.md and CODE_OF_CONDUCT.md.

Credits

Projects using github-tag-action

Examples of projects using github-tag-action for reference.