{"data":{"slug":"discovered-ade47d3b57fcd8dc6d9ce1621b76399d97d08b7787557472","title":"Reproducing CI Locally","summary":"Run the exact CI checks locally to ensure consistency with the runner, including commands, paths, environment variables, and test markers derived directly from the workflow file.","url":"https:\/\/skillshunter.net\/skills\/discovered-ade47d3b57fcd8dc6d9ce1621b76399d97d08b7787557472","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-ade47d3b57fcd8dc6d9ce1621b76399d97d08b7787557472","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-ade47d3b57fcd8dc6d9ce1621b76399d97d08b7787557472.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-ade47d3b57fcd8dc6d9ce1621b76399d97d08b7787557472\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before running any CI commands locally, copy the `env:` block from the workflow into a `.env.ci` file and source it using `set -a; . .\/.env.ci; set +a` to match the CI environment. Ensure that the paths, commands, and test markers used locally are identical to those specified in the workflow file.","instructions":"---\nname: reproducing-ci-locally\ndescription: Run the CI gate on your machine so it agrees with the runner \u2014 deriving the exact command, paths, markers, and env from the workflow file instead of the Makefile, unblocking gate steps that short-circuit and hide the next failure, pinning the linter version CI resolves, building the interpreter\/toolchain environment the runner builds, and confirming the run is green instead of explaining a red job away. Use when a check passes locally but fails in CI (or the reverse), when a lint\/format job goes red on an untouched file, when setting up a local dev loop for an unfamiliar repo, or before pushing a branch you expect to merge.\n---\n\n# Reproducing CI Locally\n\nA local check is only useful if it runs the same thing the runner runs. Most\n\"green locally, red in CI\" failures are not bugs in the code \u2014 they are a\ndifference between two commands: different paths, different test markers,\ndifferent env, a different linter version, or a different interpreter.\n\nThe fix is mechanical: **derive the local command from the workflow file**, not\nfrom the Makefile, not from habit, not from what the last repo used.\n\n## Read the workflow before you run anything\n\nThe workflow is the contract. The Makefile is a convenience that drifts from it.\n\n```bash\n# What the gate actually is, in order\nsed -n '\/jobs:\/,$p' .github\/workflows\/ci.yml\n\n# Every command CI runs, across all workflows\ngrep -rn \"run:\" .github\/workflows\/\n```\n\nCopy out four things, verbatim:\n\n1. **The commands and their order.**\n2. **The paths each command is scoped to** (`ruff check app tests scripts` is not\n   `ruff check .`).\n3. **Test selection** \u2014 marker expressions, `-k` filters, which suites are excluded.\n4. **The `env:` block**, and the runtime\/toolchain versions in `setup-*` steps.\n\nEach of those four is a distinct way to get a wrong answer locally.\n\n**Paths.** If CI lints `app tests scripts` and you run `ruff check .`, you get\nfindings from directories CI never looks at \u2014 a red that isn't a merge blocker\nand shouldn't be \"fixed\" in an unrelated PR. Run it the narrow way to reproduce\nthe gate; run it the wide way only when you're deliberately auditing.\n\n**Markers.** A suite-wide `make test` that excludes one marker is not the CI\ngate if CI excludes six. Live-credential integration tests deselected in CI will\nrun locally, hit a fake key, and fail in a way that looks like a regression:\n\n```bash\n# Wrong: local shorthand \u2014 pulls in suites CI never runs\npytest -m \"not browser\"\n\n# Right: the full expression, copied from the workflow\npytest -m \"not browser and not slow and not load and not integration\"\n```\n\n**Env.** Config objects instantiated at import time (a settings singleton at\nmodule scope, an engine built when the module loads) make *collection* fail\nwithout the workflow's variables \u2014 a wall of \"Field required\" errors that looks\nlike a broken suite. Mirror the `env:` block, including the *shape* of values:\nif CI passes a Postgres URL and the module builds a pooled engine, a local\nSQLite URL raises on arguments that dialect rejects before a single test runs.\n\nKeep those values in a gitignored `.env.ci` copied from the workflow's `env:`\nblock, so the local command is the workflow command plus one `set -a`:\n\n```bash\nset -a; . .\/.env.ci; set +a\npytest -m \"not browser and not slow and not load and not integration\"\n```\n\n## A short-circuiting gate hides the next failure\n\nGate steps run in order and the job stops at the first red. So the CI log shows\nyou *one* failure even when three are waiting:\n\n```yaml\n- run: ruff check .          # fails here \u2026\n- run: ruff format --check . # \u2026 so this never runs, and you never see it\n```\n\nYou fix the lint error, push, and get an immediate second red for formatting.\nSame shape everywhere: `cargo fmt --all -- --check` before `cargo clippy\n--all-targets -- -D warnings` before `cargo test` means a formatting failure\ntells you nothing about whether clippy or the tests pass.\n\n**Run every gate step locally, even after one fails.** Don't `&&`-chain them\nwhile diagnosing \u2014 run them separately and collect the whole set:\n\n```bash\nruff check app tests scripts;  echo \"lint:   $?\"\nruff format --check app tests; echo \"format: $?\"\npytest -m \"not integration\";   echo \"tests:  $?\"\n```\n\nThe corollary: after a red job, never report \"only X is broken.\" Everything\ndownstream of X is unmeasured until you run it.\n\n## Pin what gates the build, and reproduce the version CI resolves\n\nAn unpinned gating tool means the gate changes without a commit. A range like\n`ruff>=0.4.0` resolves to whatever shipped this morning, and a release that\n*widens file coverage* \u2014 a formatter that starts formatting code blocks inside\nMarkdown, a linter that promotes a rule to default \u2014 turns every open PR red on\nfiles nobody touched.\n\nTwo habits:\n\n- **Pin the linter, formatter, and toolchain** in the manifest, and bump them in\n  a dedicated PR where the reformat is the whole diff.\n- **Reproduce with the version CI resolves**, not the one you happen to have:\n\n```bash\nuvx ruff@0.16.4 format --check .      # exactly what the runner would install\n\n# Node: CI does `npm ci` then `npx prettier --check web` \u2014 that's the LOCKFILE's\n# prettier. A bare `npx prettier` fetches the latest and flags files CI is fine\n# with. Read the pinned version, then ask for it.\ngrep -m1 -A2 '\"node_modules\/prettier\"' package-lock.json\nnpx -y prettier@3.8.3 --check web\n```\n\nFormatting a file CI never complained about is not a fix \u2014 it's an unrelated\ndiff caused by using a different tool than the gate.\n\n## Build the environment the runner builds\n\nPackage managers will happily invent an environment for you, and the one they\ninvent is not CI's.\n\n- **A fresh clone or worktree has no virtualenv.** `uv run <tool>` silently\n  creates a bare one *without* your dev extras, then fails with `Failed to\n  spawn: ruff` \u2014 which reads like a missing dependency rather than a missing\n  environment.\n- **`uv run` re-syncs from the lockfile** against your *host* interpreter. On a\n  Python newer than CI's matrix, a pinned dependency with no wheel for that\n  version gets built from source and fails on a compiler error that has nothing\n  to do with your change.\n- **Extras differ.** If CI installs `[dev,web]` and `make install` installs\n  `[dev]`, the full suite errors at collection locally on an import CI has.\n\nBuild it explicitly, at CI's interpreter version, with CI's extras:\n\n```bash\nuv venv .venv --python 3.12 --seed\nuv pip install --python \"$PWD\/.venv\/bin\/python\" -e \".[dev,web]\"\n.venv\/bin\/python -m ruff check app tests scripts\n.venv\/bin\/python -m pytest -m \"not integration\"\n```\n\nDriving the tools as `.venv\/bin\/python -m <tool>` sidesteps the re-sync entirely.\nIf you prefer `uv run`, pass `--no-sync`. And prefix with `env -u VIRTUAL_ENV`\nwhen a shell profile exports one \u2014 otherwise the run is silently redirected into\nan unrelated environment and its results mean nothing.\n\n## Fix divergence in shared config, not in the workflow\n\nWhen you find a difference, ask where the fix belongs. A flag added to the\nworkflow YAML fixes CI and leaves every local run diverging \u2014 so the next person\nhits the same confusion.\n\nPrefer the file both sides read:\n\n- Test-runner flags \u2192 `addopts` in `pyproject.toml`, not the workflow's `run:`.\n  (Import-mode is the classic one: a source directory on `sys.path` shadowing an\n  installed compiled package is a *config* problem, and pinning\n  `--import-mode=importlib` in `addopts` fixes local and CI together.)\n- Marker definitions, coverage thresholds, lint rules and target version \u2192 the\n  project manifest.\n- Keep `requires-python` and the linter's `target-version` in sync; a mismatch\n  means the linter applies rules for a runtime you don't support.\n\nThe workflow should read as `make lint` \/ `make test` plus the environment. When\nit contains flags the local target doesn't, that's the divergence.\n\n## Know which checks are actually gates\n\nNot every command in the repo is a merge blocker, and treating them as equal\nwastes PRs.\n\n```bash\n# Which jobs are required is a repo setting, not a file \u2014 check it\ngh api repos\/OWNER\/REPO\/branches\/main\/protection --jq '.required_status_checks.contexts'\n```\n\nIf CI runs the linter but not the type checker, then a pre-existing type error in\nan untouched module is not blocking your PR \u2014 don't fold a speculative fix for it\ninto an unrelated change, and don't claim CI verifies types. The inverse matters\ntoo: a helper target like `make quality-check` that runs *more* than CI will show\nyou reds that no one is gating on.\n\n## Finish by confirming the run, not by explaining it\n\n\"Passes locally\" is a prediction. Wait for the real result:\n\n```bash\ngh pr checks --watch\ngh run view --log-failed        # the failing step's output, not the summary\n```\n\nWhen a job is red, fix it in the same PR if the fix is feasible. If you believe\nit's pre-existing, **prove it**: check out the base commit and run the same\ncommand there. An unverified \"pre-existing \/ out of scope\" is how a base branch\nbecomes permanently red.\n\nTwo traps in the log itself:\n\n- A step gated on an event (`if: github.event.action == 'opened'`) is skipped\n  when you re-run by pushing a commit. Green-on-rerun can mean *not run*.\n- A permissions failure at the last step (an HTTP 403 posting a comment) shows\n  every build\/test step green with a red X on the job \u2014 read which step failed\n  before concluding the code is broken.\n\n## Checklist\n\n```\nBefore running anything:\n- [ ] Read .github\/workflows\/*.yml \u2014 commands, order, paths, markers, env, versions\n- [ ] Local command uses CI's paths (not `.`) and CI's full marker expression\n- [ ] Workflow env: block mirrored, including value shape (DB URL dialect, etc.)\n\nEnvironment:\n- [ ] venv created explicitly at CI's runtime version, with CI's extras\n- [ ] Tools driven from that venv (`.venv\/bin\/python -m \u2026` or `--no-sync`)\n- [ ] `env -u VIRTUAL_ENV` when a shell profile exports one\n- [ ] Gating linter\/formatter\/toolchain pinned; local run uses the pinned version\n\nRunning:\n- [ ] Every gate step run separately \u2014 a first failure hides the rest\n- [ ] Formatter check run even when the linter passed (they are different tools)\n\nFixing:\n- [ ] Divergence fixed in shared config (manifest\/addopts), not only in the workflow\n- [ ] Checked which jobs are actually required before treating a red as blocking\n- [ ] Waited for the real run; any red either fixed here or proven on the base commit\n```\n\n## Note for this repository (ffmpeg-skill)\n\nThis repo's gate is `.github\/workflows\/ci.yml`: install ffmpeg per-OS (apt \/\n`brew install ffmpeg-full` \/ `choco install ffmpeg`), then `python\ntests\/run_parallel.py --part N\/3` on each of three machines per OS: the nine\nmodules `tests\/test_all.py` imports plus `tests\/test_contract.py`, split three\nways (unittest, not pytest \u2014 there is no marker expression to copy, but there\nIS an OS-conditional: some `test_contract.py` tests and classes are `skipIf`'d\non Windows because they depend on a POSIX shell shim, not on CI's own `if:`\ngating). Read the actual workflow file before assuming a local `npm test` run\nmatches \u2014 `npm test` runs the same modules through `tests\/run_parallel.py`\nwithout the three-way split, and `python3 tests\/run_parallel.py --part 2\/3`\nruns one CI machine's share. Either reproduces a CI job only when the OS and\nthe FFmpeg version match that job's (CI runs FFmpeg 6.1, 7.1 and 8, and\nWindows): a failure that belongs to another FFmpeg version passes locally just\nas a Windows-only one does, and for Windows read what `skipIf` actually\nexcludes before assuming a fix applies everywhere.\n\nSource: [wdm0006\/python-skills](https:\/\/github.com\/wdm0006\/python-skills) (MIT).\n","use_cases":["Debugging a CI failure that passes locally","Reproducing a CI job that fails on an untouched file","Setting up a local development loop for an unfamiliar repository","Verifying a branch before pushing for merging"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/kajisho5\/ffmpeg-skill\/blob\/daae28ea4fe27223932392be07206798423c0f8b\/.claude\/skills\/reproducing-ci-locally\/SKILL.md","source_commit":"daae28ea4fe27223932392be07206798423c0f8b","license":null,"version":null,"listing_approved_at":"2026-11-28","created_at":"2026-11-28T08:11:23.000000Z","updated_at":"2026-11-28T18:38:03.000000Z","seo_title":"Reproducing CI Locally for Consistent Testing","seo_description":"Learn how to run CI checks locally with the same commands, paths, and environment as the CI runner to avoid discrepancies and ensure accurate test results.","seo_keywords":["reproduce ci locally","ci environment setup","ci test consistency","ci workflow execution","local ci testing"]}}