Skip to content

Commit 5f90f6a

Browse files
authored
ci: always release on push to main (#346)
1 parent 0a46302 commit 5f90f6a

File tree

1 file changed

+46
-74
lines changed

1 file changed

+46
-74
lines changed

.github/workflows/release.yml

Lines changed: 46 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,28 @@ on:
44
push:
55
branches:
66
- main
7-
workflow_dispatch:
8-
inputs:
9-
tag:
10-
description: "Version tag (e.g. v0.1.0). Leave empty to reuse package.json."
11-
required: false
12-
type: string
7+
paths:
8+
- "apps/array/**"
9+
- "packages/agent/**"
10+
- "pnpm-lock.yaml"
11+
- "package.json"
12+
- "turbo.json"
13+
- ".github/workflows/release.yml"
1314

1415
permissions:
1516
contents: write
1617

17-
jobs:
18-
determine-version:
19-
runs-on: ubuntu-latest
20-
outputs:
21-
should_publish: ${{ steps.detect.outputs.should_publish || steps.manual.outputs.should_publish }}
22-
version: ${{ steps.detect.outputs.version || steps.manual.outputs.version }}
23-
steps:
24-
- name: Checkout
25-
uses: actions/checkout@v5
26-
with:
27-
fetch-depth: 0
28-
29-
- name: Manual version input
30-
if: github.event_name == 'workflow_dispatch'
31-
id: manual
32-
run: |
33-
VERSION="${{ inputs.tag }}"
34-
if [ -z "$VERSION" ]; then
35-
VERSION=$(jq -r .version apps/array/package.json)
36-
fi
37-
VERSION="${VERSION#v}"
38-
if [ -z "$VERSION" ]; then
39-
echo "Failed to determine version for manual publish."
40-
exit 1
41-
fi
42-
echo "Using manual version $VERSION"
43-
echo "should_publish=true" >> "$GITHUB_OUTPUT"
44-
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
45-
46-
- name: Detect version change on main
47-
if: github.event_name != 'workflow_dispatch'
48-
id: detect
49-
run: |
50-
if ! git rev-parse HEAD~1 >/dev/null 2>&1; then
51-
echo "Initial commit detected, skipping publish."
52-
echo "should_publish=false" >> "$GITHUB_OUTPUT"
53-
exit 0
54-
fi
55-
CURRENT_VERSION=$(jq -r .version apps/array/package.json)
56-
PREVIOUS_VERSION=$(git show HEAD~1:apps/array/package.json | jq -r .version)
57-
if [ "$CURRENT_VERSION" = "$PREVIOUS_VERSION" ]; then
58-
echo "Version unchanged ($CURRENT_VERSION), skipping publish."
59-
echo "should_publish=false" >> "$GITHUB_OUTPUT"
60-
exit 0
61-
fi
62-
echo "Detected version bump from $PREVIOUS_VERSION to $CURRENT_VERSION"
63-
echo "should_publish=true" >> "$GITHUB_OUTPUT"
64-
echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
18+
concurrency:
19+
group: release
20+
cancel-in-progress: true
6521

22+
jobs:
6623
publish:
67-
needs: determine-version
68-
if: needs.determine-version.outputs.should_publish == 'true'
6924
runs-on: macos-latest
7025
env:
7126
GH_TOKEN: ${{ secrets.POSTHOG_BOT_PAT }}
7227
GITHUB_TOKEN: ${{ secrets.POSTHOG_BOT_PAT }}
7328
NODE_ENV: production
74-
APP_VERSION: ${{ needs.determine-version.outputs.version }}
7529
APPLE_CODESIGN_IDENTITY: ${{ secrets.APPLE_CODESIGN_IDENTITY }}
7630
APPLE_ID: ${{ secrets.APPLE_ID }}
7731
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
@@ -84,17 +38,42 @@ jobs:
8438
uses: actions/checkout@v5
8539
with:
8640
fetch-depth: 0
41+
token: ${{ secrets.POSTHOG_BOT_PAT }}
42+
8743
- name: Setup pnpm
8844
uses: pnpm/action-setup@v4
45+
8946
- name: Setup Node.js
9047
uses: actions/setup-node@v4
9148
with:
9249
node-version: 22
9350
cache: "pnpm"
51+
52+
- name: Bump minor version
53+
id: version
54+
run: |
55+
CURRENT_VERSION=$(jq -r .version apps/array/package.json)
56+
MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)
57+
MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
58+
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
59+
echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION"
60+
61+
jq --arg v "$NEW_VERSION" '.version = $v' apps/array/package.json > tmp.json && mv tmp.json apps/array/package.json
62+
63+
git config user.name "posthog-bot"
64+
git config user.email "[email protected]"
65+
git add apps/array/package.json
66+
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
67+
git push
68+
69+
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
70+
9471
- name: Install dependencies
9572
run: pnpm install --frozen-lockfile
73+
9674
- name: Build agent package
9775
run: pnpm --filter @posthog/agent run build
76+
9877
- name: Import code signing certificate
9978
if: env.APPLE_CODESIGN_IDENTITY != ''
10079
env:
@@ -115,26 +94,19 @@ jobs:
11594
security list-keychains -d user -s "$KEYCHAIN" $(security list-keychains -d user | tr -d '"')
11695
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN"
11796
rm "$RUNNER_TEMP/certificate.p12"
118-
- name: Verify package version
119-
run: |
120-
PACKAGE_VERSION=$(jq -r .version apps/array/package.json)
121-
if [ "$PACKAGE_VERSION" != "$APP_VERSION" ]; then
122-
echo "Package version $PACKAGE_VERSION does not match expected $APP_VERSION"
123-
exit 1
124-
fi
125-
- name: Create or reuse tag
97+
98+
- name: Create tag
99+
env:
100+
APP_VERSION: ${{ steps.version.outputs.version }}
126101
run: |
127102
TAG="v$APP_VERSION"
128-
git fetch --tags
129-
if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then
130-
echo "Tag $TAG already exists, reusing it."
131-
else
132-
git config user.name "posthog-bot"
133-
git config user.email "[email protected]"
134-
git tag -a "$TAG" -m "Release $TAG"
135-
git push https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }} "$TAG"
136-
fi
103+
git tag -a "$TAG" -m "Release $TAG"
104+
git push https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }} "$TAG"
105+
137106
- name: Build native modules
138107
run: pnpm --filter array run build-native
108+
139109
- name: Publish with Electron Forge
110+
env:
111+
APP_VERSION: ${{ steps.version.outputs.version }}
140112
run: pnpm --filter array run publish

0 commit comments

Comments
 (0)