Last active
July 22, 2024 01:23
-
-
Save sarmadgulzar/f9792b2c82780f9a43af23dea34ebc56 to your computer and use it in GitHub Desktop.
Increment GitHub release with ease
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Function to increment version | |
| increment_version() { | |
| local version=$1 | |
| local increment_type=${2:-patch} | |
| IFS='.' read -ra version_parts <<< "$version" | |
| case $increment_type in | |
| major) | |
| ((version_parts[0]++)) | |
| version_parts[1]=0 | |
| version_parts[2]=0 | |
| ;; | |
| minor) | |
| ((version_parts[1]++)) | |
| version_parts[2]=0 | |
| ;; | |
| patch|*) | |
| ((version_parts[2]++)) | |
| ;; | |
| esac | |
| echo "${version_parts[0]}.${version_parts[1]}.${version_parts[2]}" | |
| } | |
| # Get the increment type from argument or use default | |
| increment_type=${1:-patch} | |
| # Validate increment type | |
| if [[ ! "$increment_type" =~ ^(major|minor|patch)$ ]]; then | |
| echo "Invalid increment type. Please use 'major', 'minor', or 'patch'." | |
| exit 1 | |
| fi | |
| # Get the latest release version | |
| latest_version=$(gh release list -L 1 | awk -F'\t' '{print $3}') | |
| # Increment the version | |
| new_version=$(increment_version "$latest_version" "$increment_type") | |
| # Create the new release | |
| gh release create "$new_version" -t "$new_version" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version Increment and Release Script
This Bash script automates the process of incrementing version numbers and creating new releases using GitHub CLI. It supports patch, minor, and major version increments.
Prerequisites
gh) installed and authenticatedInstallation
Usage
Run the script with an optional argument to specify the increment type:
Where
[increment_type]can be:patch(default): Increments the patch version (e.g., 1.0.0 to 1.0.1)minor: Increments the minor version (e.g., 1.0.0 to 1.1.0)major: Increments the major version (e.g., 1.0.0 to 2.0.0)Examples
Create a patch release (default):
Create a minor release:
Create a major release:
How It Works
Notes