Skip to content

Instantly share code, notes, and snippets.

@greenido
Created January 31, 2025 01:34
Show Gist options
  • Save greenido/1d6a500bfe20b81f2d6a735ba6884ad8 to your computer and use it in GitHub Desktop.
Save greenido/1d6a500bfe20b81f2d6a735ba6884ad8 to your computer and use it in GitHub Desktop.
A GitHub Action workflow that increments the version number in index.html and commits it back to the repository.
name: Increment Version Number
on:
workflow_dispatch:
inputs:
version_increment:
description: 'Increment type (major/minor/patch)'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
jobs:
increment-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Increment Version
id: version_increment
run: |
# Read current version from index.html
current_version=$(grep -oP '(?<=version: )[\d.]+' index.html)
# Split version into major.minor.patch
IFS='.' read -r major minor patch <<< "$current_version"
# Increment version based on input
case "${{ github.event.inputs.version_increment }}" in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
esac
new_version="$major.$minor.$patch"
# Update version in index.html
sed -i "s/version: $current_version/version: $new_version/" index.html
# Set output for use in commit step
echo "new_version=$new_version" >> $GITHUB_OUTPUT
- name: Commit and Push Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name github-actions
git config user.email [email protected]
git add index.html
git commit -m "Bump version to ${{ steps.version_increment.outputs.new_version }}"
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment