Skip to content

Commit 7ffac1b

Browse files
authored
Update release.yml to support commit signing (#458)
* Update release.yml to support commit signing The `planetscale/ghcommit-action` action uses ghcommit which uses the GitHub API, which supports commit signing by default. This removes the need to configure a GPG key in our Action. * Pin uv action * Pin pypa/gh-action-pypi-publish action * Add note about commit signing to readme * Fix semgrep findings
1 parent 4f570cc commit 7ffac1b

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

.github/workflows/release.yml

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
python-version: 3.11.11
102102

103103
- name: Install uv
104-
uses: astral-sh/setup-uv@v5
104+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
105105
with:
106106
enable-cache: true
107107
pyproject-file: "pyproject.toml"
@@ -126,11 +126,6 @@ jobs:
126126
- name: Install dependencies
127127
run: uv sync --extra dev
128128

129-
- name: Configure Git
130-
run: |
131-
git config user.name "github-actions[bot]"
132-
git config user.email "github-actions[bot]@users.noreply.github.com"
133-
134129
- name: Prepare release with Sampo
135130
id: sampo-release
136131
env:
@@ -141,66 +136,67 @@ jobs:
141136
echo "new_version=$new_version" >> "$GITHUB_OUTPUT"
142137
143138
- name: Sync version to posthog/version.py
139+
env:
140+
NEW_VERSION: ${{ steps.sampo-release.outputs.new_version }}
144141
run: |
145-
echo 'VERSION = "${{ steps.sampo-release.outputs.new_version }}"' > posthog/version.py
142+
echo "VERSION = \"$NEW_VERSION\"" > posthog/version.py
146143
147144
- name: Commit release changes
148145
id: commit-release
146+
uses: planetscale/ghcommit-action@25309d8005ac7c3bcd61d3fe19b69e0fe47dbdde # v0.2.20
147+
with:
148+
commit_message: "chore: Release v${{ steps.sampo-release.outputs.new_version }}"
149+
repo: ${{ github.repository }}
150+
branch: master
149151
env:
150152
GITHUB_TOKEN: ${{ steps.releaser.outputs.token }}
151-
run: |
152-
git add -A
153-
if git diff --staged --quiet; then
154-
echo "No changes to commit"
155-
echo "committed=false" >> "$GITHUB_OUTPUT"
156-
else
157-
git commit -m "chore: Release v${{ steps.sampo-release.outputs.new_version }}"
158-
git push origin master
159-
echo "committed=true" >> "$GITHUB_OUTPUT"
160-
fi
161153

162154
# Publishing is done manually (not via `sampo publish`) because we need to
163155
# publish both `posthog` and `posthoganalytics` packages to PyPI.
164156
# Sampo only knows about the `posthog` package, so we handle both here.
165157
# Both packages use PyPI OIDC trusted publishing (no API tokens needed).
166158
- name: Build posthog
167-
if: steps.commit-release.outputs.committed == 'true'
159+
if: steps.commit-release.outputs.commit-hash != ''
168160
run: uv run make build_release
169161

170162
- name: Publish posthog to PyPI
171-
if: steps.commit-release.outputs.committed == 'true'
172-
uses: pypa/gh-action-pypi-publish@release/v1
163+
if: steps.commit-release.outputs.commit-hash != ''
164+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
173165

174166
# The `posthoganalytics` package is a mirror of `posthog` published under
175167
# a different name for backwards compatibility. The make target handles
176168
# copying, renaming imports, and building the dist automatically.
177169
- name: Build posthoganalytics
178-
if: steps.commit-release.outputs.committed == 'true'
170+
if: steps.commit-release.outputs.commit-hash != ''
179171
run: uv run make build_release_analytics
180172

181173
- name: Publish posthoganalytics to PyPI
182-
if: steps.commit-release.outputs.committed == 'true'
183-
uses: pypa/gh-action-pypi-publish@release/v1
174+
if: steps.commit-release.outputs.commit-hash != ''
175+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
184176

185177
# We skip `sampo publish` (which normally creates the tag) because we
186178
# need to publish both posthog and posthoganalytics manually, so we
187179
# create the tag ourselves.
188180
- name: Tag release
189-
if: steps.commit-release.outputs.committed == 'true'
190-
run: git tag "v${{ steps.sampo-release.outputs.new_version }}"
191-
192-
- name: Push tags
193-
if: steps.commit-release.outputs.committed == 'true'
194-
run: git push origin --tags
181+
if: steps.commit-release.outputs.commit-hash != ''
182+
env:
183+
GH_TOKEN: ${{ steps.releaser.outputs.token }}
184+
NEW_VERSION: ${{ steps.sampo-release.outputs.new_version }}
185+
COMMIT_HASH: ${{ steps.commit-release.outputs.commit-hash }}
186+
run: |
187+
gh api "repos/${{ github.repository }}/git/refs" \
188+
-f "ref=refs/tags/v$NEW_VERSION" \
189+
-f "sha=$COMMIT_HASH"
195190
196191
- name: Create GitHub Release
197-
if: steps.commit-release.outputs.committed == 'true'
192+
if: steps.commit-release.outputs.commit-hash != ''
198193
env:
199194
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
200-
run: gh release create "v${{ steps.sampo-release.outputs.new_version }}" --generate-notes
195+
NEW_VERSION: ${{ steps.sampo-release.outputs.new_version }}
196+
run: gh release create "v$NEW_VERSION" --generate-notes
201197

202198
- name: Dispatch generate-references
203-
if: steps.commit-release.outputs.committed == 'true'
199+
if: steps.commit-release.outputs.commit-hash != ''
204200
env:
205201
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
206202
run: gh workflow run generate-references.yml --ref master

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Please see the [Python integration docs](https://posthog.com/docs/integrations/p
2222

2323
## Development
2424

25+
This repo requires all commits to be signed. To configure commit signing, see the [PostHog handbook](https://posthog.com/handbook/engineering/security#commit-signing).
26+
2527
### Testing Locally
2628

2729
We recommend using [uv](https://docs.astral.sh/uv/). It's super fast.

0 commit comments

Comments
 (0)