Skip to content

feat(gradle-plugin): run hog instead of posthog-cli - #1015

Merged
rafaeelaudibert merged 7 commits into
mainfrom
rafa/gradle-plugin-on-hog
Dec 1, 2026
Merged

rafaeelaudibert merged 7 commits into
mainfrom
rafa/gradle-plugin-on-hog

Conversation

@rafaeelaudibert

@rafaeelaudibert rafaeelaudibert commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

💡 Motivation and Context

  • Android builds upload ProGuard mappings and native symbols with posthog-cli, which hog replaces.
  • hog uploads the same bytes, content hashes and releases (migration guide).

Changes

  • The upload tasks run hog when it is installed, and fall back to posthog-cli with its old commands otherwise.
  • hog wins when both are installed. The search covers PATH, the hog install locations and node_modules/.bin.
  • The commands become hog error-tracking upload <path> --kind proguard|elf, with the same map ID, release and conflict flags, plus -o text.
  • postHogHost, postHogProjectId, postHogApiKey and posthog.dotenvFile reach hog as HOG_* variables.
  • Without a configured key, hog gets no HOG_PERSONAL_API_KEY, so OIDC and hog auth login keep working.
  • Without a key, a us.i.posthog.com or eu.i.posthog.com host becomes the matching app host, where those logins live.
  • When hog exits 3 for a missing login, the build failure points at hog auth migrate, which imports a posthog-cli login.
  • Each POSTHOG_CLI_* variable in the environment or dotenv file reaches hog under its HOG_* name, unless that name is set. The task warns once per build to rename it.
  • Explicit postHogHost, postHogProjectId and postHogApiKey settings still win over every variable.
  • When hog gets a personal API key in GitHub Actions, GitLab.com or Depot CI, the task suggests hog ci setup and the job's OIDC token, once per build.
  • The posthog-cli deprecation warning prints once per build. In GitHub Actions it also points at the PostHog/setup-hog action.
  • postHogExecutable = 'posthog-cli' keeps posthog-cli. A configured path runs as hog only when the file is named hog.

💚 How did you test it?

  • Unit tests cover the CLI search order and the HOG_* variables.
  • Unit tests pin the variable mapping and its warning, no mapping when the HOG_* name is set, the OIDC hint per CI, no hint without a key or outside those CIs, and the setup-hog sentence only in GitHub Actions.
  • Unit tests pin the credential source choice, hog's dotenv parsing, and the ingestion host mapping.
  • Functional tests run both tasks on AGP 8.0.2 and 8.9.1 with a fake hog and a fake posthog-cli, checking the arguments and that no key variable is set.
  • A functional test passes POSTHOG_CLI_API_KEY in GitHub Actions and checks that hog gets HOG_PERSONAL_API_KEY and each warning prints once across both tasks.
  • Functional tests check the deprecation prints once per build, and that a hog exit 3 fails the build with the hog auth migrate pointer.
  • hog@1.0.0 error-tracking upload mapping.txt --kind proguard --map-id <id> --release-name com.posthog.test --release-version 1.0 --build 1 --dry-run -o text planned one symbol set on release com.posthog.test@1.0+1.
  • Not run: a real upload, and Windows.

📝 Checklist

  • All commits are signed (see Commit signing)
  • 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

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Written by Claude Code (Claude Opus 5.5, claude-opus-5-5) while the driver was away. Not yet checked by the driver.
  • Skills: writing-pr-descriptions.
Decisions
  • --kind elf and --kind proguard stop hog from treating another file in the folder as a different artifact type, as posthog-cli's dedicated commands never did.
  • -o text keeps the build log readable. hog prints JSON when stdout is a pipe, which it is under Gradle. Nothing parses the output.
  • Inherited POSTHOG_CLI_* variables map to HOG_* so existing builds keep uploading. A legacy key now beats OIDC, and the OIDC hint asks to remove it.
  • Credentials (key, project ID, host) map as one set from the source posthog-cli and hog pick: the environment when it has a key and a project ID, otherwise the dotenv file.
  • When the file wins, its set replaces inherited values. Task settings and an inherited HOG_HOST stay.
  • The dotenv parser matches hog's, so export KEY= lines are not credentials. An unreadable or unparseable file leaves the check to hog.
  • With a key, the configured host stays as is, so egress allowlists still hold.
  • Where two legacy names map to one, such as POSTHOG_CLI_API_KEY and POSTHOG_CLI_TOKEN, the first one set wins, as in posthog-cli.
  • The OIDC check matches hog's: DEPOT_JOB_URL first, then GITHUB_ACTIONS=true, then GITLAB_CI=true with CI_SERVER_URL=https://gitlab.com. A key in the dotenv file also counts.
  • A build service dedupes the mapping warnings and the OIDC hint, so each prints once per build across both upload tasks.
  • The plugin does not check hog's version.
  • With no CLI found, the task runs a bare hog and warns with hog's install commands.
  • getHogArguments is a new abstract method on PostHogCliExecTask. The class is documented as internal to the plugin.
  • The changeset replaces a hand-written CHANGELOG entry, as AGENTS.md asks.
  • The posthog.com Android docs still say to install posthog-cli, and need a follow-up.

🤖 Generated with Claude Code

The ProGuard mapping and native symbol uploads run hog when it is
installed and fall back to posthog-cli with its old commands otherwise.
hog gets HOG_* variables, and no HOG_PERSONAL_API_KEY without a
configured key, so OIDC and hog auth login keep working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rafaeelaudibert rafaeelaudibert self-assigned this Nov 30, 2026
rafaeelaudibert and others added 4 commits November 30, 2026 18:22
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each POSTHOG_CLI_ variable in the environment or the dotenv file reaches
hog under its HOG_ name when that name is unset, with a warning to rename
it. Explicit plugin settings still win.

When hog gets a personal API key in GitHub Actions, GitLab.com or Depot
CI, the upload tasks suggest hog ci setup and the job's OIDC token. Both
warnings print once per build. In GitHub Actions, the posthog-cli
deprecation warning also points at the PostHog/setup-hog action.

The guide links point at https://posthog.com/docs/cli/migrating

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e react native scripts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rafaeelaudibert
rafaeelaudibert marked this pull request as ready for review December 1, 2026 14:10
@rafaeelaudibert
rafaeelaudibert requested a review from a team as a code owner December 1, 2026 14:10
@veria-ai

veria-ai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed ec8d56d: 1 Must fix, 2 Should fix.

New pushes to this pull request won't start an automatic review. Comment @posthog review to review new changes.

hog and posthog-cli take the key, project ID and host from one source.
A HOG_ key in the dotenv file now keeps the environment's posthog-cli
credentials unmapped, and the file's credentials reach hog together,
host included, only when the file has a key and the environment has
none. An unreadable dotenv file no longer fails the upload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI-assisted review.

Running hog and its arguments, the HOG_* variables, the OIDC hint and the once-per-build legacy-variable warnings check out against hog's source. Configuration-cache reuse and PATH discovery with postHogExecutable unset also passed in local TestKit runs on AGP 8.0.2 and 8.9.1.

One concern, inline: a partial POSTHOG_CLI_* credential set in the environment now overrides a complete set in the dotenv file. Depending on which variable is left over, the release build fails with hog exit 3, or the file's key uploads to the environment's project. The other inline comments are optional.

Follow-up outside this repo: the posthog.com docs still describe posthog-cli for Android (contents/docs/error-tracking/upload-mappings/android.mdx, upload-source-maps/react-native.mdx:252), and the build-plugins table in contents/docs/cli/migrating.mdx doesn't list com.posthog.android or its first hog version.

val dotenv = readHogDotenvFile(environment + variables, workingDirectory)
val apiKey = PostHogCli.HOG.apiKeyVariable

if (isSet(apiKey) || dotenv[apiKey].isNullOrBlank()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Concern: A partial set of POSTHOG_CLI_* credentials in the environment now beats a complete set in the dotenv file

mapLegacyHogVariables chooses between the environment and the dotenv file by whether the environment has a key (lines 102-123). posthog-cli uses the environment only when it has a key and a project, and otherwise takes the file's key, project and host together (try_source, auth.rs:73-100). hog does the same with its own names (credentials.ts:46-57, 196-213).

Setup: posthog.dotenvFile=.env, hog installed, and this .env:

POSTHOG_CLI_API_KEY=phx_file_key
POSTHOG_CLI_PROJECT_ID=12345

The Gradle daemon still has one variable exported from before the dotenv option (CHANGELOG.md:60 says "Process env still wins inside the CLI"):

Inherited Before (posthog-cli) With hog
POSTHOG_CLI_API_KEY=phx_env_key the file's key and project hog gets HOG_PERSONAL_API_KEY=phx_env_key and no project. The file has no HOG_ names, so hog stops with not_authenticated (exit 3) and the release build fails
POSTHOG_CLI_PROJECT_ID=999 the file's key and project 12345 the file's key uploads to project 999

The changeset says these variables "keep working". The KDoc at lines 70-73 says both CLIs read "the environment when it has a key", but both need a key and a project. The mapping also doesn't match what hog would do after the rename the migration guide asks for: with HOG_PROJECT_ID=999 in the env and HOG_ key+project in the file, hog uses 12345. The siblings keep the file as one source. posthog-ios#1134 translates the dotenv into a copy and lets hog pick, which handles both rows. posthog-js#5961 moves the file's set over an env HOG_PROJECT_ID.

This is a new trigger next to the resolved thread. That fix covers an environment with no key, not one with only part of a set. The second case of leaves the dotenv file to hog when hog would not take a key from it assumes the same thing: with a key and no project in the environment, hog does read the file.

Limits: this needs a posthog-cli-named dotenv file, a partial inherited set, and hog. The second row only misroutes when the IDs differ and the key can reach both projects. (An inherited POSTHOG_CLI_HOST alone also differs from posthog-cli, but it matches hog's own HOG_HOST override and iOS, so I'm not counting it.)

Consider choosing the source the way posthog-cli does: map the environment's posthog-cli credentials only when the environment, task settings included, ends up with both a key and a project. Otherwise, when the file has a key and a project, map the file's key, project and host together. iOS's translated copy is the other option. Updating the KDoc and that test case would go with it. Regression tests, in PostHogCliEnvironmentTest:

@Test
fun `an environment key without a project leaves hog the dotenv file's complete set`() {
    val file = temporaryFolder.newFile(".env")
    file.writeText("POSTHOG_CLI_API_KEY=phx_file_key\nPOSTHOG_CLI_PROJECT_ID=$projectId\n")
    val environment = mapOf("POSTHOG_CLI_API_KEY" to "phx_env_key", "HOG_DOTENV_FILE" to file.path)

    val legacy = mapLegacyHogVariables(environment, temporaryFolder.root)

    assertEquals(mapOf("HOG_PERSONAL_API_KEY" to "phx_file_key", "HOG_PROJECT_ID" to projectId), legacy.variables)
}

@Test
fun `an inherited project ID does not pair with the dotenv file's key`() {
    val file = temporaryFolder.newFile(".env")
    file.writeText("POSTHOG_CLI_API_KEY=$apiKey\nPOSTHOG_CLI_PROJECT_ID=$projectId\n")
    val environment = mapOf("POSTHOG_CLI_PROJECT_ID" to "999", "HOG_DOTENV_FILE" to file.path)

    val legacy = mapLegacyHogVariables(environment, temporaryFolder.root)

    assertEquals(apiKey, legacy.variables["HOG_PERSONAL_API_KEY"])
    assertEquals(projectId, legacy.variables["HOG_PROJECT_ID"])
}

At 4e18d0a both fail: the first got {HOG_PERSONAL_API_KEY=phx_env_key}, the second got project 999. A control with a complete environment set passes. A TestKit version through :app:uploadPostHogProguardMappingsRelease (with posthog.dotenvFile=.env and inherited POSTHOG_CLI_API_KEY) also fails on AGP 8.0.2 and 8.9.1: the fake hog received HOG_DOTENV_FILE and HOG_PERSONAL_API_KEY=phx_env_key, with no HOG_PROJECT_ID. The base comparison comes from posthog-cli's source, since these functions don't exist on base.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 Fixed in 2394cb5: the environment's credentials map only when it ends up with a key and a project ID, task settings included. Otherwise the dotenv file's key, project ID and host move together over inherited values, and both of your tests are in. Following posthog-cli also reverses an earlier bot-review choice: a complete posthog-cli set in the environment now beats a HOG_ set in the file again, as it did with posthog-cli.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: A task's postHogApiKey now goes to the dotenv file's host

Thanks, both rows from this thread are fixed and the tests are in. I checked them, and the regression tests from my last run pass at 2394cb5. One case is left, from the task-settings side. When the task sets a key but no project, and the posthog-cli dotenv file has its own key, project and host, hog gets the task's key with the file's project and host.

Setup: hog is installed, the environment has no POSTHOG_CLI_* or HOG_* credentials, -Pposthog.dotenvFile=posthog.env, and:

tasks.withType(com.posthog.android.PostHogCliExecTask).configureEach {
    postHogApiKey = 'phx_task_key'
}
POSTHOG_CLI_API_KEY=phx_file_key
POSTHOG_CLI_PROJECT_ID=12345
POSTHOG_CLI_HOST=https://posthog.example.com
Key Project Host
Base (posthog-cli) file file file
4e18d0a (hog) task none, so not_authenticated unless posthog.json has one —
2394cb5 (hog) task file file
hog, once the file is renamed to HOG_ names file file file

In the file branch, settings only skip their own names (HogEnvironment.kt:119-127), so the file's host moves next to the task's key. Neither CLI builds that pair:

  • hog: "The host only counts when it comes from the same source as the key, so a stray host cannot redirect a key from somewhere else" (credentials.ts:43-57, 196-214).
  • posthog-cli: tests that an environment key without a project never reaches the dotenv file's host (auth.rs:312-333).
  • The React Native plugin says the same: "a key never goes to a host from another source" (posthog-js#5961 posthog.gradle:475-482).

The changeset ("As in posthog-cli, … otherwise from the dotenv file") and the KDoc also don't quite hold with task settings.

Limits:

  • It needs a key in the build and a key-bearing posthog-cli dotenv file with a host, without postHogProjectId. The Android docs set all three settings together, and then nothing mixes.
  • The build script and the file usually belong to the same owner, so I'm not treating it as a security issue. The worst case is a failed upload, with the task key shown to another host the owner configured.
  • If the key belongs to that host, the upload now works where 4e18d0a failed outright.
  • I'm not counting the task-project row (test :175-186). It follows your "settings win" rule, and hog lets a project come from elsewhere because it "only picks a project the key can already reach".

Consider moving the file's host only together with the file's key. That keeps "settings win" and the same-source host rule, and the task key then goes to postHogHost or hog's default host:

val keptHost = current == PostHogCli.HOG.hostVariable &&
    (!environment[current].isNullOrBlank() || !settings[apiKey].isNullOrBlank())

The other option is letting the file's whole set win, as both CLIs do. Either way, a clause in the changeset such as "task settings still win over both" would make it accurate.

Regression test for PostHogCliEnvironmentTest:

@Test
fun `a task key does not go to the dotenv file's host`() {
    val file = temporaryFolder.newFile("t1.env")
    file.writeText(
        "POSTHOG_CLI_API_KEY=phx_file_key\nPOSTHOG_CLI_PROJECT_ID=$projectId\nPOSTHOG_CLI_HOST=https://posthog.example.com\n",
    )
    val settings = postHogCliEnvironment(PostHogCli.HOG, null, null, "phx_task_key", file.path)

    val legacy = mapLegacyHogVariables(emptyMap(), temporaryFolder.root, settings)
    val hogEnvironment = settings + legacy.variables

    val taskKeyGoesToFileHost =
        hogEnvironment["HOG_PERSONAL_API_KEY"] == "phx_task_key" &&
            hogEnvironment["HOG_HOST"] == "https://posthog.example.com"
    assertFalse(taskKeyGoesToFileHost, "got: $hogEnvironment")
}

What I saw when I ran it:

  • At 2394cb5 it fails with {HOG_PERSONAL_API_KEY=phx_task_key, HOG_DOTENV_FILE=…, HOG_PROJECT_ID=12345, HOG_HOST=https://posthog.example.com}.
  • At 4e18d0a, adapted to the old signature, it passes.
  • A TestKit version through :app:uploadPostHogProguardMappingsRelease (the snippet above, plus -Pposthog.dotenvFile) fails on AGP 8.0.2 and 8.9.1. The fake hog received HOG_HOST=https://posthog.example.com, HOG_PERSONAL_API_KEY=phx_task_key and HOG_PROJECT_ID=12345.
  • The base comparison comes from posthog-cli's source, because this function doesn't exist on base. I haven't run it against a fix.

): Map<String, String> {
fun configured(value: String?): String? = if (cli == PostHogCli.HOG) value?.takeIf { it.isNotBlank() } else value
return buildMap {
configured(host)?.let { put(cli.hostVariable, it) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: Should postHogHost (or POSTHOG_CLI_HOST) set to a Cloud ingestion host such as https://us.i.posthog.com become the app host when hog runs without a key? hog uses HOG_HOST for every credential source (globals.ts:27-33) and doesn't map ingestion hosts to app hosts (host.ts:51-79). A hog auth login saved for us.posthog.com then stops with host_mismatch (credentials.ts:247-258), and the OIDC exchange goes to the ingestion host (credentials.ts:300-303). posthog-js#5960 maps these for keyless runs (toHogHost in plugin-utils/src/env.ts). With a key nothing changes, so this isn't a regression. It matters once someone follows the plugin's OIDC hint and removes the key. I haven't verified whether the exchange answers on the ingestion host. Either mapping the host or documenting that postHogHost must be the app host would settle it. Non-blocking.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 Yes, in 2394cb5. Without a key, https://us.i.posthog.com and https://eu.i.posthog.com become https://us.posthog.com and https://eu.posthog.com, because OIDC and saved logins live on the app host. With a key the configured host stays as is, so egress allowlists hold. This matches toHogHost in posthog-js#5960, and other hosts never change.

}
}

super.exec()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: When hog exits 3, consider pointing at hog auth migrate, and mention it in the changeset.

Setup: a machine logged in with posthog-cli login (the auth step the Android upload docs give), no POSTHOG_CLI_* variables or dotenv file, postHogExecutable unset, and hog installed, for example by a teammate adding hog to package.json. After the upgrade, a minified release build runs hog. hog doesn't read posthog-cli's ~/.posthog/credentials.json (paths.ts:80), so the upload stops with not_authenticated, exit 3. Because the task finalizes minify, assembleRelease fails. Before, posthog-cli fell back to that file (auth.rs:164-194). hog's message says "Run hog auth login, or set HOG_PERSONAL_API_KEY" (credentials.ts:315-320), so people can recover. But the migration guide's step is hog auth migrate, which keeps the existing login (posthog.com contents/docs/cli/migrating.mdx, "Log in on the machine").

Preferring hog makes sense and matches the other plugins. posthog-ios#1134 also adds the pointer when hog exits 3 (upload-symbols.sh:546-551). Consider:

  • After hog exits 3, logging once, before the task fails: "To log in, run hog auth migrate when posthog-cli is logged in on this machine, or hog auth login." For example, run with isIgnoreExitValue = true, then check executionResult and rethrow.
  • Adding to the changeset: "If this machine logged in with posthog-cli login, run hog auth migrate, or set postHogExecutable = "posthog-cli"."

I ran this TestKit test with a fake hog that prints to stderr and exits 3:

@Test
fun `a hog run that needs a login points at hog auth migrate`() {
    setUpProject(uploadNativeSymbols = false, minifyEnabled = true)
    File(projectDir.root, "fake-bin/$HOG").apply {
        writeText("#!/bin/sh\necho \"hog couldn't find PostHog credentials.\" >&2\nexit 3\n")
        setExecutable(true)
    }

    val result = runner(":app:uploadPostHogProguardMappingsRelease").buildAndFail()

    assertTrue(result.output.contains("hog auth migrate"), result.output)
}

At 4e18d0a it fails on AGP 8.0.2 and 8.9.1: the task fails with exit value 3, and the output never mentions hog auth migrate.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 Done in 2394cb5: when hog exits 3, the build fails with "To log in, run hog auth migrate when posthog-cli is logged in on this machine, or hog auth login." The changeset mentions hog auth migrate and the postHogExecutable = "posthog-cli" fallback, and your TestKit test is in.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: The exit-3 hint only mentions logging in, but in CI hog also exits 3 for OIDC policy, scope and keychain problems

A follow-up on the wording I suggested here. hog exits 3 for 13 error codes, not only not_authenticated (errors.ts:49-65). They include workload_no_matching_policy, workload_policy_request_pending, not_in_ci, scopes_not_granted, session_expired and keychain_access_*. In CI, hog's own hint for a missing login points at hog ci setup or HOG_PERSONAL_API_KEY (credentials.ts:315-326). The task adds the same login line to every exit 3 (PostHogCliExecTask.kt:151-152, 167-168).

Setup: GitHub Actions, hog installed, no key, and a job that hog ci setup's policy doesn't match, so hog exits 3.

What happens: hog prints its reason ("No policy matches this job." in my fake), and then the build fails with "[PostHog] hog finished with exit value 3. To log in, run hog auth migrate when posthog-cli is logged in on this machine, or hog auth login." Neither command helps in CI. posthog-ios#1134 defers to hog and adds the CI path: "hog needs you to act before it can upload, as its message above says. … In CI, set HOG_PERSONAL_API_KEY and HOG_PROJECT_ID." (upload-symbols.sh:610-612).

Limits: hog's own message and hint still print above, so the cause is visible. Only the plugin's last line points the wrong way. Local builds and exit codes other than 3 are unaffected.

Consider wording like: "[PostHog] hog needs a person to act before it can upload, as its message above says. To log in, run hog auth migrate when posthog-cli is logged in on this machine, or hog auth login. In CI, run hog ci setup --scope error_tracking:write once in the repository, or set HOG_PERSONAL_API_KEY and HOG_PROJECT_ID." hog ci setup matches the plugin's own OIDC hint (HogEnvironment.kt:176).

TestKit test for NativeSymbolsUploadFunctionalTest:

@Test
fun `a hog run that needs a person in CI points at CI setup, not only a login`() {
    setUpProject(uploadNativeSymbols = false, minifyEnabled = true)
    File(projectDir.root, "fake-bin/$HOG").apply {
        writeText("#!/bin/sh\necho \"No policy matches this job.\" >&2\nexit 3\n")
        setExecutable(true)
    }
    val inheritedEnvironment =
        System.getenv().filterKeys { name ->
            !name.startsWith("HOG_") && !name.startsWith("POSTHOG_") && name !in setOf("DEPOT_JOB_URL", "GITLAB_CI")
        }

    val result =
        runner(":app:uploadPostHogProguardMappingsRelease")
            .withEnvironment(inheritedEnvironment + mapOf("GITHUB_ACTIONS" to "true"))
            .buildAndFail()

    assertTrue(result.output.contains("hog ci setup"), result.output)
}

At 2394cb5 it fails on AGP 8.0.2 and 8.9.1. The output contains hog's stderr and the login-only hint, with no hog ci setup. If you pick other CI wording, match the assertion to it.

A control I ran passes on both legs, and might be worth keeping as a test: a hog exit of 1 keeps Gradle's "finished with non-zero exit value 1" without the hint, and ignoreExitValue = true with exit 3 succeeds without it.

"repository, then remove the key. Migration guide: $HOG_MIGRATION_GUIDE"
}

private val DOTENV_ENTRY = Regex("""^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$""")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: DOTENV_ENTRY accepts export KEY=value, but hog's parseDotenv and posthog-cli's load_dotenv both read export HOG_PERSONAL_API_KEY as the key name. Take a file with export HOG_PERSONAL_API_KEY=… and export HOG_PROJECT_ID=…, plus POSTHOG_CLI_API_KEY and POSTHOG_CLI_PROJECT_ID in the environment. The plugin sees a HOG_ key in the file and leaves the environment's set unmapped. hog then finds no key in either place and exits 3, where posthog-cli used the environment's set. Consider matching hog's parser, so the KDoc's "as hog reads them" holds. The export POSTHOG_CLI_API_KEY fixture in moves the dotenv file's credentials to hog as one set would change with it. I ran this test at 4e18d0a, and it fails (legacy.variables is {}):

@Test
fun `an exported HOG_ key that hog cannot read does not hide the environment's credentials`() {
    val file = temporaryFolder.newFile(".env")
    file.writeText("export HOG_PERSONAL_API_KEY=phx_file_key\nexport HOG_PROJECT_ID=1\n")
    val environment =
        mapOf("POSTHOG_CLI_API_KEY" to apiKey, "POSTHOG_CLI_PROJECT_ID" to projectId, "HOG_DOTENV_FILE" to file.path)

    val legacy = mapLegacyHogVariables(environment, temporaryFolder.root)

    assertEquals(mapOf("HOG_PERSONAL_API_KEY" to apiKey, "HOG_PROJECT_ID" to projectId), legacy.variables)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 Fixed in 2394cb5: the parser now matches hog's parseDotenv, so export HOG_PERSONAL_API_KEY is a different key name. A line hog can't parse makes the plugin leave the file to hog. Your test is in, plus one showing that exported posthog-cli names stay unread.

args.addAll(listOf("-o", "text"))
}
PostHogCli.POSTHOG_CLI -> {
logger.warn(postHogCliDeprecationWarning(taskEnvironment))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: This warning bypasses the build service that dedupes the other warnings, so a build that runs both uploads prints "posthog-cli is deprecated" twice, and more with several variants or modules. Consider buildWarnings.get().warnOnce(logger, postHogCliDeprecationWarning(taskEnvironment)), so it matches the once-per-build legacy-variable warnings and OIDC hint (and the SDK guidelines' "Deprecate before removing" advice to keep deprecation warnings useful, not noisy). I ran this TestKit test at 4e18d0a, and it fails on AGP 8.0.2 and 8.9.1 (count 2):

@Test
fun `the posthog-cli deprecation prints once per build`() {
    setUpProject(uploadNativeSymbols = false, minifyEnabled = true, cliName = POSTHOG_CLI)

    val result = runner(":app:uploadPostHogNativeSymbolsRelease", ":app:uploadPostHogProguardMappingsRelease").build()

    assertEquals(1, result.output.split("[PostHog] posthog-cli is deprecated").size - 1, result.output)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 Done in 2394cb5: the deprecation warning now goes through warnOnce, and your TestKit test is in.

@dustinbyrne
dustinbyrne requested a review from a team December 1, 2026 16:46
- Use the environment's credentials only when it has a key and a
  project ID, otherwise the dotenv file's key, project ID and host.
- Parse the dotenv file exactly as hog does, so `export KEY=` lines
  are not credentials.
- Map a Cloud ingestion host to its app host when hog runs without a
  key, as the posthog-js plugins do.
- Point a hog run that exits 3 at `hog auth migrate`.
- Print the posthog-cli deprecation once per build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI-assisted review.

Thanks for the quick turnaround. At 2394cb5, F1–F5 are resolved. I re-ran the regression tests from my last review, and the seven that failed at 4e18d0a now pass, the TestKit ones on both AGP 8.0.2 and 8.9.1. The plugin's own suite (37 unit, 38 functional) passes too. Going back to posthog-cli's order for a complete environment set, which reverses the earlier bot thread, matches both CLIs.

Two small follow-ons, both optional, are in replies on the F1 thread (a task key without a project picks up the dotenv file's host) and the F3 thread (the exit-3 hint in CI). The posthog.com Android upload page still covers only posthog-cli. That's a docs follow-up, not a blocker here.

"POSTHOG_CLI_DOTENV_FILE" to "HOG_DOTENV_FILE",
"POSTHOG_CLI_DRY_RUN" to "HOG_DRY_RUN",
"POSTHOG_CLIENT_RATE_LIMIT" to "HOG_RATE_LIMIT",
"POSTHOG_HOME" to "HOG_HOME",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

POSTHOG_* (maybe not POSTHOG_CLI_*) does seem like a somewhat informal standard we've been using for env var prefixes, though i can understand the reasoning here - just a consideration

@rafaeelaudibert
rafaeelaudibert merged commit 8de0b95 into main Dec 1, 2026
18 checks passed
@rafaeelaudibert
rafaeelaudibert deleted the rafa/gradle-plugin-on-hog branch December 1, 2026 22:53
rafaeelaudibert added a commit that referenced this pull request Dec 2, 2026
Resolve the conflicts in the Gradle plugin's CLI code with the hog resolver
and environment handling from #1015. The posthog-cli specific Windows .exe
lookup from this branch is dropped, because #1015's PATHEXT lookup replaces
it. The cmd safety check stays and now applies to any CLI that runs through
cmd, such as the npm hog.cmd launcher. The exec task splits into a resolve
step and a run step, so the JVM upload can check the CLI before it runs it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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