Skip to content

Configurable executable and env for CLI task#485

Merged
marandaneto merged 4 commits intoPostHog:mainfrom
brettwillis:main
Apr 13, 2026
Merged

Configurable executable and env for CLI task#485
marandaneto merged 4 commits intoPostHog:mainfrom
brettwillis:main

Conversation

@brettwillis
Copy link
Copy Markdown
Contributor

@brettwillis brettwillis commented Apr 12, 2026

I've been trialling migrating to PostHog from Crashlytics, and I've hit that TODO in the plugin implementation where the CLI install location is not configurable, so I thought I'd help out if that's amenable?

💡 Motivation and Context

The upload mappings task relies on the machine having a globally installed posthog-cli that is already authenticated. This PR adds input variables to the PostHogCliExecTask for

  • postHogExecutable (defaults to "posthog-cli" as per existing global install behaviour)
  • postHogHost (optional, sets POSTHOG_CLI_HOST env variable)
  • postHogProjectId (optional, sets POSTHOG_CLI_PROJECT_ID env variable)
  • postHogApiKey (optional, sets POSTHOG_CLI_API_KEY env variable)

Furthermore, all tasks are made public so that the inputs can be configured in the end project. Note: this exposes your task hierarchy as a de-facto public API, but otherwise it's impossible to actually set those input variables in the end project.

In this way, the PostHog CLI can be entirely standalone without relying on global machine state.

💚 How did you test it?

I ran :posthog-android-gradle-plugin:build.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the "release" label to the PR to indicate we're publishing new versions for the affected packages

Make tasks public so inputs/outputs can be configured in the end project
@brettwillis brettwillis requested a review from a team as a code owner April 12, 2026 22:06
@marandaneto
Copy link
Copy Markdown
Member

thanks @brettwillis thats great

id("com.posthog.android") // <- add this plugin
}

// Optional configuration
Copy link
Copy Markdown
Member

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 amend this section of the docs as well https://posthog.com/docs/error-tracking/upload-mappings/android#inject-and-upload

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

// Optional configuration
tasks.withType<PostHogCliExecTask> {
// Custom CLI location
// defaults to globally installed posthog-cli on the PATH
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you can just export the env variables as well
https://posthog.com/docs/error-tracking/upload-mappings/android#authenticate
you dont need to manually do posthog-cli login

@marandaneto
Copy link
Copy Markdown
Member

@marandaneto
Copy link
Copy Markdown
Member

Execution failed for task ':spotlessKotlinCheck'.
The following files had format violations:

@brettwillis you jsut need to run make format

Copy link
Copy Markdown
Member

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

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

left a few comments otherwise LGTM

@brettwillis brettwillis changed the title Configurable executable and env for CLI tasl Configurable executable and env for CLI task Apr 13, 2026
@marandaneto marandaneto merged commit 1144733 into PostHog:main Apr 13, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants