Skip to content

Commit 97dafe1

Browse files
committed
Compute version from git tags
1 parent df84b6a commit 97dafe1

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

.github/workflows/release.yml

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,45 @@ jobs:
5050
node-version: 22
5151
cache: "pnpm"
5252

53-
- name: Bump minor version
53+
- name: Compute version from git tags
5454
id: version
5555
run: |
56-
CURRENT_VERSION=$(jq -r .version apps/array/package.json)
57-
MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)
58-
MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
59-
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
60-
echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION"
56+
# Find the latest minor version tag (vX.Y format - exactly 2 parts)
57+
# These are manually created to mark new minor releases
58+
# Release tags (vX.Y.Z) are ignored for base version calculation
59+
LATEST_TAG=$(git tag --list 'v[0-9]*.[0-9]*' --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+$' | head -1)
60+
61+
# Fall back to vX.Y.0 format if no vX.Y tags exist (backward compat)
62+
if [ -z "$LATEST_TAG" ]; then
63+
LATEST_TAG=$(git tag --list 'v[0-9]*.[0-9]*.0' --sort=-v:refname | head -1)
64+
fi
65+
66+
if [ -z "$LATEST_TAG" ]; then
67+
echo "No version tag found. Create one with: git tag v0.15 && git push origin v0.15"
68+
exit 1
69+
fi
70+
71+
# Extract major.minor from tag
72+
VERSION_PART=${LATEST_TAG#v}
73+
MAJOR=$(echo "$VERSION_PART" | cut -d. -f1)
74+
MINOR=$(echo "$VERSION_PART" | cut -d. -f2)
6175
62-
jq --arg v "$NEW_VERSION" '.version = $v' apps/array/package.json > tmp.json && mv tmp.json apps/array/package.json
76+
# Count commits since the base tag
77+
PATCH=$(git rev-list "$LATEST_TAG"..HEAD --count)
6378
64-
git config user.name "posthog-bot"
65-
git config user.email "[email protected]"
66-
git add apps/array/package.json
67-
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
68-
git push
79+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
80+
echo "Version: $NEW_VERSION (from base tag $LATEST_TAG + $PATCH commits)"
6981
7082
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
83+
echo "base_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT"
84+
85+
- name: Set version in package.json
86+
env:
87+
APP_VERSION: ${{ steps.version.outputs.version }}
88+
run: |
89+
# Update package.json for the build (not committed)
90+
jq --arg v "$APP_VERSION" '.version = $v' apps/array/package.json > tmp.json && mv tmp.json apps/array/package.json
91+
echo "Set apps/array/package.json version to $APP_VERSION"
7192
7293
- name: Install dependencies
7394
run: pnpm install --frozen-lockfile

apps/array/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@posthog/array",
3-
"version": "0.14.0",
3+
"version": "0.0.0-dev",
44
"description": "Array - PostHog desktop task manager",
55
"main": ".vite/build/index.js",
66
"versionHash": "dynamic",

0 commit comments

Comments
 (0)