|
| 1 | +--- |
| 2 | +name: gx-act |
| 3 | +description: "Run GitHub Actions workflows locally with nektos/act before pushing, so CI failures are caught on the laptop and the PR can be squash-merged on the first remote run." |
| 4 | +--- |
| 5 | + |
| 6 | +# gx-act — local GitHub Actions |
| 7 | + |
| 8 | +Use whenever a change touches code that would trigger CI on GitHub. Run the workflows locally with `act` first; only push the branch when the local run is green, then squash-merge the PR on GitHub. |
| 9 | + |
| 10 | +## When to invoke |
| 11 | + |
| 12 | +- Before `gx pr open` / `gx pr sync` / `gx branch finish --via-pr`. |
| 13 | +- Before re-pushing after a CI failure. |
| 14 | +- When iterating on `.github/workflows/*.yml` itself. |
| 15 | + |
| 16 | +## Install `act` |
| 17 | + |
| 18 | +`act` requires Docker (or Podman). Check the binary: |
| 19 | + |
| 20 | +```sh |
| 21 | +command -v act || echo "act not installed" |
| 22 | +``` |
| 23 | + |
| 24 | +Install one way: |
| 25 | + |
| 26 | +```sh |
| 27 | +# Linux/macOS via the upstream installer |
| 28 | +curl -fsSL https://raw.githubusercontent.com/nektos/act/master/install.sh | bash -s -- -b "$HOME/.local/bin" |
| 29 | + |
| 30 | +# macOS via Homebrew |
| 31 | +brew install act |
| 32 | + |
| 33 | +# Arch |
| 34 | +sudo pacman -S act |
| 35 | + |
| 36 | +# Or use the GitHub CLI extension |
| 37 | +gh extension install https://github.com/nektos/gh-act |
| 38 | +``` |
| 39 | + |
| 40 | +Upstream: https://github.com/nektos/act |
| 41 | + |
| 42 | +## Quick commands |
| 43 | + |
| 44 | +```sh |
| 45 | +# List jobs the local runner would execute for the push event |
| 46 | +act -l |
| 47 | + |
| 48 | +# Run the default push workflows (what GitHub runs on a normal push) |
| 49 | +act push |
| 50 | + |
| 51 | +# Run a specific event |
| 52 | +act pull_request |
| 53 | +act workflow_dispatch -W .github/workflows/release.yml |
| 54 | + |
| 55 | +# Run a single job |
| 56 | +act -j test |
| 57 | + |
| 58 | +# Pin a runner image (medium is the act default; large matches real GH closer) |
| 59 | +act -P ubuntu-latest=catthehacker/ubuntu:act-latest |
| 60 | + |
| 61 | +# Pass secrets / env without committing them |
| 62 | +act -s GITHUB_TOKEN="$GITHUB_TOKEN" --env-file .env.act |
| 63 | + |
| 64 | +# Reuse containers between runs (faster iteration) |
| 65 | +act --reuse |
| 66 | +``` |
| 67 | + |
| 68 | +## Workflow (local CI → squash-merge on GitHub) |
| 69 | + |
| 70 | +1. Implement the change in the agent worktree. |
| 71 | +2. `act -l` to confirm which jobs will fire for the event you care about. |
| 72 | +3. `act push` (or the specific event/job) until it is green locally. |
| 73 | +4. `gx branch finish --branch "<agent-branch>" --base main --via-pr --wait-for-merge --cleanup`. |
| 74 | + - Or `gx pr open` then `gx pr sync --auto-merge --merge-strategy squash` for explicit PR control. |
| 75 | +5. On GitHub: squash-merge once the remote run mirrors the local one. |
| 76 | + |
| 77 | +## Notes |
| 78 | + |
| 79 | +- `act` does not reproduce GitHub-hosted services exactly (no real secrets, different runner image, no concurrency groups). Treat a green `act` run as a strong signal, not a proof — the remote run is still authoritative. |
| 80 | +- Keep `act` config in `.actrc` at the repo root so every agent uses the same runner image. |
| 81 | +- If a workflow uses `GITHUB_TOKEN` for API calls, pass a PAT via `-s GITHUB_TOKEN=...`; do not commit it. |
| 82 | +- Add `.actrc`, `.cache/act`, and any `act`-specific event payloads to `.gitignore` if they appear. |
0 commit comments