|
| 1 | +--- |
| 2 | +title: Checkout |
| 3 | +description: Advanced, configurable git checkout with shallow clone by default |
| 4 | +--- |
| 5 | + |
| 6 | +import { Code, Aside, Steps, CardGrid, Card } from '@astrojs/starlight/components'; |
| 7 | + |
| 8 | +Cigen automatically inserts a checkout step at the start of every job. By default this is a fast, shallow checkout implemented by a built-in `shallow_checkout` command. |
| 9 | + |
| 10 | +## Configuration |
| 11 | + |
| 12 | +Checkout can be configured at multiple levels, with this precedence: |
| 13 | + |
| 14 | +- Job-level `checkout` |
| 15 | +- Workflow-level `checkout` |
| 16 | +- Global `checkout` |
| 17 | +- Defaults (shallow checkout) |
| 18 | + |
| 19 | +### Parameters |
| 20 | + |
| 21 | +- `shallow` (boolean, default: true): when false, use CircleCI’s standard `checkout` step |
| 22 | +- `clone_options` (string): options for the initial clone, e.g. `--depth 1 --verbose` |
| 23 | +- `fetch_options` (string): options for `git fetch`, e.g. `--depth 10` |
| 24 | +- `tag_fetch_options` (string): options for fetching tags (default: `--tags`) |
| 25 | +- `keyscan` (map): add SSH host keys (`github`, `gitlab`, `bitbucket` ⇒ boolean) |
| 26 | +- `path` (string): checkout directory |
| 27 | + |
| 28 | +### Disable Checkout |
| 29 | + |
| 30 | +Set `checkout: false` at the global, workflow, or job level to skip inserting any checkout step for those scopes. |
| 31 | + |
| 32 | +<Code code={`jobs: |
| 33 | + lint: |
| 34 | + image: cimg/node:20.11 |
| 35 | + checkout: false # do not checkout repo for this job |
| 36 | + steps: |
| 37 | + - run: npm run lint`} lang="yaml" title="Disable checkout for a job" /> |
| 38 | + |
| 39 | +### Global Example |
| 40 | + |
| 41 | +<Code code={`checkout: |
| 42 | + shallow: true |
| 43 | + clone_options: "--depth 1" |
| 44 | + fetch_options: "--depth 10" |
| 45 | + tag_fetch_options: "--tags" |
| 46 | + keyscan: |
| 47 | + github: true |
| 48 | + gitlab: false |
| 49 | + bitbucket: false |
| 50 | + path: "."`} lang="yaml" title="Global checkout configuration" /> |
| 51 | + |
| 52 | +### Job Override Example |
| 53 | + |
| 54 | +<Code code={`jobs: |
| 55 | + build: |
| 56 | + image: cimg/node:20.11 |
| 57 | + checkout: |
| 58 | + shallow: true |
| 59 | + fetch_options: "--depth 50 --no-tags" |
| 60 | + steps: |
| 61 | + - run: npm run build`} lang="yaml" title="Job-level checkout override" /> |
| 62 | + |
| 63 | +<Aside type="note"> |
| 64 | + Do not add `checkout` or `shallow_checkout` in your job steps — cigen inserts the checkout step automatically. |
| 65 | + Set `shallow: false` to emit CircleCI's standard `checkout` step (optionally with `path`). |
| 66 | +</Aside> |
| 67 | + |
| 68 | +## Generated Output |
| 69 | + |
| 70 | +<Code code={`steps: |
| 71 | + - shallow_checkout |
| 72 | + - run: |
| 73 | + name: Build application |
| 74 | + command: npm run build`} lang="yaml" title="Shallow checkout (default)" /> |
| 75 | + |
| 76 | +<Code code={`steps: |
| 77 | + - shallow_checkout: |
| 78 | + fetch_options: --depth 50 --no-tags |
| 79 | + keyscan_github: true |
| 80 | + path: .`} lang="yaml" title="Parameterized shallow checkout" /> |
| 81 | + |
| 82 | +<Code code={`steps: |
| 83 | + - checkout |
| 84 | + - run: |
| 85 | + name: Build application |
| 86 | + command: npm run build`} lang="yaml" title="Standard checkout (shallow: false)" /> |
| 87 | + |
| 88 | +## Best Practices |
| 89 | + |
| 90 | +- Prefer shallow checkout for most jobs to reduce time and IO. |
| 91 | +- Increase `fetch_options` depth in jobs that need more history (e.g., changelog tooling). |
| 92 | +- Use `tag_fetch_options` when building from tags; disable tags (`--no-tags`) to reduce noise if unused. |
| 93 | +- Enable `keyscan` only for hosts you actually use (GitHub/GitLab/Bitbucket). |
| 94 | +- Use `path` when checking out into a subdirectory. |
| 95 | + |
| 96 | +## Migration |
| 97 | + |
| 98 | +If your configs include explicit `checkout` steps in job definitions: |
| 99 | + |
| 100 | +- Remove manual `checkout` steps; cigen now inserts checkout automatically. |
| 101 | +- If you required full history, set `checkout.shallow: false` at the appropriate scope. |
| 102 | +- If you used custom clone or fetch options, move them under the `checkout` section. |
0 commit comments