Skip to content

Commit e21d6d8

Browse files
committed
feat: add version bump script, GitHub release workflow, and Makefile targets
1 parent 7c3cfe7 commit e21d6d8

6 files changed

Lines changed: 145 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write # needed to create a GitHub Release
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Set up JDK 21
19+
uses: actions/setup-java@v4
20+
with:
21+
java-version: "21"
22+
distribution: "temurin"
23+
24+
- name: Setup Gradle
25+
uses: gradle/actions/setup-gradle@v4
26+
27+
- name: Run tests
28+
run: ./gradlew test
29+
30+
- name: Upload test results
31+
if: always()
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: test-results-release
35+
path: build/reports/tests/test/
36+
37+
- name: Build plugin ZIP
38+
run: ./gradlew buildPlugin
39+
40+
- name: Create GitHub Release
41+
uses: softprops/action-gh-release@v2
42+
with:
43+
tag_name: ${{ github.ref_name }}
44+
name: ${{ github.ref_name }}
45+
generate_release_notes: true
46+
files: build/distributions/*.zip

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
push:
66
branches:
77
- main
8+
tags-ignore:
9+
- "**"
810

911
jobs:
1012
test:

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.PHONY: test build release release/patch release/minor release/major
2+
3+
test:
4+
./gradlew test
5+
6+
build:
7+
./gradlew buildPlugin
8+
9+
release/patch:
10+
./scripts/bump-version.sh --next-patch
11+
git push && git push --tags
12+
13+
release/minor:
14+
./scripts/bump-version.sh --next-minor
15+
git push && git push --tags
16+
17+
release/major:
18+
./scripts/bump-version.sh --next-major
19+
git push && git push --tags
20+
21+
release:
22+
@if [ -z "$(VERSION)" ]; then echo "Usage: make release VERSION=0.1.0"; exit 1; fi
23+
./scripts/bump-version.sh $(VERSION)
24+
git push && git push --tags

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = "com.ashotn"
8-
version = "1.0-SNAPSHOT"
8+
version = providers.gradleProperty("pluginVersion").get()
99

1010
repositories {
1111
mavenCentral()

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pluginVersion=0.0.0
12
org.gradle.java.home=/usr/lib/jvm/java-21-openjdk
23
org.jetbrains.intellij.platform.buildFeature.useClosestVersionResolving=true
34
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError

scripts/bump-version.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
# Usage: ./scripts/bump-version.sh <new-version>
3+
# ./scripts/bump-version.sh --next-patch
4+
# ./scripts/bump-version.sh --next-minor
5+
# ./scripts/bump-version.sh --next-major
6+
#
7+
# This script:
8+
# 1. Updates pluginVersion in gradle.properties
9+
# 2. Commits the change
10+
# 3. Creates a git tag vX.Y.Z
11+
#
12+
# When called via `make release/patch|minor|major`, the push happens automatically.
13+
# The tag push triggers the GitHub release workflow.
14+
15+
set -euo pipefail
16+
17+
PROPS_FILE="gradle.properties"
18+
CURRENT_VERSION=$(grep '^pluginVersion=' "$PROPS_FILE" | cut -d= -f2)
19+
20+
# Parse current version parts
21+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
22+
23+
if [ $# -ne 1 ]; then
24+
echo "Usage: $0 <new-version> | --next-patch | --next-minor | --next-major"
25+
exit 1
26+
fi
27+
28+
case "$1" in
29+
--next-patch)
30+
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
31+
;;
32+
--next-minor)
33+
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
34+
;;
35+
--next-major)
36+
NEW_VERSION="$((MAJOR + 1)).0.0"
37+
;;
38+
*)
39+
NEW_VERSION="$1"
40+
;;
41+
esac
42+
TAG="v${NEW_VERSION}"
43+
44+
# Validate version format (semver: X.Y.Z)
45+
if ! echo "$NEW_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
46+
echo "Error: version must be in X.Y.Z format (e.g. 0.2.0)"
47+
exit 1
48+
fi
49+
50+
# Check for uncommitted changes
51+
if ! git diff --quiet || ! git diff --cached --quiet; then
52+
echo "Error: you have uncommitted changes. Commit or stash them first."
53+
exit 1
54+
fi
55+
56+
# Check the tag doesn't already exist
57+
if git rev-parse "$TAG" >/dev/null 2>&1; then
58+
echo "Error: tag $TAG already exists."
59+
exit 1
60+
fi
61+
62+
echo "Bumping $CURRENT_VERSION$NEW_VERSION"
63+
64+
# Update gradle.properties
65+
sed -i "s/^pluginVersion=.*/pluginVersion=${NEW_VERSION}/" "$PROPS_FILE"
66+
67+
git add "$PROPS_FILE"
68+
git commit -m "chore: bump version to ${NEW_VERSION}"
69+
git tag "$TAG"
70+
71+
echo "Done. Tag $TAG created."

0 commit comments

Comments
 (0)