|
| 1 | +# Checker script |
| 2 | + |
| 3 | +The checker script (`scripts/check`) runs code quality checks for all apps in the monorepo. It supports parallel |
| 4 | +execution, dependency management between checks, and various filtering options. |
| 5 | + |
| 6 | +## Quick start |
| 7 | + |
| 8 | +```bash |
| 9 | +# Run all checks (excludes slow checks by default) |
| 10 | +go run ./scripts/check |
| 11 | + |
| 12 | +# Run checks for a specific app |
| 13 | +go run ./scripts/check --app desktop |
| 14 | + |
| 15 | +# Run a specific check |
| 16 | +go run ./scripts/check --check desktop-rust-clippy |
| 17 | + |
| 18 | +# Run multiple specific checks |
| 19 | +go run ./scripts/check --check desktop-rust-rustfmt --check desktop-rust-clippy |
| 20 | + |
| 21 | +# Include slow checks |
| 22 | +go run ./scripts/check --include-slow |
| 23 | + |
| 24 | +# CI mode (no auto-fixing, stop on first failure) |
| 25 | +go run ./scripts/check --ci --fail-fast |
| 26 | +``` |
| 27 | + |
| 28 | +## Command-line options |
| 29 | + |
| 30 | +| Option | Description | |
| 31 | +| ----------------------------- | ------------------------------------------------ | |
| 32 | +| `--app NAME` | Run checks for a specific app | |
| 33 | +| `--rust`, `--rust-only` | Run only Rust checks (desktop) | |
| 34 | +| `--svelte`, `--svelte-only` | Run only Svelte checks (desktop) | |
| 35 | +| `--check ID` | Run specific checks by ID (repeatable) | |
| 36 | +| `--ci` | Disable auto-fixing (for CI) | |
| 37 | +| `--verbose` | Show detailed output | |
| 38 | +| `--include-slow` | Include slow checks (excluded by default) | |
| 39 | +| `--fail-fast` | Stop on first failure | |
| 40 | +| `-h`, `--help` | Show help message | |
| 41 | + |
| 42 | +## Available apps |
| 43 | + |
| 44 | +- `desktop` - The Tauri desktop app (Rust + Svelte) |
| 45 | +- `website` - The marketing website (Astro) |
| 46 | +- `license-server` - The license server (Cloudflare Worker) |
| 47 | + |
| 48 | +## How it works |
| 49 | + |
| 50 | +### Parallel execution |
| 51 | + |
| 52 | +Checks run in parallel by default, using a number of workers equal to the CPU count. The script respects dependencies |
| 53 | +between checks—if check B depends on check A, B won't start until A completes successfully. |
| 54 | + |
| 55 | +### Dependencies |
| 56 | + |
| 57 | +Checks can declare dependencies on other checks. For example: |
| 58 | +- `desktop-rust-clippy` depends on `desktop-rust-rustfmt` (formatting should happen before linting) |
| 59 | +- `desktop-svelte-eslint` depends on `desktop-svelte-prettier` |
| 60 | +- `desktop-rust-tests` depends on `desktop-rust-clippy` |
| 61 | + |
| 62 | +If a dependency fails, dependent checks are marked as "BLOCKED" and don't run. |
| 63 | + |
| 64 | +### Continue on failure |
| 65 | + |
| 66 | +By default, the script continues running independent checks even if some fail. Use `--fail-fast` to stop on the first |
| 67 | +failure (useful in CI). |
| 68 | + |
| 69 | +### Slow checks |
| 70 | + |
| 71 | +Some checks are marked as "slow" (for example, `desktop-rust-tests-linux` which runs tests in Docker). These are |
| 72 | +excluded by default. Use `--include-slow` to run them, or specify them directly with `--check`. |
| 73 | + |
| 74 | +## Output format |
| 75 | + |
| 76 | +Each check outputs a single line: |
| 77 | + |
| 78 | +``` |
| 79 | +• Desktop: 🦀 Rust / clippy... OK (1.23s) - No warnings |
| 80 | +``` |
| 81 | + |
| 82 | +Format: `• {App}: {Tech} / {CheckName}... {Status} ({Duration}) - {Message}` |
| 83 | + |
| 84 | +Status can be: |
| 85 | +- `OK` (green) - Check passed |
| 86 | +- `warn` (yellow) - Check passed with warnings |
| 87 | +- `SKIPPED` (yellow) - Check was skipped (for example, missing config file) |
| 88 | +- `FAILED` (red) - Check failed |
| 89 | +- `BLOCKED` (yellow) - Check couldn't run because a dependency failed |
| 90 | + |
| 91 | +A status line at the bottom shows currently running checks. |
| 92 | + |
| 93 | +## File structure |
| 94 | + |
| 95 | +``` |
| 96 | +scripts/check/ |
| 97 | +├── main.go # Entry point, CLI parsing |
| 98 | +├── runner.go # Parallel execution engine |
| 99 | +├── registry.go # Check lookup helpers |
| 100 | +├── colors.go # ANSI colors and output helpers |
| 101 | +├── utils.go # Utility functions |
| 102 | +├── types.go # Type re-exports (mostly empty) |
| 103 | +└── checks/ # Check implementations |
| 104 | + ├── common.go # Shared types and utilities |
| 105 | + ├── registry.go # Check definitions with metadata |
| 106 | + └── *.go # Individual check files |
| 107 | +``` |
| 108 | + |
| 109 | +## Adding a new check |
| 110 | + |
| 111 | +1. Create a new file in `scripts/check/checks/` following the naming convention `{app}-{tech}-{checkname}.go`: |
| 112 | + |
| 113 | +```go |
| 114 | +package checks |
| 115 | + |
| 116 | +import ( |
| 117 | + "fmt" |
| 118 | + "os/exec" |
| 119 | + "path/filepath" |
| 120 | +) |
| 121 | + |
| 122 | +// RunMyCheck does something useful. |
| 123 | +func RunMyCheck(ctx *CheckContext) (CheckResult, error) { |
| 124 | + cmd := exec.Command("some-tool", "some-args") |
| 125 | + cmd.Dir = filepath.Join(ctx.RootDir, "apps", "desktop") |
| 126 | + output, err := RunCommand(cmd, true) |
| 127 | + if err != nil { |
| 128 | + return CheckResult{}, fmt.Errorf("check failed\n%s", indentOutput(output)) |
| 129 | + } |
| 130 | + return Success("Checked 42 files"), nil |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +2. Add the check definition to `scripts/check/checks/registry.go`: |
| 135 | + |
| 136 | +```go |
| 137 | +{ |
| 138 | + ID: "desktop-mytech-mycheck", |
| 139 | + DisplayName: "mycheck", |
| 140 | + App: AppDesktop, |
| 141 | + Tech: "🔧 MyTech", |
| 142 | + IsSlow: false, |
| 143 | + DependsOn: []string{"desktop-mytech-formatter"}, // optional |
| 144 | + Run: RunMyCheck, |
| 145 | +}, |
| 146 | +``` |
| 147 | + |
| 148 | +3. Test your check: |
| 149 | + |
| 150 | +```bash |
| 151 | +go run ./scripts/check --check desktop-mytech-mycheck |
| 152 | +``` |
| 153 | + |
| 154 | +## Check implementation guidelines |
| 155 | + |
| 156 | +### Return values |
| 157 | + |
| 158 | +- Return `Success(message)` on success with a short, informative message |
| 159 | +- Return `Warning(message)` for non-fatal issues |
| 160 | +- Return `Skipped(reason)` when the check can't run (for example, missing config) |
| 161 | +- Return `CheckResult{}, error` on failure |
| 162 | + |
| 163 | +### Success messages |
| 164 | + |
| 165 | +Include useful stats in success messages: |
| 166 | + |
| 167 | +- ✅ `12 tests passed` |
| 168 | +- ✅ `Checked 42 files` |
| 169 | +- ✅ `No lint errors` |
| 170 | +- ❌ `OK` (too generic) |
| 171 | + |
| 172 | +### Error messages |
| 173 | + |
| 174 | +Include the command output in error messages using `indentOutput()`: |
| 175 | + |
| 176 | +```go |
| 177 | +return CheckResult{}, fmt.Errorf("check failed\n%s", indentOutput(output)) |
| 178 | +``` |
| 179 | + |
| 180 | +### CI vs local mode |
| 181 | + |
| 182 | +Use `ctx.CI` to change behavior: |
| 183 | + |
| 184 | +```go |
| 185 | +if ctx.CI { |
| 186 | + cmd = exec.Command("tool", "--check") // Just check, don't fix |
| 187 | +} else { |
| 188 | + cmd = exec.Command("tool", "--fix") // Auto-fix locally |
| 189 | +} |
| 190 | +``` |
| 191 | + |
| 192 | +### Dependencies |
| 193 | + |
| 194 | +Set `DependsOn` to ensure checks run in the right order: |
| 195 | + |
| 196 | +- Formatters should run before linters |
| 197 | +- Linters should run before tests |
| 198 | +- Type checkers should run before tests |
| 199 | + |
| 200 | +## Troubleshooting |
| 201 | + |
| 202 | +### Check is blocked |
| 203 | + |
| 204 | +A check shows "BLOCKED" when its dependency failed. Fix the dependency first. |
| 205 | + |
| 206 | +### Check is slow |
| 207 | + |
| 208 | +Add `IsSlow: true` to the check definition if it takes more than a few seconds. Users can include it with |
| 209 | +`--include-slow`. |
| 210 | + |
| 211 | +### Check needs a tool installed |
| 212 | + |
| 213 | +Use `CommandExists()` to check if a tool is installed, and auto-install if possible: |
| 214 | + |
| 215 | +```go |
| 216 | +if !CommandExists("some-tool") { |
| 217 | + installCmd := exec.Command("cargo", "install", "some-tool") |
| 218 | + if _, err := RunCommand(installCmd, true); err != nil { |
| 219 | + return CheckResult{}, fmt.Errorf("failed to install some-tool: %w", err) |
| 220 | + } |
| 221 | +} |
| 222 | +``` |
0 commit comments