{"id":20313742,"url":"https://github.com/posthog/posthog-github-action","last_synced_at":"2026-04-26T10:01:02.312Z","repository":{"id":66068773,"uuid":"558047242","full_name":"PostHog/posthog-github-action","owner":"PostHog","description":"Capture CI/CD metrics in PostHog - workflow duration, success rates, and performance trends","archived":false,"fork":false,"pushed_at":"2026-02-17T12:19:07.000Z","size":1685,"stargazers_count":5,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-02-17T17:52:50.775Z","etag":null,"topics":["analytics","ci-cd","continuous-integration","github-actions","metrics","posthog"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PostHog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-10-26T19:51:54.000Z","updated_at":"2026-02-17T12:19:18.000Z","dependencies_parsed_at":"2023-03-19T18:36:06.923Z","dependency_job_id":null,"html_url":"https://github.com/PostHog/posthog-github-action","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/PostHog/posthog-github-action","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fposthog-github-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fposthog-github-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fposthog-github-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fposthog-github-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PostHog","download_url":"https://codeload.github.com/PostHog/posthog-github-action/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fposthog-github-action/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32292958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T09:34:17.070Z","status":"ssl_error","status_checked_at":"2026-04-26T09:34:00.993Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","ci-cd","continuous-integration","github-actions","metrics","posthog"],"created_at":"2024-11-14T18:12:34.319Z","updated_at":"2026-04-26T10:01:02.306Z","avatar_url":"https://github.com/PostHog.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostHog GitHub Action\n\nCapture CI/CD metrics in PostHog - track workflow duration, success/failure rates, and analyze performance trends with PostHog's full analytics toolkit.\n\n## Quick Start\n\n```yaml\njobs:\n  tests:\n    # ... your test job\n\n  ci-metrics:\n    needs: [tests]\n    if: always()\n    runs-on: ubuntu-latest\n    steps:\n      - uses: PostHog/posthog-github-action@v1\n        with:\n          posthog-token: ${{ secrets.POSTHOG_API_KEY }}\n          event: 'ci-metrics'\n          capture-run-duration: true\n          github-token: ${{ secrets.GITHUB_TOKEN }}\n          status-job: 'tests'\n```\n\nThis captures run duration, pass/fail status, and GitHub context (repo, branch, commit, actor).\n\n## Why PostHog for CI Metrics?\n\n- **Trends \u0026 insights** - duration over time, failure rates by branch/author\n- **Dashboards** - build CI health dashboards alongside product metrics\n- **Alerts** - get notified when builds slow down or failure rates spike\n- **Correlation** - connect CI data with your product analytics\n\n## Inputs\n\n### `posthog-token`\n\n**Required** Your write-only PostHog API Token (Project API Key).\n\n### `posthog-api-host`\n\nYour PostHog API Host.\n\nDefaults to `https://us.i.posthog.com`\n\n### `event`\n\n**Required** The event name to send to PostHog.\n\nDefaults to `event-from-github-actions`\n\n### `properties`\n\nOptional properties to add to the event. These should be passed as a string containing a JSON object.\n\nThe action runs `JSON.parse(properties)` on the input.\n\n### `capture-run-duration`\n\nSet to `true` to capture run duration via GitHub API. Adds `duration_seconds` and run metadata.\n\n### `capture-job-durations`\n\nSet to `true` to capture timing and status for each job in the workflow. Emits one additional event per completed job (named `{event}-job`, e.g., `ci-metrics-job`). All events share the same `workflow_run` group for correlation in PostHog.\n\n### `github-token`\n\nGitHub token for API access. Required when `capture-run-duration`, `capture-job-durations`, or `status-job` is set.\n\n### `runner`\n\nOptional runner label to include in properties (e.g., `'depot'`).\n\n### `status-job`\n\nJob name to check for workflow status. Captures that job's conclusion (`success`, `failure`, `cancelled`) as `conclusion`.\n\nNote: Your metrics job must `needs` the target job and use `if: always()` to run even on failure.\n\n## Automatically Included Properties\n\nThe following GitHub context properties are automatically added to every event:\n\n- `sha` - The commit SHA\n- `ref` - The branch or tag ref\n- `workflow` - The workflow name\n- `runNumber` - The run number\n- `runId` - The run ID\n- `repository` - The repository name\n- `repositoryOwner` - The repository owner\n- `actor` - The user who triggered the workflow\n- `actor_type` - `\"bot\"` if `actor` ends in `[bot]` or matches a known bot account (currently `Copilot`), otherwise `\"human\"`. Useful for slicing CI metrics by bot vs. human-driven runs.\n- `eventName` - The event that triggered the workflow\n\nWhen `capture-run-duration` is enabled:\n\n- `duration_seconds` - Time elapsed since run started\n- `url` - URL to the run\n- `attempt` - The attempt number\n- `started_at` - ISO 8601 timestamp\n\nWhen `status-job` is set:\n\n- `conclusion` - Referenced job's conclusion (`success`, `failure`, `cancelled`)\n\nWhen `capture-job-durations` is enabled, each per-job event (`{event}-job`) includes:\n\n- `name` - The job's display name\n- `duration_seconds` - Time from job start to completion\n- `conclusion` - Job result (`success`, `failure`, `cancelled`, `skipped`)\n- `started_at` - ISO 8601 timestamp\n- `completed_at` - ISO 8601 timestamp\n- `runner` - The runner that executed the job\n\n## Groups \u0026 Correlation\n\nAll events are tagged with a `workflow_run` group (`owner/repo/run_id`) for correlation in PostHog.\n\nWhen `capture-job-durations` is enabled, group properties are also set via `groupIdentify`:\n\n```\nworkflow_run: PostHog/posthog/12345\n├── group properties: { conclusion: 'success' }     ← only with capture-job-durations\n│\n├── event: ci-metrics                               ← run-level metrics\n│   └── { duration_seconds: 1080, conclusion: 'success', ... }\n│\n├── event: ci-metrics-job                           ← per-job metrics\n│   └── { name: 'Build', duration_seconds: 120, conclusion: 'success', ... }\n│\n└── event: ci-metrics-job\n    └── { name: 'Test', duration_seconds: 300, conclusion: 'success', ... }\n```\n\nThis enables:\n- **Filter job events by workflow outcome** - use group property `workflow_run.conclusion`\n- **See all jobs in a run** - filter by `workflow_run = owner/repo/run_id`\n- **Correlate across events** - breakdown by group in insights\n\n## Example Usage\n\n### Custom event with properties\n\n```yaml\n- uses: PostHog/posthog-github-action@v1\n  with:\n    posthog-token: ${{ secrets.POSTHOG_API_KEY }}\n    event: \"deploy-completed\"\n    properties: '{\"environment\": \"production\"}'\n```\n\n### With run duration\n\n```yaml\n- uses: PostHog/posthog-github-action@v1\n  with:\n    posthog-token: ${{ secrets.POSTHOG_API_KEY }}\n    event: \"ci-metrics\"\n    capture-run-duration: true\n    github-token: ${{ secrets.GITHUB_TOKEN }}\n```\n\n### With per-job metrics\n\n```yaml\n- uses: PostHog/posthog-github-action@v1\n  with:\n    posthog-token: ${{ secrets.POSTHOG_API_KEY }}\n    event: \"ci-metrics\"\n    capture-run-duration: true\n    capture-job-durations: true\n    github-token: ${{ secrets.GITHUB_TOKEN }}\n    status-job: 'Tests'\n```\n\n### Using with EU Cloud\n\n```yaml\n- uses: PostHog/posthog-github-action@v1\n  with:\n    posthog-token: ${{ secrets.POSTHOG_API_KEY }}\n    posthog-api-host: \"https://eu.i.posthog.com\"\n    event: \"ci-metrics\"\n    capture-run-duration: true\n    github-token: ${{ secrets.GITHUB_TOKEN }}\n```\n\n### Complete Workflow Example\n\n```yaml\nname: CI\n\non:\n  push:\n    branches: [main]\n  pull_request:\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - run: npm test\n\n  ci-metrics:\n    needs: [test]\n    if: always()\n    runs-on: ubuntu-latest\n    steps:\n      - uses: PostHog/posthog-github-action@v1\n        with:\n          posthog-token: ${{ secrets.POSTHOG_API_KEY }}\n          event: \"ci-metrics\"\n          capture-run-duration: true\n          capture-job-durations: true\n          github-token: ${{ secrets.GITHUB_TOKEN }}\n          status-job: 'test'\n```\n\n## Development\n\n### Prerequisites\n\n- Node.js 20+\n- [act](https://github.com/nektos/act) for local testing (requires Docker)\n\n### Setup\n\n```bash\n# Install dependencies\nnpm install\n\n# Copy secrets template and add your PostHog API token\ncp .secrets.example .secrets\n```\n\n### Building\n\nThis action uses [`@vercel/ncc`](https://github.com/vercel/ncc) to bundle all dependencies into a single file. **You must rebuild before committing changes:**\n\n```bash\nnpm run build\n```\n\nThis compiles `index.js` and all dependencies into `dist/index.js`.\n\n### Testing Locally\n\nTest the action locally using `act`:\n\n```bash\n# Dry run (validates workflow without running)\nnpm run test:dry-run\n\n# Full test (sends real event to PostHog)\nnpm test\n```\n\nNote: `act` requires Docker to be running.\n\n## Releasing\n\n### 1. Build the Bundle\n\nAlways rebuild before releasing to ensure the dist folder is up to date:\n\n```bash\nnpm run build\n```\n\n### 2. Commit and Merge\n\n```bash\n# Update version in package.json manually\ngit add package.json dist/\ngit commit -m \"1.x.x\"\n# Create PR and merge to main\n```\n\n### 3. Tag the Release\n\n```bash\ngit checkout main \u0026\u0026 git pull\ngit tag v1.x.x\ngit push origin v1.x.x\n```\n\nThe release workflow creates the GitHub Release and updates the `v1` tag automatically.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthog%2Fposthog-github-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthog%2Fposthog-github-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthog%2Fposthog-github-action/lists"}