Skip to content

Commit

Permalink
[skip ci] Add initial prepare-release GitHub action for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
burnoo committed Aug 3, 2024
1 parent 46b3921 commit bd2f654
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/prepere-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Prepare release

on:
workflow_dispatch:
inputs:
name:
type: choice
description: Version to bump
options:
- minor
- major
jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run bump version script
run: sh ./scripts/bump-version.sh ${{ github.event.inputs.name }}
- name: Echo new version
run: echo $NEW_VERSION
51 changes: 51 additions & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# Check if a parameter is provided
if [ -z "$1" ]; then
echo "Usage: $0 <major|minor|patch>"
exit 1
fi

# File path
file="compose-remember-setting/build.gradle.kts"

# Read the file and find the version line
while IFS= read -r line; do
if [[ $line =~ [0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT ]]; then
version_line=$line
break
fi
done < "$file"

# Extract the current version
current_version=$(echo "$version_line" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT')
IFS='.' read -r major minor patch <<< "$(echo "$current_version" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')"

# Determine the new version based on the input parameter
if [ "$1" == "major" ]; then
new_major=$((major + 1))
new_version="${new_major}.0.0-SNAPSHOT"
elif [ "$1" == "minor" ]; then
new_minor=$((minor + 1))
new_version="${major}.${new_minor}.0-SNAPSHOT"
elif [ "$1" == "patch" ]; then
new_patch=$((patch + 1))
new_version="${major}.${minor}.${new_patch}-SNAPSHOT"
else
echo "Invalid parameter. Use 'major', 'minor', or 'patch'."
exit 1
fi

# Replace the version in the file
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s/$current_version/$new_version/" "$file"
else
# Linux and other UNIX systems
sed -i "s/$current_version/$new_version/" "$file"
fi

# Set the new version as a GitHub Actions output
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV

echo "Version bumped from $current_version to $new_version"

0 comments on commit bd2f654

Please sign in to comment.