Skip to content

Commit 4e05e2c

Browse files
committed
Automate agent versioning with git tags in CI
1 parent 008f1d5 commit 4e05e2c

4 files changed

Lines changed: 90 additions & 32 deletions

File tree

.github/workflows/agent-release.yml

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,17 @@ name: Release Agent
22

33
on:
44
push:
5-
branches:
6-
- main
7-
workflow_dispatch:
5+
tags:
6+
- "agent-v*"
87

98
concurrency:
109
group: agent-release
1110
cancel-in-progress: false
1211

1312
jobs:
14-
check-package-version:
15-
name: Check package version and detect an update
16-
runs-on: ubuntu-latest
17-
permissions:
18-
contents: read
19-
outputs:
20-
committed-version: ${{ steps.check-package-version.outputs.committed-version }}
21-
published-version: ${{ steps.check-package-version.outputs.published-version }}
22-
is-new-version: ${{ steps.check-package-version.outputs.is-new-version }}
23-
steps:
24-
- name: Checkout repository
25-
uses: actions/checkout@v6
26-
with:
27-
persist-credentials: false
28-
29-
- name: Check package version and detect an update
30-
id: check-package-version
31-
uses: PostHog/check-package-version@v2
32-
with:
33-
path: packages/agent
34-
3513
release:
36-
name: Publish release if new version
14+
name: Publish agent to npm
3715
runs-on: ubuntu-latest
38-
needs: check-package-version
39-
if: needs.check-package-version.outputs.is-new-version == 'true'
4016
permissions:
4117
contents: read
4218
id-token: write
@@ -56,6 +32,20 @@ jobs:
5632
cache: "pnpm"
5733
registry-url: https://registry.npmjs.org
5834

35+
- name: Extract version from tag
36+
id: version
37+
run: |
38+
TAG_VERSION="${GITHUB_REF#refs/tags/agent-v}"
39+
echo "Version: $TAG_VERSION"
40+
echo "version=$TAG_VERSION" >> "$GITHUB_OUTPUT"
41+
42+
- name: Set version in package.json
43+
env:
44+
APP_VERSION: ${{ steps.version.outputs.version }}
45+
run: |
46+
jq --arg v "$APP_VERSION" '.version = $v' packages/agent/package.json > tmp.json && mv tmp.json packages/agent/package.json
47+
echo "Set packages/agent/package.json version to $APP_VERSION"
48+
5949
- name: Install dependencies
6050
run: pnpm install --frozen-lockfile
6151

@@ -76,7 +66,7 @@ jobs:
7666

7767
- name: Publish the package to npm registry
7868
working-directory: packages/agent
79-
run: pnpm publish --access public
69+
run: pnpm publish --access public --no-git-checks
8070
env:
8171
NPM_CONFIG_PROVENANCE: true
8272
NODE_AUTH_TOKEN: ''

.github/workflows/agent-tag.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Tag Agent Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "packages/agent/**"
9+
- ".github/workflows/agent-tag.yml"
10+
- ".github/workflows/agent-release.yml"
11+
12+
concurrency:
13+
group: agent-tag
14+
cancel-in-progress: false
15+
16+
jobs:
17+
tag:
18+
permissions:
19+
contents: write
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Get app token
23+
id: app-token
24+
uses: getsentry/action-github-app-token@d4b5da6c5e37703f8c3b3e43abb5705b46e159cc # v3
25+
with:
26+
app_id: ${{ secrets.GH_APP_ARRAY_RELEASER_APP_ID }}
27+
private_key: ${{ secrets.GH_APP_ARRAY_RELEASER_PRIVATE_KEY }}
28+
29+
- name: Checkout
30+
uses: actions/checkout@v6
31+
with:
32+
fetch-depth: 0
33+
token: ${{ steps.app-token.outputs.token }}
34+
35+
- name: Compute version and create tag
36+
env:
37+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
38+
REPOSITORY: ${{ github.repository }}
39+
run: |
40+
# Find the latest agent base version tag (agent-vX.Y or agent-vX.Y.0 format)
41+
LATEST_TAG=$(git tag --list 'agent-v[0-9]*.[0-9]*' --sort=-v:refname | grep -E '^agent-v[0-9]+\.[0-9]+(\.0)?$' | head -1)
42+
43+
if [ -z "$LATEST_TAG" ]; then
44+
echo "No agent version tag found. Create one with: git tag agent-v2.1 && git push origin agent-v2.1"
45+
exit 1
46+
fi
47+
48+
# Extract major.minor from tag
49+
VERSION_PART=${LATEST_TAG#agent-v}
50+
MAJOR=$(echo "$VERSION_PART" | cut -d. -f1)
51+
MINOR=$(echo "$VERSION_PART" | cut -d. -f2)
52+
53+
# Count commits since the base tag
54+
PATCH=$(git rev-list "$LATEST_TAG"..HEAD --count)
55+
56+
if [ "$PATCH" -eq 0 ]; then
57+
echo "No commits since $LATEST_TAG. Nothing to release."
58+
exit 0
59+
fi
60+
61+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
62+
TAG="agent-v$NEW_VERSION"
63+
echo "Creating tag: $TAG (from base tag $LATEST_TAG + $PATCH commits)"
64+
65+
git config user.email "github-actions[bot]@users.noreply.github.com"
66+
git config user.name "github-actions[bot]"
67+
git tag -a "$TAG" -m "Agent release $TAG"
68+
git push "https://x-access-token:${GH_TOKEN}@github.com/$REPOSITORY" "$TAG"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Tag Release
1+
name: Tag Twig Release
22

33
on:
44
push:
@@ -11,11 +11,11 @@ on:
1111
- "pnpm-lock.yaml"
1212
- "package.json"
1313
- "turbo.json"
14-
- ".github/workflows/tag.yml"
14+
- ".github/workflows/twig-tag.yml"
1515
- ".github/workflows/twig-release.yml"
1616

1717
concurrency:
18-
group: tag
18+
group: twig-tag
1919
cancel-in-progress: false
2020

2121
jobs:

packages/agent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@posthog/agent",
3-
"version": "2.0.3",
3+
"version": "0.0.0-dev",
44
"repository": "https://github.com/PostHog/twig",
55
"description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
66
"exports": {

0 commit comments

Comments
 (0)