Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Prepare Release

on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., 1.2.3 or 1.2.3-alpha.1)'
required: true
type: string

permissions:
contents: write
pull-requests: write

jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Validate version
id: validate_version
run: |
VERSION="${{ inputs.version }}"

# Use the validation script
./scripts/validate-version.sh "$VERSION"

# If validation passed, output the version
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Create release branch
run: |
git checkout main
git pull origin main
git checkout -b release/${{ steps.validate_version.outputs.version }}

- name: Update versions and changelog
run: |
./scripts/bump-version.sh ${{ steps.validate_version.outputs.version }}

- name: Commit changes
run: |
git add -A
git commit -m "chore(release): bump to ${{ steps.validate_version.outputs.version }}"

- name: Push release branch
run: |
git push origin release/${{ steps.validate_version.outputs.version }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@98357b18bf14b5342f975ff684046ec3b2a07725 # v8.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: release/${{ steps.validate_version.outputs.version }}
base: main
title: "chore(release): bump to ${{ steps.validate_version.outputs.version }}"
body: |
## Release ${{ steps.validate_version.outputs.version }}

This PR was automatically created by the release workflow.

### Changes
- Updated version in pubspec.yaml
- Updated version in iOS (PostHogFlutterVersion.swift)
- Updated version in Android (PostHogVersion.kt)
- Updated CHANGELOG.md

### Next Steps
1. Review and approve this PR
2. Merge to main
3. The release tag will be created automatically after merge
Comment thread Fixed
54 changes: 54 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Tag Release After Merge

on:
pull_request:
types: [closed]
branches:
- main

permissions:
contents: write

jobs:
tag-release:
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/')
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can also be a tag, no strong pref.

runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Extract version from branch name
id: extract_version
run: |
BRANCH="${{ github.event.pull_request.head.ref }}"
VERSION="${BRANCH#release/}"
echo "version=$VERSION" >> $GITHUB_OUTPUT

# Check if version has a suffix (prerelease)
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+-.*$ ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi

- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# Create annotated tag
git tag -a "${{ steps.extract_version.outputs.version }}" -m "Release ${{ steps.extract_version.outputs.version }}"

# Push the tag
git push origin "${{ steps.extract_version.outputs.version }}"

- name: Update GitHub Release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
with:
tag_name: ${{ steps.extract_version.outputs.version }}
name: Release ${{ steps.extract_version.outputs.version }}
draft: false
prerelease: ${{ steps.extract_version.outputs.is_prerelease }}
generate_release_notes: true
Comment thread Fixed
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be cool to extract the notes from the changelog instead

70 changes: 48 additions & 22 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
Releasing
=========

Since `main` is protected, releases are done via pull requests.

1. Update the CHANGELOG.md with the version
2. Choose a tag name (e.g. `3.0.0`), this is the version number of the release.
1. Preview releases follow the pattern `3.0.0-alpha.1`, `3.0.0-beta.1`, `3.0.0-RC.1`
2. Execute the script with the tag's name, the script will update the version file and create a release branch.

```bash
./scripts/prepare-release.sh 3.0.0
```
3. Create a PR from the release branch to `main`
4. Get approval and merge the PR
5. Go to [GH Releases](https://github.com/PostHog/posthog-flutter/releases)
6. Choose a tag name (e.g. `3.0.0`), same as step 2.
7. Choose a release name (e.g. `3.0.0`), ideally it matches the above.
8. Write a description of the release.
9. Publish the release.
10. GH Action (publish.yml) is doing everything else [automatically](https://pub.dev/packages/posthog_flutter/admin).
11. Done.
# Automated Release Process

This repository uses GitHub Actions to automate the release process. The workflow ensures that all version updates and changelog modifications are completed before creating the release tag.

## How It Works

The release process is split into two workflows:

### 1. Prepare Release Workflow (`prepare-release.yml`)
- Triggered manually via GitHub Actions UI with a version input
- Creates a release branch
- Updates version in all necessary files (pubspec.yaml, iOS, Android)
- Updates CHANGELOG.md (replaces `## Next` with the version or adds it at the top)
- Creates a Pull Request to main

### 2. Tag Release Workflow (`tag-release.yml`)
- Automatically triggered when a release PR is merged to main
- Creates a git tag with the version
- Creates a GitHub Release with auto-generated release notes
Comment on lines +9 to +19
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're essentially moving the manual runs of the shell scripts into a workflow dispatch. I like this approach.

I suppose the only potential gap we might have would be if someone modifies the CHANGELOG, but adds their changes under a specific version instead of 'next'. Seems like we should be able to solve that, though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the only potential gap we might have would be if someone modifies the CHANGELOG, but adds their changes under a specific version instead of 'next'. Seems like we should be able to solve that, though.

we can also disable auto-generated and parse the changelog and pass it to the GH actions
the other option is to fully automate the changelog as well so we dont have to do it manually, but usually this adds a bunch of PRs with no user facing changes, or rely on a label which we will forget, as we also forget with changesets, i dont think theres a silver bullet tho


## Release Steps

### Step 1: Prepare Your Changes
1. Ensure all your changes are merged to main
2. Update CHANGELOG.md with release notes under `## Next` section (optional - if not present, version will be added at the top)

### Step 2: Trigger the Release
1. Go to Actions tab in GitHub
2. Select "Prepare Release" workflow
3. Click "Run workflow"
4. Enter the version number (e.g., `5.10.0` or `5.10.0-beta.1`)
5. Click "Run workflow"

### Step 3: Review and Merge
1. The workflow will create a PR with all version updates
2. Review the changes
3. Approve and merge the PR

### Step 4: Automatic Tag Creation
1. Once the PR is merged, the tag-release workflow automatically:
- Creates a git tag (e.g., `v5.10.0`)
- Creates a GitHub Release with release notes

## Version Format

The version must follow semantic versioning:
- Format: `X.Y.Z` or `X.Y.Z-suffix`
- Examples: `1.2.3`, `2.0.0-alpha.1`, `3.1.0-beta.2`
15 changes: 15 additions & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@ perl -pi -e "s/postHogVersion = \".*\"/postHogVersion = \"$NEW_VERSION\"/" andro

# Replace Flutter `version` with the given version
perl -pi -e "s/^version: .*/version: $NEW_VERSION/" pubspec.yaml

# Update CHANGELOG.md
echo "Updating CHANGELOG.md..."
if grep -q "^## $NEW_VERSION$" CHANGELOG.md; then
# Version already exists, do nothing
echo "Version '## $NEW_VERSION' already exists in CHANGELOG.md, skipping update"
elif grep -q "^## Next" CHANGELOG.md; then
# Replace "## Next" with the new version
perl -pi -e "s/^## Next$/## $NEW_VERSION/" CHANGELOG.md
echo "Replaced '## Next' with '## $NEW_VERSION' in CHANGELOG.md"
else
# If "## Next" doesn't exist and version doesn't exist, add the new version at the top of the file
perl -i -pe "if (\$. == 1) {print \"## $NEW_VERSION\\n\\n\"}" CHANGELOG.md
echo "Added '## $NEW_VERSION' at the top of CHANGELOG.md"
fi
33 changes: 0 additions & 33 deletions scripts/prepare-release.sh

This file was deleted.

26 changes: 26 additions & 0 deletions scripts/validate-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Validates a version string against semantic versioning format
# Usage: ./scripts/validate-version.sh <version>
# Returns: 0 if valid, 1 if invalid

set -e

if [[ $# -ne 1 ]]; then
echo "Usage: $0 <version>"
echo "Example: $0 1.2.3"
echo "Example: $0 1.2.3-alpha.1"
exit 1
fi

VERSION="$1"

# Validate version format (e.g., 1.2.3 or 1.2.3-alpha.1)
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
echo "Error: Invalid version format: $VERSION" >&2
echo "Version must match pattern: X.Y.Z or X.Y.Z-suffix (e.g., 1.2.3 or 1.2.3-alpha.1)" >&2
exit 1
fi

echo "Version $VERSION is valid"
exit 0
Loading