: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
feat(cli): publish posthog-cli to crates.io (#105728)
Hugues Pouillot7cad632cafe5
diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.ymlindex 94cc381c28f5..b53c3f908282 100644--- a/.github/workflows/release-cli.yml+++ b/.github/workflows/release-cli.yml@@ -1193,12 +1193,75 @@ jobs:env:GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}+ publish-cargo:+ needs:+ - release+ - plan-release+ - host-release+ runs-on: 'ubuntu-22.04'+ timeout-minutes: 15+ # Same gate as publish-npm. crates.io understands prerelease semver and+ # `cargo install` will not pick one by default, so the Homebrew+ # stable-only rule does not apply here.+ if: ${{ needs.plan-release.result == 'success' && (!fromJson(needs.plan-release.outputs.val).announcement_is_prerelease || fromJson(needs.plan-release.outputs.val).publish_prereleases) }}+ permissions:+ contents: read+ # Exchanged for a short-lived crates.io token by the auth action, so+ # there is no CARGO_REGISTRY_TOKEN secret to hold or rotate.+ id-token: write+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ ref: ${{ needs.release.outputs.release-commit }}+ - name: Install rust+ uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9+ with:+ toolchain: 1.91.1+ - name: Fetch release artifacts+ uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0+ with:+ pattern: artifacts-*+ path: artifacts/+ merge-multiple: true+ # Taken from the npm package rather than rebuilt from services/mcp, so+ # the crate ships the same bytes every other channel does. A rebuild+ # could drift.+ #+ # This path is not incidental: package/lib/posthog-api-cli.mjs is what+ # `npm i -g @posthog/cli` installs and runs, so it cannot go missing+ # without breaking npm first. If it ever does, tar exits non-zero here+ # and the crate is not published, which is the outcome we want.+ - name: Take the API bundle from the npm package+ run: |+ set -euo pipefail+ tar -xzf artifacts/posthog-cli-npm-package.tar.gz \+ -C "$RUNNER_TEMP" package/lib/posthog-api-cli.mjs+ cp "$RUNNER_TEMP/package/lib/posthog-api-cli.mjs" cli/lib/posthog-api-cli.mjs+ # build.rs treats a missing bundle as None and still compiles, so+ # without this check a broken extraction would publish a crate whose+ # `posthog-cli api` is dead, and nothing would fail.+ - name: Verify the bundle is present+ run: |+ set -euo pipefail+ test -s cli/lib/posthog-api-cli.mjs+ echo "bundle: $(wc -c < cli/lib/posthog-api-cli.mjs) bytes"+ - name: Authenticate with crates.io+ id: auth+ uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1.0.5+ - name: Publish to crates.io+ working-directory: cli+ env:+ CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}+ # --allow-dirty because lib/posthog-api-cli.mjs is gitignored, so it+ # is always an untracked file in the checkout.+ run: cargo publish -p posthog-cli --allow-dirty+notify-released:name: Notify Slack - Release Published- needs: [notify-approval-needed, release, host-release, publish-npm, publish-homebrew]+ needs: [notify-approval-needed, release, host-release, publish-npm, publish-homebrew, publish-cargo]runs-on: ubuntu-24.04timeout-minutes: 5- if: always() && needs.host-release.result == 'success' && (needs.publish-npm.result == 'success' || needs.publish-npm.result == 'skipped') && (needs.publish-homebrew.result == 'success' || needs.publish-homebrew.result == 'skipped') && needs.notify-approval-needed.outputs.slack_ts != ''+ if: always() && needs.host-release.result == 'success' && (needs.publish-npm.result == 'success' || needs.publish-npm.result == 'skipped') && (needs.publish-homebrew.result == 'success' || needs.publish-homebrew.result == 'skipped') && (needs.publish-cargo.result == 'success' || needs.publish-cargo.result == 'skipped') && needs.notify-approval-needed.outputs.slack_ts != ''steps:- name: Notify Slack - Release Publisheduses: posthog/.github/.github/actions/slack-thread-reply@03565438486849ac0d19543de36c248a27d32a2f@@ -1223,12 +1286,13 @@ jobs:- host-release- publish-npm- publish-homebrew+ - publish-cargoruns-on: ubuntu-24.04timeout-minutes: 5if: >-always() && (needs.plan-release.result == 'failure' || needs.build-local-artifacts.result == 'failure'|| needs.build-global-artifacts.result == 'failure' || needs.host-release.result == 'failure'- || needs.publish-npm.result == 'failure' || needs.publish-homebrew.result == 'failure')+ || needs.publish-npm.result == 'failure' || needs.publish-homebrew.result == 'failure' || needs.publish-cargo.result == 'failure')steps:- name: Collect failed jobsid: failure-metadatadiff --git a/cli/Cargo.toml b/cli/Cargo.tomlindex 9970f728215b..689082b208ba 100644--- a/cli/Cargo.toml+++ b/cli/Cargo.toml@@ -16,6 +16,16 @@ license = "MIT"edition = "2021"repository = "https://github.com/PostHog/posthog"readme = "README.md"+# An explicit include replaces cargo's "every tracked file" default, so every+# path the build needs has to be listed. lib/posthog-api-cli.mjs is gitignored+# and written by the release workflow, which is why it is named here and why+# publishing uses --allow-dirty.+include = [+ "src/**/*",+ "build.rs",+ "lib/posthog-api-cli.mjs",+ "README.md",+][[bin]]name = "posthog-cli"