Skip to content

mogenius/gha-semver-bump

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Semantic Version Bump Action

A GitHub Composite Action that automatically determines version bump types from Conventional Commits and calculates the new semantic version for Helm charts.

Features

  • πŸ” Automatic Detection: Analyzes commit messages to determine the appropriate version bump
  • πŸ“ Conventional Commits Support: Recognizes feat, fix, and breaking change patterns
  • πŸŽ›οΈ Manual Override: Allows explicit version bump type via input
  • πŸ“Š Helm Chart Integration: Reads current version directly from Chart.yaml
  • πŸ”„ Semantic Versioning: Follows SemVer 2.0.0 specification

Version Bump Rules

Commit Pattern Bump Type Example
feat!: or BREAKING CHANGE major 1.2.3 β†’ 2.0.0
feat: or feature: minor 1.2.3 β†’ 1.3.0
All other commits patch 1.2.3 β†’ 1.2.4

Usage

Basic Usage

steps:
  - name: Checkout
    uses: actions/checkout@v4
    with:
      fetch-depth: 0  # Required for commit history analysis

  - name: Bump Version
    id: version
    uses: your-org/semver-bump-action@v1
    with:
      chart-path: charts/my-chart

  - name: Print Versions
    run: |
      echo "Current: ${{ steps.version.outputs.current-version }}"
      echo "Bump type: ${{ steps.version.outputs.bump-type }}"
      echo "New: ${{ steps.version.outputs.new-version }}"

With Manual Version Bump

on:
  workflow_dispatch:
    inputs:
      version_bump:
        description: 'Version bump type'
        required: true
        type: choice
        options:
          - patch
          - minor
          - major

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Bump Version
        id: version
        uses: your-org/semver-bump-action@v1
        with:
          chart-path: charts/my-chart
          version-bump: ${{ inputs.version_bump }}

Local Action (Same Repository)

If the action is stored in your repository under .github/actions/semver-bump/:

- name: Bump Version
  id: version
  uses: ./.github/actions/semver-bump
  with:
    chart-path: charts/my-chart

Complete Helm Chart Release Workflow

name: Release Helm Chart

on:
  push:
    branches: [main]
    paths:
      - 'charts/**'
  workflow_dispatch:
    inputs:
      version_bump:
        description: 'Version bump type'
        required: false
        type: choice
        options:
          - ''
          - patch
          - minor
          - major

env:
  CHART_PATH: charts/my-chart

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      packages: write

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Bump Version
        id: version
        uses: your-org/semver-bump-action@v1
        with:
          chart-path: ${{ env.CHART_PATH }}
          version-bump: ${{ inputs.version_bump }}

      - name: Update Chart.yaml
        run: |
          sed -i "s/^version:.*/version: ${{ steps.version.outputs.new-version }}/" \
            ${{ env.CHART_PATH }}/Chart.yaml

      - name: Commit and Tag
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add ${{ env.CHART_PATH }}/Chart.yaml
          git commit -m "chore: bump chart version to ${{ steps.version.outputs.new-version }}"
          git tag "v${{ steps.version.outputs.new-version }}"
          git push origin main --tags

      - name: Package and Push Chart
        run: |
          helm package ${{ env.CHART_PATH }}
          helm push *.tgz oci://ghcr.io/${{ github.repository_owner }}/charts

Inputs

Input Description Required Default
chart-path Path to the Helm chart directory containing Chart.yaml βœ… -
version-bump Manual version bump type (major, minor, patch). If empty, auto-detection is used. ❌ ''
commit-count Number of recent commits to analyze for auto-detection ❌ 10

Outputs

Output Description Example
current-version The current version extracted from Chart.yaml 1.2.3
bump-type The determined or specified bump type minor
new-version The calculated new semantic version 1.3.0

Requirements

  • The target Chart.yaml must contain a version: field in standard format
  • For auto-detection: repository must be checked out with fetch-depth: 0 or sufficient depth
  • Git must be available in the runner environment

Conventional Commits Reference

This action recognizes the following commit message patterns:

# Major version bump (breaking changes)
feat!: remove deprecated API endpoints
feat(api)!: change authentication flow
chore: update dependencies

BREAKING CHANGE: API v1 is no longer supported

# Minor version bump (new features)
feat: add user profile endpoint
feature: implement dark mode
feat(auth): add OAuth2 support

# Patch version bump (fixes, chores, etc.)
fix: resolve memory leak in worker
docs: update installation guide
chore: upgrade dependencies
refactor: simplify error handling
style: format code with prettier
test: add unit tests for auth module

Installation

Option 1: Use from GitHub Marketplace

uses: your-org/semver-bump-action@v1

Option 2: Copy to Your Repository

  1. Create the directory structure:

    mkdir -p .github/actions/semver-bump
  2. Create .github/actions/semver-bump/action.yml:

    name: 'Semantic Version Bump'
    description: 'Determines version bump type from conventional commits and calculates new version'
    inputs:
      chart-path:
        description: 'Path to the Helm chart directory'
        required: true
      version-bump:
        description: 'Manual version bump type (major, minor, patch)'
        required: false
        default: ''
      commit-count:
        description: 'Number of commits to analyze'
        required: false
        default: '10'
    
    outputs:
      current-version:
        description: 'The current version from Chart.yaml'
        value: ${{ steps.current_version.outputs.version }}
      bump-type:
        description: 'The determined bump type'
        value: ${{ steps.bump_type.outputs.type }}
      new-version:
        description: 'The calculated new version'
        value: ${{ steps.new_version.outputs.version }}
    
    runs:
      using: 'composite'
      steps:
        - name: Get current version
          id: current_version
          shell: bash
          run: |
            CURRENT_VERSION=$(grep '^version:' ${{ inputs.chart-path }}/Chart.yaml | awk '{print $2}')
            echo "version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
    
        - name: Determine version bump type
          id: bump_type
          shell: bash
          run: |
            if [ -n "${{ inputs.version-bump }}" ]; then
              echo "type=${{ inputs.version-bump }}" >> $GITHUB_OUTPUT
            else
              COMMITS=$(git log --format=%s -n ${{ inputs.commit-count }})
              if echo "$COMMITS" | grep -qE "^(feat|feature)!:|BREAKING CHANGE"; then
                echo "type=major" >> $GITHUB_OUTPUT
              elif echo "$COMMITS" | grep -qE "^(feat|feature):"; then
                echo "type=minor" >> $GITHUB_OUTPUT
              else
                echo "type=patch" >> $GITHUB_OUTPUT
              fi
            fi
    
        - name: Bump version
          id: new_version
          shell: bash
          run: |
            CURRENT="${{ steps.current_version.outputs.version }}"
            BUMP_TYPE="${{ steps.bump_type.outputs.type }}"
            
            IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
            
            case $BUMP_TYPE in
              major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
              minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
              patch) PATCH=$((PATCH + 1)) ;;
            esac
            
            echo "version=${MAJOR}.${MINOR}.${PATCH}" >> $GITHUB_OUTPUT
  3. Reference it in your workflows:

    uses: ./.github/actions/semver-bump

Troubleshooting

"Version is empty"

Ensure your Chart.yaml has the version field at the start of a line:

version: 1.2.3  # βœ… Correct
  version: 1.2.3  # ❌ Indented - won't be detected

"Always getting patch bump"

  • Check that commits follow Conventional Commits format
  • Ensure repository is checked out with sufficient history:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0  # Full history

"Git command not found"

This action requires Git to be available. All GitHub-hosted runners include Git by default.

License

MIT License - see LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published