Skip to content
Merged
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
1 change: 0 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
### If releasing new changes

- [ ] Ran `sampo add` to generate a changeset file
- [ ] Added the `release` label to the PR

<!-- For more details check RELEASING.md -->
37 changes: 16 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,50 @@
name: "Release"

on:
pull_request:
types: [closed]
push:
branches: [main]
paths:
- '.sampo/changesets/*.md'
workflow_dispatch:

permissions:
contents: read

# Concurrency control: only one release process can run at a time
# This prevents race conditions if multiple PRs with 'release' label merge simultaneously
# This prevents race conditions if multiple releasable changesets merge simultaneously
concurrency:
group: release
cancel-in-progress: false

jobs:
check-release-label:
name: Check for release label
check-changesets:
name: Check for changesets
runs-on: ubuntu-latest
# Run when PR with 'release' label is merged to main
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'release'))
outputs:
should-release: ${{ steps.check.outputs.should-release }}
has-changesets: ${{ steps.check.outputs.has-changesets }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0

- name: Check release conditions
- name: Check for changesets
id: check
run: |
changeset_count=$(find .sampo/changesets -name '*.md' 2>/dev/null | wc -l)
if [ "$changeset_count" -gt 0 ]; then
echo "should-release=true" >> "$GITHUB_OUTPUT"
echo "has-changesets=true" >> "$GITHUB_OUTPUT"
echo "Found $changeset_count changeset(s), ready to release"
else
echo "should-release=false" >> "$GITHUB_OUTPUT"
echo "has-changesets=false" >> "$GITHUB_OUTPUT"
echo "No changesets to release"
fi

notify-approval-needed:
name: Notify Slack - Approval Needed
needs: check-release-label
if: needs.check-release-label.outputs.should-release == 'true'
needs: check-changesets
if: needs.check-changesets.outputs.has-changesets == 'true'
uses: posthog/.github/.github/workflows/notify-approval-needed.yml@main
with:
slack_channel_id: ${{ vars.SLACK_APPROVALS_CLIENT_LIBRARIES_CHANNEL_ID }}
Expand All @@ -60,11 +55,11 @@ jobs:

release:
name: Release and publish
needs: [check-release-label, notify-approval-needed]
needs: [check-changesets, notify-approval-needed]
runs-on: ubuntu-latest
# Use `always()` to ensure the job runs even if notify-approval-needed is skipped,
# but still depend on it to access `needs.notify-approval-needed.outputs.slack_ts`
if: always() && needs.check-release-label.outputs.should-release == 'true'
if: always() && needs.check-changesets.outputs.has-changesets == 'true'
environment: "Release" # This will require an approval from a maintainer, they are notified in Slack above
permissions:
contents: write
Expand Down Expand Up @@ -143,7 +138,7 @@ jobs:
id: commit-release
uses: planetscale/ghcommit-action@25309d8005ac7c3bcd61d3fe19b69e0fe47dbdde # v0.2.20
with:
commit_message: "chore: Release v${{ steps.sampo-release.outputs.new_version }}"
commit_message: "chore: Release v${{ steps.sampo-release.outputs.new_version }} [skip ci]"
repo: ${{ github.repository }}
branch: main
env:
Expand Down Expand Up @@ -257,7 +252,7 @@ jobs:

notify-released:
name: Notify Slack - Released
needs: [check-release-label, notify-approval-needed, release]
needs: [check-changesets, notify-approval-needed, release]
runs-on: ubuntu-latest
if: always() && needs.release.result == 'success' && needs.notify-approval-needed.outputs.slack_ts != ''
steps:
Expand Down
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repository uses [Sampo](https://github.com/bruits/sampo) for versioning and

1. When making changes, include a changeset: `sampo add`
2. Create a PR with your changes and the changeset file
3. Add the `release` label and merge to `main`
3. Merge to `main` (no release label required)
4. Approve the release in Slack when prompted — this triggers the version bump, publishes both `posthog` and the `posthoganalytics` mirror package to PyPI, creates a git tag, and creates a GitHub Release

You can also trigger a release manually via the workflow's `workflow_dispatch` trigger (still requires pending changesets).
Loading