From a660c7e68ff0ad26b15ed6fd649e298b6ead604d Mon Sep 17 00:00:00 2001 From: Kohei Date: Sun, 1 Mar 2026 01:05:28 +0900 Subject: [PATCH] feat: unify version management with VERSION file and bump workflow Add a single VERSION file (0.1.0) as the source of truth for both Go backend and Android app. Makefile reads from VERSION with git describe fallback, build.gradle.kts dynamically loads ../VERSION, and .goreleaser.yaml now has explicit ldflags matching Go variables. Includes a version-bump GitHub Actions workflow for automated semver bumps and a release validation step to ensure tag/VERSION consistency. Co-Authored-By: Claude Opus 4.6 --- .github/workflows/release.yml | 11 ++++++ .github/workflows/version-bump.yml | 54 ++++++++++++++++++++++++++++++ .goreleaser.yaml | 5 +++ Makefile | 2 +- VERSION | 1 + android/app/build.gradle.kts | 5 ++- 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/version-bump.yml create mode 100644 VERSION diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3fbebe8ab..8158919eb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,6 +30,17 @@ jobs: with: fetch-depth: 0 + - name: Validate version + env: + TAG_VERSION: ${{ inputs.tag }} + run: | + FILE_VERSION=$(cat VERSION) + TAG_VERSION="${TAG_VERSION#v}" + if [ "$FILE_VERSION" != "$TAG_VERSION" ]; then + echo "::error::Tag ($TAG_VERSION) ≠ VERSION file ($FILE_VERSION). Run version-bump first." + exit 1 + fi + - name: Create and push tag shell: bash env: diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml new file mode 100644 index 000000000..1ba750774 --- /dev/null +++ b/.github/workflows/version-bump.yml @@ -0,0 +1,54 @@ +name: Version Bump +on: + workflow_dispatch: + inputs: + bump: + description: "Semver bump type" + required: true + type: choice + options: + - patch + - minor + - major + +permissions: + contents: write + +jobs: + bump: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Read current version + id: current + run: echo "version=$(cat VERSION)" >> "$GITHUB_OUTPUT" + + - name: Calculate next version + id: next + run: | + IFS='.' read -r major minor patch <<< "${{ steps.current.outputs.version }}" + case "${{ inputs.bump }}" in + major) major=$((major+1)); minor=0; patch=0 ;; + minor) minor=$((minor+1)); patch=0 ;; + patch) patch=$((patch+1)) ;; + esac + echo "version=${major}.${minor}.${patch}" >> "$GITHUB_OUTPUT" + + - name: Update VERSION file + run: echo "${{ steps.next.outputs.version }}" > VERSION + + - name: Increment versionCode + run: | + FILE=android/app/build.gradle.kts + CODE=$(grep -oP 'versionCode\s*=\s*\K\d+' "$FILE") + sed -i "s/versionCode\s*=\s*[0-9]\+/versionCode = $((CODE+1))/" "$FILE" + echo "versionCode: $CODE -> $((CODE+1))" + + - name: Commit and push + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add VERSION android/app/build.gradle.kts + git commit -m "chore: bump version to ${{ steps.next.outputs.version }}" + git push diff --git a/.goreleaser.yaml b/.goreleaser.yaml index f85f8f2ed..79369a627 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -18,6 +18,11 @@ builds: - arm64 - arm main: ./cmd/clawdroid + ldflags: + - -s -w + - -X main.version={{.Version}} + - -X main.gitCommit={{.Commit}} + - -X main.buildTime={{.Date}} archives: - formats: [tar.gz] diff --git a/Makefile b/Makefile index 08f50efec..f277bc69b 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ CMD_DIR=cmd/$(BINARY_NAME) MAIN_GO=$(CMD_DIR)/main.go # Version -VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") +VERSION?=$(shell cat VERSION 2>/dev/null || git describe --tags --always --dirty 2>/dev/null || echo "dev") GIT_COMMIT=$(shell git rev-parse --short=8 HEAD 2>/dev/null || echo "dev") BUILD_TIME=$(shell date +%FT%T%z) GO_VERSION=$(shell $(GO) version | awk '{print $$3}') diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..6e8bf73aa --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index b6bee367e..826242ed2 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -13,6 +13,9 @@ val keystoreProperties = Properties().apply { } } +val versionFile = rootProject.file("../VERSION") +val appVersionName = if (versionFile.exists()) versionFile.readText().trim() else "0.1.0" + android { namespace = "io.clawdroid" compileSdk = libs.versions.android.compileSdk.get().toInt() @@ -22,7 +25,7 @@ android { minSdk = libs.versions.android.minSdk.get().toInt() targetSdk = libs.versions.android.targetSdk.get().toInt() versionCode = 1 - versionName = "1.0.0" + versionName = appVersionName } signingConfigs {