Skip to content

[build-tools] Add eas/posthog_flag_rollout workflow function#3944

Open
gwdp wants to merge 1 commit into
gwdp/eng-21551-posthog-capture-eventfrom
gwdp/eng-21551-posthog-flag-rollout
Open

[build-tools] Add eas/posthog_flag_rollout workflow function#3944
gwdp wants to merge 1 commit into
gwdp/eng-21551-posthog-capture-eventfrom
gwdp/eng-21551-posthog-flag-rollout

Conversation

@gwdp

@gwdp gwdp commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Why

Manage a PostHog feature flag straight from an EAS workflow. Flip it on or ramp its rollout as part of a deploy, instead of doing it by hand in PostHog.

How

Adds eas/posthog_flag_rollout. It uses the personal API key from integrations:posthog:connect (POSTHOG_CLI_API_KEY/POSTHOG_CLI_PROJECT_ID), or the api_key/project_id inputs. There's no host input on purpose, so the personal key only ever goes to POSTHOG_CLI_HOST.

The rollout_percentage input updates the flag's catch-all release condition and leaves targeted groups alone. Failures fail the step. Set ignore_error: true to log a warning and continue instead. Bad inputs, unknown flags and 403 scope errors always fail. Lookup and update aren't atomic, so a parallel dashboard edit can be lost.

Test Plan

CI passes. Enabled a real flag from a local run with this workflow. It needs a personal key with feature-flag scopes. The last job fails the lookup on purpose and just warns.

Test workflow
name: PostHog flag rollout test

jobs:
  enable_flag:
    steps:
      - uses: eas/posthog_flag_rollout
        with:
          flag: eas-workflow-test-flag
          active: true

  gradual_rollout:
    steps:
      - uses: eas/posthog_flag_rollout
        with:
          flag: eas-workflow-test-flag
          rollout_percentage: 50

  set_payload:
    steps:
      - uses: eas/posthog_flag_rollout
        with:
          flag: eas-workflow-test-flag
          active: true
          payload:
            welcome_message: hello from a workflow

  ignored_failure:
    steps:
      - uses: eas/posthog_flag_rollout
        with:
          flag: eas-workflow-test-flag
          active: true
          api_key: phx_invalid_local_test
          ignore_error: true

(Validate posthog side, feature flag is updated with enw values)

Screenshot 2026-07-03 at 10 21 39 AM Screenshot 2026-07-03 at 11 49 00 AM

Examples

These are simple workflows just to exercise the step. More fun and useful ones, mixed with EAS Update and deploys, are coming in the docs.

Ship a feature behind a flag

Publish the update, then enable the flag at 10% once the code is out.

name: Ship a feature behind a PostHog flag

jobs:
  update:
    type: update
    params:
      branch: main
      message: Ship new-checkout behind a flag

  enable_flag:
    needs: [update]
    steps:
      - uses: eas/posthog_flag_rollout
        with:
          flag: new-checkout
          active: true
          rollout_percentage: 10
Kill switch

Disable the flag, record an audit event, and leave a note on the run.

name: Kill switch, disable new-checkout now

jobs:
  disable_flag:
    steps:
      - uses: eas/posthog_flag_rollout
        with:
          flag: new-checkout
          active: false

  audit_trail:
    needs: [disable_flag]
    steps:
      - uses: eas/posthog_capture_event
        with:
          event: kill_switch_pulled
          properties:
            flag: new-checkout
            source: eas-workflow

@linear-code

linear-code Bot commented Jul 3, 2026

Copy link
Copy Markdown

ENG-21551

@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from c50c7ce to 4f8d88f Compare July 3, 2026 06:48
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.63%. Comparing base (dcd93a6) to head (f37a747).

Additional details and impacted files
@@                           Coverage Diff                            @@
##           gwdp/eng-21551-posthog-capture-event    #3944      +/-   ##
========================================================================
+ Coverage                                 59.55%   59.63%   +0.09%     
========================================================================
  Files                                       940      941       +1     
  Lines                                     41414    41498      +84     
  Branches                                   8725     8746      +21     
========================================================================
+ Hits                                      24661    24745      +84     
  Misses                                    16659    16659              
  Partials                                     94       94              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 4f8d88f to 17c3b91 Compare July 3, 2026 07:35
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-capture-event branch from c08213f to 0d8006c Compare July 3, 2026 07:35
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch 2 times, most recently from 3745235 to e006085 Compare July 3, 2026 17:14

gwdp commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Subscribed to pull request

File Patterns Mentions
**/* @douglowder

Generated by CodeMention

Warning: The preamble and epilogue options in commentConfiguration are deprecated. Use template instead.

Comment on lines +235 to +260
let updateResponse: Response;
try {
updateResponse = await fetch(`${flagsUrl}/${flag.id}/`, {
method: 'PATCH',
headers,
body: JSON.stringify(patch),
});
} catch (error) {
failOrIgnore({
logger,
ignoreError,
message: `Updating PostHog flag "${flagKey}" failed.`,
err: error,
});
return;
}
if (updateResponse.status === 403) {
throw new Error(
`Updating PostHog flag "${flagKey}" was forbidden (403). The personal API key likely lacks the "feature_flag:write" scope.`
);
}
if (!updateResponse.ok) {
failOrIgnore({
logger,
ignoreError,
message: `Updating PostHog flag "${flagKey}" failed with ${await readPostHogErrorAsync(updateResponse)}.`,

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.

ok now i think we might want a PostHogClient

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

100%, that got way cleaner now, thank you!

@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 021c85f to 7d5471d Compare July 6, 2026 19:51
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-capture-event branch from 5263ea7 to 32884c8 Compare July 6, 2026 19:51
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 7d5471d to 2a9777a Compare July 6, 2026 20:40
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-capture-event branch from 32884c8 to 090b547 Compare July 6, 2026 20:40
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 2a9777a to 05251fe Compare July 6, 2026 21:59
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-capture-event branch from 090b547 to f3d1c98 Compare July 6, 2026 21:59
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 05251fe to 84eab00 Compare July 6, 2026 22:21
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-capture-event branch from f3d1c98 to 194afc1 Compare July 6, 2026 22:21
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 84eab00 to 21a614d Compare July 6, 2026 22:54
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-capture-event branch 2 times, most recently from 1c7e9db to e28aa8f Compare July 6, 2026 23:35
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 21a614d to c84289b Compare July 6, 2026 23:35
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-capture-event branch from e28aa8f to dcd93a6 Compare July 7, 2026 23:43
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from c84289b to f37a747 Compare July 7, 2026 23:43
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

✅ Thank you for adding the changelog entry!

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