|
| 1 | +# Context |
| 2 | + |
| 3 | +Purpose: ship a public GitHub Action that opens a PR when a new **CPython patch** for a tracked `X.Y` is released. Target users: OSS and companies that hard-pin Python patch versions in workflows, Dockerfiles, and version files. |
| 4 | + |
| 5 | +Problem: many repos pin `3.X.Y`. Renovate/Dependabot do not reliably sweep all pins or need custom regex managers. `actions/setup-python` resolves latest patch only when using `3.X` or `3.X.x`, not exact pins. |
| 6 | + |
| 7 | +Scope: |
| 8 | + |
| 9 | +- Track `X.Y` and propose the highest stable `X.Y.Z`. |
| 10 | +- Scan common files and bump exact patch pins in place. |
| 11 | +- Verify runner availability across ubuntu/macos/windows. |
| 12 | +- Open an idempotent PR with clear diff and rollback steps. |
| 13 | + |
| 14 | +Non-goals: |
| 15 | + |
| 16 | +- Major/minor upgrades by default. |
| 17 | +- Managing third-party toolchain lockfiles beyond version fields. |
| 18 | +- Editing unrelated dependencies. |
| 19 | + |
| 20 | +Success criteria: |
| 21 | + |
| 22 | +- First release used by ≥10 public repos. |
| 23 | +- ≥90% test coverage, green CI across ubuntu/macos/windows. |
| 24 | +- Zero duplicate PRs per track. Clear skip reasons. |
| 25 | + |
| 26 | +Key dependencies: |
| 27 | + |
| 28 | +- GitHub REST API via Octokit. |
| 29 | +- `actions/python-versions` manifest for runner availability. |
| 30 | +- Optional python.org releases page as fallback. |
| 31 | + |
| 32 | +Security and permissions: |
| 33 | + |
| 34 | +- Only `contents: write` and `pull-requests: write`. |
| 35 | +- No telemetry. Network calls limited to GitHub and optional python.org. |
| 36 | +- Concurrency guard and idempotent logic. |
| 37 | + |
| 38 | +Config inputs (initial): |
| 39 | + |
| 40 | +- `track` default `3.13`. |
| 41 | +- `include_prerelease` default `false`. |
| 42 | +- `paths` globs for scan. |
| 43 | +- `automerge` default `false`. |
| 44 | +- `dry_run` default `false`. |
| 45 | + |
| 46 | +Verification model: |
| 47 | + |
| 48 | +- Each task has a concrete check: unit tests, snapshots, CI jobs, sandbox PRs, or artifact outputs. |
| 49 | +- Emit outputs: `new_version`, `files_changed`, `skipped_reason`. |
| 50 | + |
| 51 | +Release plan: |
| 52 | + |
| 53 | +- `v0.x` until stable. Commit `dist/`. Provenance + CodeQL. Move `v1` tag on first stable. |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +# Tools |
| 58 | + |
| 59 | +Use Context7 MCP for up to date documentation. |
| 60 | + |
| 61 | +# Go-to task list for the public “CPython patch PR” GitHub Action |
| 62 | + |
| 63 | +> Implementation target: JavaScript Action (Node 20, TypeScript), bundled with `@vercel/ncc`, integrated PR creation via Octokit. Optional `peter-evans/create-pull-request`. |
| 64 | +
|
| 65 | +## 1) Repo and scaffolding |
| 66 | + |
| 67 | +1. [x] **Create repo and baseline files** |
| 68 | + Tools: `git`, GitHub. |
| 69 | + Files: `LICENSE` (MIT), `README.md`, `CODE_OF_CONDUCT.md`, `SECURITY.md`, `CONTRIBUTING.md`, `.gitignore`. |
| 70 | + Verify: Repo visible. GitHub detects license. |
| 71 | + |
| 72 | +2. [ ] **Scaffold TypeScript action** |
| 73 | + Tools: `npm`, `tsc`, template `actions/typescript-action`. |
| 74 | + Files: `package.json`, `tsconfig.json`, `action.yml`, `src/index.ts`. |
| 75 | + Verify: `npm run build` succeeds. `node dist/index.js` prints placeholder. |
| 76 | + |
| 77 | +3. [ ] **Define action metadata** |
| 78 | + Inputs: `track`, `include_prerelease`, `paths`, `automerge`, `dry_run`. |
| 79 | + Outputs: `new_version`, `files_changed`, `skipped_reason`. `runs: node20`. |
| 80 | + Verify: `actionlint` passes on sample workflow. |
| 81 | + |
| 82 | +4. [ ] **Add dev tooling** |
| 83 | + Install `eslint`, `prettier`, `vitest`, `@types/node`, `@vercel/ncc`, `actionlint`. |
| 84 | + Verify: `npm run lint` and `npm run test` pass. |
| 85 | + |
| 86 | +5. [ ] **CI for build/test** |
| 87 | + Workflow `.github/workflows/ci.yml` runs lint, test, build, ncc. |
| 88 | + Verify: CI green on PR. |
| 89 | + |
| 90 | +## 2) Core version discovery |
| 91 | + |
| 92 | +6. [ ] **CPython stable tag fetcher** |
| 93 | + Libs: `undici`, `semver`. |
| 94 | + Logic: GitHub tags pagination, filter out `a/b/rc/dev`. |
| 95 | + Verify: Unit test with mocked pages returns only stable tags. |
| 96 | + |
| 97 | +7. [ ] **Latest patch resolver for X.Y** |
| 98 | + Input: `3.13` → output highest `3.13.Z`. |
| 99 | + Verify: Unit test picks max. |
| 100 | + |
| 101 | +8. [ ] **python.org releases fallback** |
| 102 | + Scrape minimal list from source releases if GitHub fails. |
| 103 | + Verify: Mock HTML test extracts `3.13.Z`. |
| 104 | + |
| 105 | +9. [ ] **Runner availability check** |
| 106 | + Fetch `actions/python-versions` `versions-manifest.json`. |
| 107 | + Check ubuntu/macos/windows presence for `X.Y.Z`. |
| 108 | + Verify: Tests for present and missing versions. Flag respected. |
| 109 | + |
| 110 | +## 3) Repo scanning and matching |
| 111 | + |
| 112 | +10. [ ] **Glob discovery** |
| 113 | + Lib: `fast-glob`. Ignore `node_modules`, `.git`, `dist`. |
| 114 | + Verify: Unit test ensures correct file set. |
| 115 | + |
| 116 | +11. [ ] **Regex matchers** |
| 117 | + Patterns for workflows, Dockerfiles, `.python-version`, `.tool-versions`, `runtime.txt`, `tox.ini`, `pyproject.toml`, `Pipfile`, `environment.yml`. |
| 118 | + Verify: Positive/negative unit tests per pattern. |
| 119 | + |
| 120 | +12. [ ] **Scanner module** |
| 121 | + Collect matches with file, position, `X.Y.Z`, `X.Y`. |
| 122 | + Verify: Snapshot test over fixture repo. |
| 123 | + |
| 124 | +13. [ ] **Single X.Y alignment** |
| 125 | + Abort with `skipped_reason=multiple_tracks_detected` if mixed tracks (default). |
| 126 | + Verify: Unit test triggers skip. |
| 127 | + |
| 128 | +## 4) Rewrite engine |
| 129 | + |
| 130 | +14. [ ] **Patch computation** |
| 131 | + Replace `X.Y.Z_old` with `X.Y.Z_new` only when same `X.Y`. Preserve Docker suffixes. |
| 132 | + Verify: Unit tests show minimal diff. |
| 133 | + |
| 134 | +15. [ ] **Dry-run** |
| 135 | + No writes. Summarize planned changes. |
| 136 | + Verify: File hashes unchanged. Summary contains diffs. |
| 137 | + |
| 138 | +16. [ ] **Idempotence** |
| 139 | + If already at latest, set `skipped_reason=already_latest`. |
| 140 | + Verify: Second run produces skip. |
| 141 | + |
| 142 | +17. [ ] **Pre-release guard** |
| 143 | + Default off. Enabled by `include_prerelease=true`. |
| 144 | + Verify: Tests confirm behavior. |
| 145 | + |
| 146 | +## 5) PR creation and safety |
| 147 | + |
| 148 | +18. [ ] **Git branch and commit** |
| 149 | + Create `chore/bump-python-<track>`. Commit updated files. |
| 150 | + Verify: Local e2e shows new branch and commit. |
| 151 | + |
| 152 | +19. [ ] **Create PR via Octokit** |
| 153 | + Title, body with changelog links, manifest evidence, diff summary, rollback. Labels. |
| 154 | + Verify: Sandbox repo e2e PR opens with exact content. |
| 155 | + |
| 156 | +20. [ ] **Duplicate PR prevention** |
| 157 | + Search open PRs by head branch. Update branch if present. |
| 158 | + Verify: Second run updates same PR. |
| 159 | + |
| 160 | +21. [ ] **Optional external PR action** |
| 161 | + Flag `use_external_pr_action`. Skip internal PR. Emit outputs for `peter-evans/create-pull-request`. |
| 162 | + Verify: Example workflow successfully creates PR. |
| 163 | + |
| 164 | +22. [ ] **Automerge** |
| 165 | + If `automerge=true`, set label or merge on green via API when permitted. |
| 166 | + Verify: Sandbox e2e merges. |
| 167 | + |
| 168 | +## 6) Docs and UX |
| 169 | + |
| 170 | +23. [ ] **README quick start + advanced config** |
| 171 | + Include minimal and guarded examples, inputs/outputs tables, permissions, FAQs. |
| 172 | + Verify: `actionlint` validates examples. |
| 173 | + |
| 174 | +24. [ ] **CHANGELOG and versioning** |
| 175 | + Keep `CHANGELOG.md`. Plan `v0.x` then `v1`. |
| 176 | + Verify: Release notes generated on tag. |
| 177 | + |
| 178 | +25. [ ] **Action icon and color** |
| 179 | + Update `action.yml` branding. |
| 180 | + Verify: Marketplace shows branding. |
| 181 | + |
| 182 | +26. [ ] **Security model doc** |
| 183 | + Explain permissions, tokens, network endpoints. |
| 184 | + Verify: `SECURITY.md` updated. |
| 185 | + |
| 186 | +## 7) Testing matrix |
| 187 | + |
| 188 | +27. [ ] **Unit tests full coverage** |
| 189 | + Cover fetchers, parsers, matchers, rewriter, PR logic (mocked). |
| 190 | + Verify: Coverage ≥ 90%. |
| 191 | + |
| 192 | +28. [ ] **Fixture repos** |
| 193 | + Cases: only workflows, only Docker, mixed, conflicting tracks, prerelease-only. |
| 194 | + Verify: Snapshot outputs stable. |
| 195 | + |
| 196 | +29. [ ] **Dry-run CI job on fixtures** |
| 197 | + Upload `GITHUB_STEP_SUMMARY` artifacts. |
| 198 | + Verify: Artifacts contain expected diffs. |
| 199 | + |
| 200 | +30. [ ] **E2E sandbox nightly** |
| 201 | + Nightly scheduled PR cycle in a sandbox repo. |
| 202 | + Verify: PR created and closes as expected. |
| 203 | + |
| 204 | +31. [ ] **API throttling** |
| 205 | + Use Octokit throttling plugin. Retry with backoff. |
| 206 | + Verify: Tests assert retries and clear messages. |
| 207 | + |
| 208 | +## 8) Build, bundle, release |
| 209 | + |
| 210 | +32. [ ] **Bundle with ncc and commit `dist/`** |
| 211 | + `ncc build src/index.ts -o dist`. |
| 212 | + Verify: `dist/index.js` runs. No dynamic requires. |
| 213 | + |
| 214 | +33. [ ] **Release workflow** |
| 215 | + Tag `v0.1.0`. Maintain moving `v1`. |
| 216 | + Verify: Tags and Marketplace listing live. |
| 217 | + |
| 218 | +34. [ ] **Provenance + CodeQL** |
| 219 | + Enable `codeql-analysis`. Attach provenance to releases. |
| 220 | + Verify: CodeQL green. Provenance present. |
| 221 | + |
| 222 | +35. [ ] **Example consumer repos** |
| 223 | + Public minimal and guarded samples using the Action. |
| 224 | + Verify: Badges and scheduled runs visible. |
| 225 | + |
| 226 | +## 9) Quality and guardrails |
| 227 | + |
| 228 | +36. [ ] **Failure modes and messages** |
| 229 | + Emit `multiple_tracks_detected`, `runners_missing`, `no_matches_found`, `already_latest`, `pr_exists`, `pr_creation_failed`. |
| 230 | + Verify: Tests assert outputs and logs. |
| 231 | + |
| 232 | +37. [ ] **Config validation with zod** |
| 233 | + Validate `track` as `/^\d+\.\d+$/`. |
| 234 | + Verify: Bad inputs fail fast. |
| 235 | + |
| 236 | +38. [ ] **Concurrency control** |
| 237 | + Check existing ref before branch create. Document workflow `concurrency`. |
| 238 | + Verify: Parallel runs yield one PR. |
| 239 | + |
| 240 | +39. [ ] **Rollback instructions generator** |
| 241 | + PR body includes exact git commands. |
| 242 | + Verify: Snapshot contains commands with placeholders. |
| 243 | + |
| 244 | +40. [ ] **No extra telemetry** |
| 245 | + Only GitHub + python.org calls. Env `NO_NETWORK_FALLBACK=true` supported with injected data. |
| 246 | + Verify: Network-blocked tests pass using fixtures. |
| 247 | + |
| 248 | +## 10) Optional compatibility and polish |
| 249 | + |
| 250 | +41. [ ] **Renovate/Dependabot coexistence docs** |
| 251 | + Provide ignore rules to avoid flapping. |
| 252 | + Verify: Example configs tested. |
| 253 | + |
| 254 | +42. [ ] **Security keyword gating** |
| 255 | + Input `security_keywords` to gate bumps by release notes. |
| 256 | + Verify: Mock notes trigger gate. |
| 257 | + |
| 258 | +43. [ ] **Matrix output for CI** |
| 259 | + Output JSON of changed files and new version. |
| 260 | + Verify: Example consumes output. |
| 261 | + |
| 262 | +44. [ ] **Windows path handling** |
| 263 | + Use `node:path`. Add Windows CI job. |
| 264 | + Verify: Windows runner green. |
| 265 | + |
| 266 | +45. [ ] **Performance baseline** |
| 267 | + Log files scanned and duration. |
| 268 | + Verify: Fixture scan < 3s on CI. |
0 commit comments