Skip to content
This repository was archived by the owner on Apr 28, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/version-bump.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Version Bump

on:
push:
paths:
- '.ktchanges/*-changeset.yaml'
branches:
- main

jobs:
version-bump:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Find latest changeset file
id: changeset
run: |
LATEST_CHANGESET=$(ls -t .ktchanges/*-changeset.yaml 2>/dev/null | head -1)
if [ -z "$LATEST_CHANGESET" ]; then
echo "No changeset file found"
exit 1
fi
echo "file=$LATEST_CHANGESET" >> $GITHUB_OUTPUT
echo "Changeset file: $LATEST_CHANGESET"

- name: Parse changeset and bump versions
id: bump
run: |
CHANGESET_FILE="${{ steps.changeset.outputs.file }}"

# Create a temporary file to store the changes
> /tmp/version_changes.txt

while IFS=: read -r project bump_type; do
project=$(echo "$project" | xargs) # trim whitespace
bump_type=$(echo "$bump_type" | xargs) # trim whitespace

if [ -z "$project" ] || [ -z "$bump_type" ]; then
continue
fi

# Find gradle.properties for this project
GRADLE_PROPS=$(find . -path "*/$project/gradle.properties" -o -path "*${project}/gradle.properties" | head -1)

if [ ! -f "$GRADLE_PROPS" ]; then
echo "::warning::gradle.properties not found for $project"
continue
fi

# Read current version
CURRENT_VERSION=$(grep "^version=" "$GRADLE_PROPS" | cut -d'=' -f2)

# Parse semantic version
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
PATCH=${PATCH%%-*} # remove pre-release suffix if any

# Bump version based on type
case "$bump_type" in
major)
NEW_VERSION="$((MAJOR + 1)).0.0"
;;
minor)
NEW_VERSION="$MAJOR.$((MINOR + 1)).0"
;;
patch)
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
;;
*)
echo "::error::Unknown bump type: $bump_type"
exit 1
;;
esac

# Update gradle.properties
sed -i "s/^version=.*/version=$NEW_VERSION/" "$GRADLE_PROPS"

echo "$project: $CURRENT_VERSION -> $NEW_VERSION ($bump_type)" >> /tmp/version_changes.txt
done < "$CHANGESET_FILE"

rm -f "$CHANGESET_FILE"

cat /tmp/version_changes.txt
echo "changes<<EOF" >> $GITHUB_OUTPUT
cat /tmp/version_changes.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "Ktchanges Versioning Action"

- name: Create commit and tag
id: git
run: |
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')

git checkout -b "$BRANCH"
git add .
git commit -m "chore: bump versions" || true
git push

echo "branch=$BRANCH" >> $GITHUB_OUTPUT
3 changes: 2 additions & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .ktchanges/1776257122-changeset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test-project/src/project-b: patch
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ class KtChangesFacade {
fileSystemService.writeChangesetFile(rootDir.absolutePath, bumpMap)
section { textLine("Changeset created!") }.run()

exitProcess(0)
return@session
}

section { textLine("Aborted.") }.run()
exitProcess(1)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class FileSystemService {
val name = "${Instant.now().epochSecond}-changeset.yaml"
val file = File(directory, "$DIRECTORY/$name")

val contents = bumps.map { (path, type) -> "$path: $type" }.joinToString("\n")
var contents = bumps.map { (path, type) -> "$path: $type" }.joinToString("\n")
contents += "\n"

file.writeText(contents)
}
}
115 changes: 115 additions & 0 deletions scripts/test-changeset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash

set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR="$SCRIPT_DIR/.."

echo "KtChanges Version Bump Test Script"
echo "==================================="
echo ""

# Find latest changeset file
CHANGESET_FILE=$(ls -t "$ROOT_DIR/.ktchanges"/*-changeset.yaml 2>/dev/null | head -1)

if [ -z "$CHANGESET_FILE" ]; then
echo "❌ No changeset file found in .ktchanges directory"
echo ""
echo "First, run: ./gradlew ktchanges"
exit 1
fi

echo "✅ Found changeset file: $CHANGESET_FILE"
echo ""
echo "📋 Changeset contents:"
cat "$CHANGESET_FILE"
echo ""

# Parse and apply version bumps
echo "🔄 Simulating version bump process..."
echo ""

TEMP_CHANGES="/tmp/version_changes.txt"
> "$TEMP_CHANGES"

while IFS=: read -r project bump_type; do
project=$(echo "$project" | xargs) # trim whitespace
bump_type=$(echo "$bump_type" | xargs) # trim whitespace

# Skip empty lines or lines that don't have both project and bump_type
if [ -z "$project" ] || [ -z "$bump_type" ]; then
continue
fi

# Validate bump_type
if [[ ! "$bump_type" =~ ^(major|minor|patch)$ ]]; then
echo "⚠️ Invalid bump type '$bump_type' for project '$project'. Skipping."
continue
fi

# Find gradle.properties for this project
# Try multiple search strategies
GRADLE_PROPS=""

# Strategy 1: Direct path match
if [ -f "$ROOT_DIR/$project/gradle.properties" ]; then
GRADLE_PROPS="$ROOT_DIR/$project/gradle.properties"
fi

# Strategy 2: Find in subdirectories
if [ -z "$GRADLE_PROPS" ]; then
GRADLE_PROPS=$(find "$ROOT_DIR" -type f -name "gradle.properties" | grep "$project" | head -1)
fi

# Strategy 3: Find all gradle.properties and match project name
if [ -z "$GRADLE_PROPS" ]; then
# Extract project name from path (last component)
PROJECT_NAME=$(basename "$project")
GRADLE_PROPS=$(find "$ROOT_DIR" -type f -name "gradle.properties" | xargs grep -l "version=" | grep "$PROJECT_NAME" | head -1)
fi

if [ ! -f "$GRADLE_PROPS" ]; then
echo "⚠️ gradle.properties not found for: $project"
continue
fi

# Read current version
CURRENT_VERSION=$(grep "^version=" "$GRADLE_PROPS" | cut -d'=' -f2)

# Parse semantic version
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
PATCH=${PATCH%%-*} # remove pre-release suffix if any

# Bump version based on type
case "$bump_type" in
major)
NEW_VERSION="$((MAJOR + 1)).0.0"
;;
minor)
NEW_VERSION="$MAJOR.$((MINOR + 1)).0"
;;
patch)
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
;;
*)
echo "❌ Unknown bump type: $bump_type"
exit 1
;;
esac

echo "📝 $project"
echo " Current version: $CURRENT_VERSION"
echo " Bump type: $bump_type"
echo " New version: $NEW_VERSION"
echo ""

echo "$project: $CURRENT_VERSION -> $NEW_VERSION ($bump_type)" >> "$TEMP_CHANGES"
done < "$CHANGESET_FILE"

echo "==================================="
echo "✅ Version bump simulation complete!"
echo ""
echo "Changes that would be applied:"
echo "---"
cat "$TEMP_CHANGES" || echo "No changes to apply"
echo "---"
6 changes: 5 additions & 1 deletion scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ echo "Navigating to project directory..."
cd ./plugin || exit 1

echo "Running tests..."
./gradlew test
./gradlew test

cd .. || exit 1

bash scripts/test-changeset.sh
Loading