Skip to content

Commit 986bba6

Browse files
committed
cargo-rail: improving the config (rail.toml) documentation, especially around change-detection effectiveness.
1 parent 8220818 commit 986bba6

File tree

1 file changed

+84
-8
lines changed

1 file changed

+84
-8
lines changed

docs/config.md

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,18 +339,74 @@ benchmarks = ["benches/**", "perf/**"]
339339
docs = ["docs/**", "*.md"]
340340
```
341341

342-
**Use Case:**
343-
Custom categories enable conditional CI:
342+
#### GitHub Actions Integration
343+
344+
Use [`loadingalias/cargo-rail-action`](https://github.com/loadingalias/cargo-rail-action) for CI:
344345

345346
```yaml
346-
# .github/workflows/ci.yml
347-
- name: Check if benchmarks changed
347+
- uses: actions/checkout@v4
348+
with: { fetch-depth: 0 }
349+
350+
- uses: loadingalias/cargo-rail-action@v1
351+
id: affected
352+
353+
- name: Test affected
354+
if: steps.affected.outputs.docs-only != 'true'
348355
run: |
349-
if cargo rail affected --json | jq -e '.custom.benchmarks'; then
350-
cargo bench
356+
if [[ "${{ steps.affected.outputs.rebuild-all }}" == "true" ]]; then
357+
cargo test --workspace
358+
else
359+
cargo test ${{ steps.affected.outputs.cargo-args }}
351360
fi
352361
```
353362
363+
**Action Outputs:**
364+
365+
| Output | Description |
366+
|--------|-------------|
367+
| `docs-only` | `"true"` if only documentation changed |
368+
| `rebuild-all` | `"true"` if infrastructure files changed |
369+
| `crates` | Space-separated affected crates |
370+
| `cargo-args` | Ready-to-use `-p crate1 -p crate2` flags |
371+
| `matrix` | JSON array for `strategy.matrix` |
372+
| `count` | Number of affected crates |
373+
| `custom-categories` | JSON object of custom category matches |
374+
375+
**Conditional Jobs with Custom Categories:**
376+
377+
```yaml
378+
jobs:
379+
detect:
380+
outputs:
381+
run-bench: ${{ contains(steps.affected.outputs.custom-categories, 'benchmarks') }}
382+
steps:
383+
- uses: actions/checkout@v4
384+
with: { fetch-depth: 0 }
385+
- uses: loadingalias/cargo-rail-action@v1
386+
id: affected
387+
388+
bench:
389+
needs: detect
390+
if: needs.detect.outputs.run-bench == 'true'
391+
runs-on: ubuntu-latest
392+
steps:
393+
- uses: actions/checkout@v4
394+
- run: cargo bench
395+
```
396+
397+
#### Output Formats
398+
399+
The `affected` command supports multiple output formats via `--format`:
400+
401+
| Format | Use Case | Example |
402+
|--------|----------|---------|
403+
| `text` | Human debugging | `direct: 2\n lib-a` |
404+
| `json` | Scripting | `{"impact": {"direct": ["lib-a"]}}` |
405+
| `github` | `$GITHUB_OUTPUT` | `crates=lib-a lib-b` |
406+
| `github-matrix` | `strategy.matrix` | `{"include": [{"crate": "lib-a"}]}` |
407+
| `names-only` | Shell loops | `lib-a\nlib-b` |
408+
| `cargo-args` | Direct cargo use | `-p lib-a -p lib-b` |
409+
354410
---
355411

356412
### [crates.NAME] Configuration
@@ -371,6 +427,14 @@ Crate splitting and syncing configuration. Enables extracting crates to separate
371427
| `include` | `string[]` | no | Additional files/directories to include in the split (e.g., `["LICENSE", "README.md"]`) |
372428
| `exclude` | `string[]` | no | Files/directories to exclude from the split |
373429

430+
**Choosing a Mode:**
431+
432+
| Scenario | Mode | Result |
433+
|----------|------|--------|
434+
| Publish one crate independently | `single` | Files at repo root, standalone Cargo.toml |
435+
| Group related utility crates | `combined` + `standalone` | Preserves directory structure, independent crates |
436+
| Extract as sub-workspace | `combined` + `workspace` | Root Cargo.toml with `[workspace]` |
437+
374438
**Single Crate Example:**
375439

376440
```toml
@@ -446,9 +510,21 @@ skip = false
446510
skip = true # No changelog for internal crates
447511
```
448512

449-
#### [crates.NAME.sync]
513+
#### Syncing Split Repositories
514+
515+
After initial split, use `cargo rail sync` for bidirectional synchronization:
516+
517+
```bash
518+
cargo rail sync my-lib # Auto-detect direction
519+
cargo rail sync my-lib --to-remote # Monorepo → split repo
520+
cargo rail sync my-lib --from-remote # Split repo → monorepo (PR branch)
521+
```
522+
523+
**Key behaviors:**
450524

451-
Reserved for future use. Currently has no effect.
525+
- **Idempotent**: Uses git-notes to track synced commits; re-running only processes new commits
526+
- **PR branch protection**: `--from-remote` creates `cargo-rail-sync-<crate>` branch, never commits to main
527+
- **Conflict resolution**: `--strategy` controls merge behavior (`manual`, `ours`, `theirs`, `union`)
452528

453529
---
454530

0 commit comments

Comments
 (0)