Skip to content

Commit 0e1a24e

Browse files
authored
feat: Release and version strategy (#358)
1 parent 55b1ada commit 0e1a24e

File tree

3 files changed

+105
-13
lines changed

3 files changed

+105
-13
lines changed

.github/workflows/release.yml

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,50 @@ jobs:
5252
node-version: 22
5353
cache: "pnpm"
5454

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

UPDATES.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Releasing Updates
2+
3+
Array uses semantic versioning with git tags. Patch versions are automatically computed from commit counts.
4+
5+
The version in `apps/array/package.json` is set to `0.0.0-dev` - this is intentional. CI injects the real version at build time from git tags.
6+
7+
## Version Format: `major.minor.patch`
8+
9+
- **major.minor**: Controlled by git tags (e.g., `v0.15`, `v1.0`)
10+
- **patch**: Auto-calculated as number of commits since the minor tag
11+
12+
## How It Works
13+
14+
1. A base tag like `v0.15` marks the start of a minor version
15+
2. Each push to `main` triggers a release with version `0.15.N` where N = commits since `v0.15`
16+
3. No manual `package.json` updates needed for patch releases
17+
18+
## Releasing a Patch (Automatic)
19+
20+
Just push to `main`. The workflow computes the version automatically:
21+
22+
```
23+
v0.15 tag exists
24+
Push commit #1 → releases 0.15.1
25+
Push commit #2 → releases 0.15.2
26+
Push commit #3 → releases 0.15.3
27+
```
28+
29+
## Releasing a Minor Version
30+
31+
Create a new base tag when you want to bump the minor version:
32+
33+
```bash
34+
git tag v0.16
35+
git push origin v0.16
36+
```
37+
38+
The next push to `main` will release `0.16.1`.
39+
40+
## Releasing a Major Version
41+
42+
Same process, just increment the major:
43+
44+
```bash
45+
git tag v1.0
46+
git push origin v1.0
47+
```
48+
49+
## Checking Current Version
50+
51+
See what version would be released:
52+
53+
```bash
54+
# Find the current base tag
55+
git tag --list 'v[0-9]*.[0-9]*' --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+$' | head -1
56+
57+
# Count commits since base tag (this is the patch number)
58+
git rev-list v0.15..HEAD --count
59+
```
60+
61+
## Tag Naming Convention
62+
63+
- **Base tags** (manual): `vX.Y` - e.g., `v0.15`, `v1.0`
64+
- **Release tags** (auto): `vX.Y.Z` - e.g., `v0.15.3`, created by CI
65+
66+
Only base tags (`vX.Y`) are used for version calculation. Release tags (`vX.Y.Z`) are created for GitHub releases but ignored when computing the next version.

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.16.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)