| name | run-github-ci-before-commit |
| description | Use when preparing to commit or push code and you must satisfy GitHub Actions CI requirements first. Enforce repository-scoped pre-commit checks based on workflow files, block commit/push on failures, and verify CI readiness before submitting to GitHub. |
Run GitHub CI Before Commit
Overview
Enforce a hard gate before git commit or git push: run the same required checks defined by the target repository's GitHub workflow. Never assume the skill folder is the target repository.
Workflow
- Resolve target repository.
- Discover CI requirements from workflow files.
- Build exact local check list.
- Execute checks and collect evidence.
- Block commit/push on failures.
- Submit to GitHub only after checks pass.
- Create pull request as the final step when requested.
Step 1: Resolve Target Repository (Mandatory)
Determine repo in this order:
- User-explicit path or repo name (highest priority).
- Current working directory git root (
git rev-parse --show-toplevel).
- If not in git repo, stop and ask for target repo path.
Hard rules:
- Do not treat
~/.codex/skills/<skill-name> as target repo unless user explicitly says so.
- Do not run CI checks in a non-git directory.
- Always print resolved repository path before running checks.
Step 2: Discover CI Requirements
Read workflow definitions from target repo:
.github/workflows/*.yml
.github/workflows/*.yaml
Prioritize jobs triggered by push / pull_request.
Extract required quality steps from run: commands first.
Focus on jobs that are quality gates for pull requests or pushes:
- lint / format
- typecheck / static analysis
- unit/integration/e2e tests
- build/package validation
- language-specific checks (security scan, migrations validation, etc.)
Ignore deployment-only jobs unless the user asks to run them locally.
If no workflow file exists, derive a best-effort default set from project scripts/toolchain and clearly state this is fallback mode.
Step 3: Build Local Check List
Build a deterministic ordered list matching CI intent, for example:
- install dependencies
- lint/format check
- typecheck/static analysis
- tests
- build
Use repository-native tooling and scripts first (bun run ..., npm run ..., pnpm ..., yarn ..., pytest, go test, etc.).
Do not invent non-existent commands.
If workflow has explicit commands, run those exact commands.
Step 4: Execute Checks
Run checks in deterministic order and stop at first failure when speed matters, or run all and produce a full failure list when diagnostics matter.
When a command fails:
- capture failing command
- capture key error output
- provide fix direction
- re-run affected checks after fix
Step 5: Commit/Push Gate Rules
- Never run
git commit while required checks are failing.
- Never run
git push while required checks are failing.
- If all required checks pass, proceed with commit flow and then push.
- If the user insists on commit/push with failures, require explicit confirmation and note risk.
Step 6: Submit to GitHub
When user asks "提交到 GitHub":
- Verify repo has remote (
git remote -v).
- Verify auth (
gh auth status) when available.
- Push branch to remote.
- If workflows exist, optionally check latest run status (
gh run list, gh run view).
- Report commit SHA, branch, remote URL, and CI status.
Step 7: Create Pull Request (Final Step)
When user asks to create PR (or asks to complete GitHub submission end-to-end):
- Confirm base branch and head branch.
- Ensure branch has been pushed successfully.
- Create PR with clear title and summary (
gh pr create).
- Return PR URL as final delivery artifact.
Hard rules:
- PR creation must happen after required checks pass and after push succeeds.
- If checks fail, do not create PR unless user explicitly overrides risk.
Output Format
Always report:
- Resolved target repo path
- Required checks list (source: workflow/fallback)
- Executed commands
- Pass/fail per command
- Final gate result:
CI Gate: PASS - Safe to commit
CI Gate: FAIL - Commit blocked
- If pushed: repo URL, branch, commit SHA, Actions status
- If PR created: PR URL, base branch, head branch
Example Triggers
- "提交前先跑一下 GitHub CI 要求"
- "帮我确认这次改动能过 CI 再 commit"
- "按仓库 CI 规则做 pre-commit 检查"
- "把这个改动提交到 GitHub"
- "创建 PR"
Guardrails
- Prefer exact CI parity over speed shortcuts.
- Keep command list concise and reproducible.
- If CI has matrix jobs, cover at least the default development target unless user requests full matrix simulation.
- If repository scope is ambiguous, stop and clarify before running checks or pushing.
- If user asks for PR, treat PR creation as the final completion step.