:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(ci): publish posthog-replay-anonymizer on merge instead of tags (#72513)
Robbiec7a9062b53b9
diff --git a/.github/workflows/publish-replay-anonymizer-crate.yml b/.github/workflows/publish-replay-anonymizer-crate.ymlindex 971494df7033..aca13debefbd 100644--- a/.github/workflows/publish-replay-anonymizer-crate.yml+++ b/.github/workflows/publish-replay-anonymizer-crate.yml@@ -2,50 +2,151 @@ name: Publish posthog-replay-anonymizer to crates.ioon:push:- tags:- - 'posthog-replay-anonymizer/v*'+ branches:+ - master+ paths:+ - rust/replay-anonymizer/**+ - .github/workflows/publish-replay-anonymizer-crate.yml+ pull_request:+ paths:+ - rust/replay-anonymizer/**+ - .github/workflows/publish-replay-anonymizer-crate.ymlenv:CARGO_TERM_COLOR: always+concurrency:+ group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.head_ref || github.ref }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}+jobs:+ check-version-bump:+ name: Check version was bumped+ runs-on: ubuntu-24.04+ timeout-minutes: 5+ if: github.event_name == 'pull_request'+ permissions:+ contents: read+ pull-requests: write+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2++ - name: Check if crate code changed+ id: changed-files+ uses: step-security/changed-files@2e07db73e5ccdb319b9a6c7766bd46d39d304bad # v47.0.5+ with:+ files_yaml: |+ crate:+ - rust/replay-anonymizer/**++ - name: Compare crate version against crates.io+ shell: bash+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ CRATE_CHANGED: ${{ steps.changed-files.outputs.crate_any_changed }}+ IS_FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }}+ run: |+ if [[ "$CRATE_CHANGED" != 'true' ]]; then+ echo "Only the workflow changed; no version bump needed."+ exit 0+ fi+ version=$(grep -m1 '^version' rust/replay-anonymizer/Cargo.toml | sed 's/.*"\(.*\)".*/\1/')+ # 200 = version already on crates.io, 404 = will publish on merge. Retry transient registry errors.+ for attempt in 1 2 3; do+ http_code=$(curl -o /dev/null -sSL -w '%{http_code}' -A 'PostHog CI (https://github.com/PostHog/posthog)' "https://crates.io/api/v1/crates/posthog-replay-anonymizer/$version") || http_code='000'+ if [[ "$http_code" == '200' || "$http_code" == '404' ]]; then+ break+ fi+ sleep 2+ done+ if [[ "$IS_FORK" == 'true' ]]; then+ # The fork token can't post the reminder comment; surface via annotation instead.+ if [[ "$http_code" == '200' ]]; then+ echo "::warning::posthog-replay-anonymizer changed but its version stayed at $version, which is already on crates.io. Bump version in rust/replay-anonymizer/Cargo.toml."+ fi+ exit 0+ fi+ if [[ "$http_code" == '200' ]]; then+ message_body="It looks like the code of \`posthog-replay-anonymizer\` changed in this PR, but its version stayed the same at $version, which is already on crates.io. 👀"+ message_body+=$'\n'"Bump \`version\` in \`rust/replay-anonymizer/Cargo.toml\` before merging — the crate publishes automatically on merge to master."+ BODY="$message_body" GITHUB_TOKEN="$GH_TOKEN" node .github/scripts/post-reminder-section.mjs replay-anonymizer-crate warn "version bump needed"+ elif [[ "$http_code" == '404' ]]; then+ GITHUB_TOKEN="$GH_TOKEN" node .github/scripts/post-reminder-section.mjs replay-anonymizer-crate --clear "v$version will publish on merge"+ else+ # Refresh the sticky section rather than leaving a stale warn from an earlier push.+ message_body="Could not reach crates.io (HTTP $http_code) to check whether \`posthog-replay-anonymizer\` $version is already published. Push again or re-run this check to re-verify."+ BODY="$message_body" GITHUB_TOKEN="$GH_TOKEN" node .github/scripts/post-reminder-section.mjs replay-anonymizer-crate info "could not verify v$version against crates.io"+ fi+publish:name: Publish to crates.ioruns-on: ubuntu-24.04timeout-minutes: 10- if: github.repository == 'PostHog/posthog'-+ if: github.event_name == 'push' && github.repository == 'PostHog/posthog'permissions:contents: readid-token: write-defaults:run:working-directory: rust-steps:- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ fetch-depth: 0+ filter: blob:none- - name: Install rust- uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9+ - name: Check if crate code changed in this push+ id: changed-files+ uses: step-security/changed-files@2e07db73e5ccdb319b9a6c7766bd46d39d304bad # v47.0.5with:- toolchain: 1.91.1+ files_yaml: |+ crate:+ - rust/replay-anonymizer/**- - name: Verify tag matches crate version+ - name: Check whether this version is already on crates.io+ id: version+ shell: bash+ env:+ CRATE_CHANGED: ${{ steps.changed-files.outputs.crate_any_changed }}run: |- TAG_VERSION="${GITHUB_REF_NAME#posthog-replay-anonymizer/v}"- CRATE_VERSION=$(grep '^version' replay-anonymizer/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')- if [ "$TAG_VERSION" != "$CRATE_VERSION" ]; then- echo "::error::Tag version ($TAG_VERSION) does not match crate version ($CRATE_VERSION)"+ version=$(grep -m1 '^version' replay-anonymizer/Cargo.toml | sed 's/.*"\(.*\)".*/\1/')+ for attempt in 1 2 3; do+ http_code=$(curl -o /dev/null -sSL -w '%{http_code}' -A 'PostHog CI (https://github.com/PostHog/posthog)' "https://crates.io/api/v1/crates/posthog-replay-anonymizer/$version") || http_code='000'+ if [[ "$http_code" == '200' || "$http_code" == '404' ]]; then+ break+ fi+ sleep 2+ done+ if [[ "$http_code" == '200' ]]; then+ if [[ "$CRATE_CHANGED" == 'true' ]]; then+ # Fail loudly rather than silently shipping nothing: these crate changes+ # won't reach crates.io until a follow-up PR bumps the version.+ echo "::error::posthog-replay-anonymizer changed in this push but $version is already on crates.io. Bump version in rust/replay-anonymizer/Cargo.toml in a follow-up PR."+ exit 1+ fi+ echo "posthog-replay-anonymizer $version is already on crates.io; nothing to publish."+ echo "publish-needed=false" >> $GITHUB_OUTPUT+ elif [[ "$http_code" == '404' ]]; then+ echo "Publishing posthog-replay-anonymizer v$version"+ echo "publish-needed=true" >> $GITHUB_OUTPUT+ else+ echo "::error::No definitive answer from crates.io (HTTP $http_code) for posthog-replay-anonymizer $version after 3 attempts. Re-run this job once crates.io recovers."exit 1fi- echo "Publishing posthog-replay-anonymizer v$CRATE_VERSION"++ - name: Install rust+ if: steps.version.outputs.publish-needed == 'true'+ uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9+ with:+ toolchain: 1.91.1- name: Authenticate with crates.io+ if: steps.version.outputs.publish-needed == 'true'id: authuses: rust-lang/crates-io-auth-action@bbd81622f20ce9e2dd9622e3218b975523e45bbe # v1.0.4- name: Publish to crates.io+ if: steps.version.outputs.publish-needed == 'true'env:CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}run: cargo publish -p posthog-replay-anonymizerdiff --git a/frontend/bin/ci-report/update-ci-report.mjs b/frontend/bin/ci-report/update-ci-report.mjsindex 70e1626f5953..49594e463943 100644--- a/frontend/bin/ci-report/update-ci-report.mjs+++ b/frontend/bin/ci-report/update-ci-report.mjs@@ -31,6 +31,7 @@ export const SECTIONS = [{ id: 'hogql-parser-py', title: 'hogql-parser version' },{ id: 'hogql-parser-npm', title: '@posthog/hogql-parser version' },{ id: 'hogql-parser-rs', title: 'hogql-parser-rs version' },+ { id: 'replay-anonymizer-crate', title: 'posthog-replay-anonymizer version' },{ id: 'generated-docs', title: 'Generated docs' },{ id: 'docs-preview', title: 'Docs preview' },{ id: 'hobby-deploy', title: 'Hobby preview' },diff --git a/rust/replay-anonymizer/README.md b/rust/replay-anonymizer/README.mdindex 8a1ef31fb0d5..4f9173e3a9d6 100644--- a/rust/replay-anonymizer/README.md+++ b/rust/replay-anonymizer/README.md@@ -13,9 +13,6 @@ Offline consumers (JSONL of individual events rather than Kafka messages) get a## Releasing-Publishing to crates.io is automated by `.github/workflows/publish-replay-anonymizer-crate.yml`:+Publishing to crates.io is automated by `.github/workflows/publish-replay-anonymizer-crate.yml`: bump `version` in `Cargo.toml` in your PR, and on merge to master the workflow publishes any version not yet on crates.io via trusted publishing (GitHub OIDC, no long-lived token). No tags involved.-1. Bump `version` in `Cargo.toml` and merge to master.-2. Tag the merged commit `posthog-replay-anonymizer/v<version>` and push the tag.--The workflow verifies the tag matches the crate version and publishes via crates.io trusted publishing (GitHub OIDC, no long-lived token).+If crate code changes in a PR without a version bump, CI posts a reminder comment on the PR. If un-bumped crate changes still reach master (say the version got taken by a PR that merged first), the publish run fails loudly instead of silently skipping; bump the version in a follow-up PR.