pipechecker 0.2.10

CI/CD Pipeline Auditor - Catch errors before you push
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# PipeChecker

> **Catch CI/CD pipeline errors before you push β€” not after CI fails.**

[![CI](https://github.com/Ayyankhan101/PipeChecker/actions/workflows/ci.yml/badge.svg)](https://github.com/Ayyankhan101/PipeChecker/actions/workflows/ci.yml)
[![Crates.io](https://img.shields.io/crates/v/pipechecker.svg)](https://crates.io/crates/pipechecker)
[![License](https://img.shields.io/badge/license-MIT%20%2F%20Apache--2.0-blue)](LICENSE-MIT)
[![Test Coverage](https://img.shields.io/badge/tests-134%20passing-brightgreen)]()
[![Rust](https://img.shields.io/badge/rust-2021-orange)](Cargo.toml)

---

## What Problem Does This Solve?

Every developer has been here:

```
πŸ’€ You push a small change β†’ CI fails 10 minutes later β†’
   you fix it β†’ push again β†’ CI fails again β†’ repeat 3 more times
```

**PipeChecker runs locally** and validates your CI/CD workflows **before** you commit, so you catch:

| Catches | Example |
|---------|---------|
| ❌ **Circular dependencies** | Job A β†’ Job B β†’ Job A |
| ❌ **Missing job references** | `needs: [build]` but no `build` job exists |
| ❌ **Empty pipelines** | No jobs or steps defined |
| ⚠️ **Hardcoded secrets** | `API_KEY=sk_live_abc123` in env vars |
| ⚠️ **Undeclared env vars** | `${{ env.UNKNOWN }}` never defined |
| ⚠️ **Unpinned actions** | `uses: actions/checkout` without `@v4` |
| ⚠️ **Docker `:latest` tags** | `image: nginx:latest` (unreproducible builds) |
| ⚠️ **Missing job timeouts** | No `timeout-minutes` set β€” jobs can run forever |

---

## Visual Overview

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    YOUR WORKFLOW FILE                    β”‚
β”‚              (.github/workflows/ci.yml)                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚    PIPECHECKER       β”‚
              β”‚                      β”‚
              β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
              β”‚  β”‚  YAML Parser   β”‚  β”‚
              β”‚  β”‚ GitHub/GitLab  β”‚  β”‚
              β”‚  β”‚   CircleCI     β”‚  β”‚
              β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
              β”‚          β”‚           β”‚
              β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
              β”‚  β”‚    Auditors    β”‚  β”‚
              β”‚  β”‚                β”‚  β”‚
              β”‚  β”‚  πŸ“‹ Syntax     β”‚  β”‚
              β”‚  β”‚  πŸ”— DAG/Cycle  β”‚  β”‚
              β”‚  β”‚  πŸ”’ Secrets    β”‚  β”‚
              β”‚  β”‚  🐳 Docker     β”‚  β”‚
              β”‚  β”‚  πŸ“Œ Pinning    β”‚  β”‚
              β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
              β”‚          β”‚           β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β–Ό              β–Ό              β–Ό
     βœ… PASS       ⚠️ WARNINGS    ❌ ERRORS
   No issues     Fix before       Must fix
   found!        production       before push
```

---

## Documentation

Comprehensive documentation can be found in the [docs/](docs/index.md) folder:
- [Start Here]docs/START_HERE.md
- [Complete Guide]docs/COMPLETE_GUIDE.md
- [TUI Guide]docs/TUI_GUIDE.md
- [Contributing]docs/CONTRIBUTING.md

---

## Supported Platforms

| Platform | File Pattern | Status |
|----------|-------------|--------|
| **GitHub Actions** | `.github/workflows/*.yml` | βœ… Full support |
| **GitLab CI** | `.gitlab-ci.yml` | βœ… Full support |
| **CircleCI** | `.circleci/config.yml` | βœ… Full support |

---

## Installation

### From crates.io
```bash
cargo install pipechecker
```

### From source
```bash
git clone https://github.com/Ayyankhan101/PipeChecker.git
cd PipeChecker
cargo install --path .
```

### Via npm (once published)
```bash
npm install -g pipechecker
```

---

## GitHub Action

PipeChecker can be used directly in your GitHub workflows:

```yaml
name: CI Pipeline Check
on: [push, pull_request]

jobs:
  pipechecker:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: Ayyankhan101/PipeCheck/actions/pipecheck@v0.2.9
```

### Action Inputs

| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| `path` | No | `.github/workflows` | Path to workflow file(s) |
| `strict` | No | `false` | Exit with error on warnings |
| `diff` | No | `false` | Check only changed files |
| `diff-branch` | No | `main` | Base branch for diff mode |

---

## Diff Mode

Check only workflow files that changed since a base branch:

```bash
# Check files changed since main
pipechecker --diff --diff-branch main

# Short form
pipechecker -d
```

This uses `git diff --name-only` to find changed workflow files, then checks only those. Faster in monorepos with many workflows.

---

## Quick Start

### 1. Check a single file
```bash
pipechecker .github/workflows/ci.yml
```

### 2. Auto-detect your workflow
```bash
pipechecker
# βœ“ Auto-detected: .github/workflows/ci.yml
# Provider: GitHubActions
# 0 errors, 0 warnings
```

### 3. Audit everything
```bash
pipechecker --all
# Checking 3 workflow file(s)...
#
# πŸ“„ .github/workflows/ci.yml
#    Provider: GitHubActions
#    βœ… No issues found
#
# πŸ“„ .github/workflows/deploy.yml
#    Provider: GitHubActions
#    1 errors, 2 warnings
#    ❌ ERROR: Circular dependency detected (job: deploy)
#       πŸ’‘ Remove one of the dependencies to break the cycle
#    ⚠️ WARNING: Job 'deploy' has no steps
#
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# Total: 1 errors, 2 warnings across 3 files
```

---

## Interactive TUI

PipeChecker includes a **terminal UI** for browsing results across multiple files:

```bash
pipechecker --tui
```

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ” Pipecheck - Interactive Mode         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Workflows                               β”‚
β”‚β–Ά ❌ deploy.yml β”‚ 2 errors β”‚ 1 warnings   β”‚
β”‚  βœ… ci.yml     β”‚ 0 errors β”‚ 0 warnings   β”‚
β”‚  ⚠️  lint.yml   β”‚ 0 errors β”‚ 3 warnings   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  [↑/↓] Navigate  [Enter] Details  [Q] Quitβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**Keyboard shortcuts:**

| Key | Action |
|-----|--------|
| `↑` / `k` | Move up |
| `↓` / `j` | Move down |
| `Enter` / `Space` | Toggle detail view |
| `q` / `Esc` | Quit |

---

## All CLI Flags

| Flag | Description |
|------|-------------|
| `FILE` | Path to a specific workflow file |
| `--all`, `-a` | Audit **all** discovered workflow files |
| `--tui` | Launch the interactive terminal UI |
| `--watch`, `-w` | Watch for file changes and re-run audits |
| `--fix` | Auto-fix issues (pin unpinned actions + Docker `:latest` tags) |
| `--install-hook` | Install a git pre-commit hook |
| `--format`, `-f` `<text\|json>` | Output format (default: `text`) |
| `--strict`, `-s` | Treat warnings as errors (exit code 1) |
| `--quiet`, `-q` | Only output errors β€” suppress warnings and info. Perfect for CI |
| `--verbose` | Show diagnostic info (auditors ran, per-severity counts, discovered files) |
| `--no-pinning` | Skip Docker image and action-pinning checks |
| `--version` | Show version |
| `--help` | Show help |

---

## Output Explained

### Severity Levels

| Symbol | Level | Meaning |
|--------|-------|---------|
| ❌ | **Error** | Must fix β€” will break your pipeline |
| ⚠️ | **Warning** | Should fix β€” may cause issues later |
| ℹ️ | **Info** | Informational β€” nothing to worry about |

### Example output with details

```
Provider: GitHubActions
2 errors, 1 warnings

❌ ERROR: Circular dependency detected (job: deploy) [line 42]
   πŸ’‘ Remove one of the dependencies to break the cycle

❌ ERROR: Job 'deploy' depends on non-existent job 'build' (job: deploy) [line 45]
   πŸ’‘ Add a job with id 'build' or remove the dependency

⚠️ WARNING: Job 'lint' has no steps (job: lint) [line 12]
   πŸ’‘ Add steps to perform work in this job
```

Each issue includes:
- **What** went wrong (clear message)
- **Where** it happened (job name + line number)
- **How** to fix it (actionable suggestion)

---

## JSON Output

Perfect for CI/CD integration or programmatic consumption:

```bash
pipechecker --format json
```

```json
{
  "provider": "GitHubActions",
  "issues": [
    {
      "severity": "Error",
      "message": "Circular dependency detected: job-a -> job-b -> job-a",
      "location": { "line": 42, "column": 3, "job": "deploy" },
      "suggestion": "Remove one of the dependencies to break the cycle"
    }
  ],
  "summary": "1 errors, 0 warnings"
}
```

---

## Modes of Operation

### πŸ”§ Auto-Fix Mode
Automatically pins unpinned GitHub Actions to known versions:

```bash
pipechecker --fix
```

```
πŸ”§ Auto-fix mode

✨ Fixed 2 issue(s) in .github/workflows/ci.yml:

  actions/checkout β†’ actions/checkout@v4
  actions/setup-node β†’ actions/setup-node@v4

πŸ’‘ Review the changes and commit them!
```

### πŸ‘€ Watch Mode
Monitors workflow files and re-runs on every save β€” perfect for development:

```bash
pipechecker --watch
```

```
πŸ‘€ Watching for workflow changes...
   Press Ctrl+C to stop

πŸ”„ File changed: .github/workflows/ci.yml
Provider: GitHubActions
0 errors, 0 warnings
βœ… All checks passed
```

### 🀫 Quiet Mode (CI-Friendly)
Only output errors β€” suppress warnings and info. Perfect for CI pipelines where you want clean output:

```bash
pipechecker --quiet
# or
pipechecker -q
```

```
❌ Circular dependency detected (job: deploy) (in .github/workflows/deploy.yml)
```

Exit code is still `1` if there are errors β€” works perfectly with `--strict` for failing CI on any issue.

### πŸ“’ Verbose Mode
See exactly what PipeChecker is doing β€” which files it found, which auditors ran, and per-severity breakdowns:

```bash
pipechecker --verbose
```

```
πŸ“„ Auditing: .github/workflows/ci.yml
πŸ” Auditors ran: syntax, dag, secrets, pinning
πŸ“Š Found: 0 errors, 1 warnings, 0 info
⏱️  Checked in 3.2ms
```

### ⏱️ Timing Metrics
Every audit now shows how long it took β€” because speed matters:

```bash
pipechecker .github/workflows/ci.yml
```

```
Provider: GitHubActions
0 errors, 0 warnings
βœ… All checks passed
⏱️  Checked in 2.1ms
```

### πŸ”’ Pre-commit Hook
Never commit a broken workflow again:

```bash
pipechecker --install-hook
```

```
βœ… Pre-commit hook installed!
   Pipecheck will run before every commit
   Use 'git commit --no-verify' to skip
```

The hook automatically validates any workflow files you stage:

```bash
$ git commit -m "Update CI pipeline"
πŸ” Checking workflows with pipechecker...
❌ ERROR: Circular dependency detected (job: deploy) [line 42]
   πŸ’‘ Remove one of the dependencies to break the cycle

❌ Workflow validation failed!
Fix errors above or use 'git commit --no-verify' to skip
```

---

## Configuration File

Create a `.pipecheckerrc.yml` in your project root to customize behavior:

```yaml
# Files to skip (glob patterns supported)
ignore:
  - .github/workflows/experimental-*.yml
  - .github/workflows/draft-*.yml
  - old-pipeline.yml

# Toggle individual audit rules
rules:
  circular_dependencies: true   # Detect dependency cycles
  missing_secrets: true         # Flag hardcoded secrets
  docker_latest_tag: true       # Warn about :latest tags
```

PipeChecker searches for config in this order:
1. `.pipecheckerrc.yml`
2. `.pipecheckerrc.yaml`
3. `.pipechecker.yml`

---

## How the Auditors Work

### πŸ“‹ Syntax Auditor
Validates the structural integrity of your pipeline:

- βœ… Jobs are defined
- βœ… Steps exist within jobs
- βœ… No duplicate job IDs
- βœ… `needs` / `depends_on` targets exist

### πŸ”— DAG Auditor (Cycle Detection)
Builds a **dependency graph** of your jobs and runs **Tarjan's Strongly Connected Components** algorithm:

```
  job-a ──depends──▢ job-b
    β–²                   β”‚
    β”‚                   β–Ό
    └────depends──── job-c
```
β†’ ❌ **Circular dependency detected:** job-a β†’ job-b β†’ job-c β†’ job-a

### πŸ”’ Secrets Auditor
Scans for security issues in environment variables and run blocks:

```yaml
env:
  API_KEY: sk_live_abc123         # ⚠️ Hardcoded secret
  TOKEN: ${{ secrets.TOKEN }}     # βœ… Correct way
  RUN: echo ${{ secrets.API_KEY }} # ℹ️ Info β€” ensure it's configured
  RUN: echo ${{ env.UNDEFINED }}  # ⚠️ Undeclared env var
```

Detects:
- Hardcoded API keys, passwords, tokens
- Secret references in `with:` blocks
- Undeclared `${{ env.X }}` references
- Suspicious values (long alphanumeric strings, base64)

### 🐳 Docker & πŸ“Œ Pinning Auditor
Ensures reproducible builds:

```yaml
uses: actions/checkout              # ⚠️ No version pin
uses: actions/checkout@v4           # βœ… Pinned
image: nginx:latest                 # ⚠️ Unpredictable
image: nginx:1.25-alpine            # βœ… Specific
```

---

## Real-World Examples

### Example 1: Valid workflow
```bash
$ pipechecker .github/workflows/ci.yml
Provider: GitHubActions
0 errors, 0 warnings
```

### Example 2: Circular dependency
```yaml
jobs:
  deploy:
    needs: [test]
    steps: [{ run: echo deploy }]
  test:
    needs: [deploy]
    steps: [{ run: echo test }]
```
```bash
$ pipechecker broken.yml
Provider: GitHubActions
1 errors, 0 warnings

❌ ERROR: Circular dependency detected (job: deploy)
   πŸ’‘ Remove one of the dependencies to break the cycle
```

### Example 3: Hardcoded secrets
```yaml
jobs:
  build:
    env:
      API_SECRET: sk_live_hardcoded_value
    steps: [{ run: echo building }]
```
```bash
$ pipechecker secrets.yml
Provider: GitHubActions
0 errors, 1 warnings

⚠️ WARNING: Job 'build' env 'API_SECRET' may contain a hardcoded secret
   πŸ’‘ Use secrets.API_SECRET instead of hardcoding
```

---

## Architecture

```
pipechecker/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs          # CLI entry point (clap)
β”‚   β”œβ”€β”€ lib.rs           # Public API β€” audit_file, audit_content, discover_workflows
β”‚   β”œβ”€β”€ models.rs        # Core types β€” Pipeline, Job, Step, Issue, Severity
β”‚   β”œβ”€β”€ error.rs         # Error enum (thiserror)
β”‚   β”œβ”€β”€ config.rs        # .pipecheckerrc.yml loading
β”‚   β”œβ”€β”€ fix.rs           # Auto-fix for action pinning
β”‚   β”œβ”€β”€ tui.rs           # Interactive terminal UI (ratatui + crossterm)
β”‚   β”œβ”€β”€ parsers/
β”‚   β”‚   β”œβ”€β”€ mod.rs       # Provider detection + dispatch
β”‚   β”‚   β”œβ”€β”€ github.rs    # GitHub Actions YAML parser
β”‚   β”‚   β”œβ”€β”€ gitlab.rs    # GitLab CI YAML parser
β”‚   β”‚   └── circleci.rs  # CircleCI YAML parser
β”‚   └── auditors/
β”‚       β”œβ”€β”€ mod.rs       # Module gate
β”‚       β”œβ”€β”€ syntax.rs    # Structural validation
β”‚       β”œβ”€β”€ dag.rs       # Dependency graph + cycle detection (petgraph)
β”‚       β”œβ”€β”€ secrets.rs   # Secret/env var scanning (regex)
β”‚       └── pinning.rs   # Action/Docker image pinning
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ parser_test.rs   # Parser integration tests
β”‚   └── auditors_test.rs # Auditor + fixture tests
└── tests/fixtures/      # Sample workflow files for testing
```

---

## CI/CD Integration

Add PipeChecker to your own CI pipeline:

```yaml
- name: Validate workflows
  run: |
    cargo install pipechecker
    pipechecker --all --strict --format json
```

Or use it as a pre-commit hook (recommended):

```bash
pipechecker --install-hook
```

---

## Development

### Run tests
```bash
cargo test
# 103 tests β€” all passing
```

### Lint & format
```bash
cargo clippy -- -D warnings
cargo fmt -- --check
```

### Coverage
```bash
cargo tarpaulin --fail-under 55
```

---

## License

This project is licensed under either **MIT** or **Apache-2.0** at your option.

```
SPDX: MIT OR Apache-2.0
```

---

<div align="center">

**PipeChecker** β€” *because waiting 10 minutes for CI to tell you about a typo is nobody's idea of fun.*

[Report a bug](https://github.com/Ayyankhan101/PipeCheck/issues) Β· [Request a feature](https://github.com/Ayyankhan101/PipeCheck/issues) Β· [Contributing](docs/CONTRIBUTING.md)

</div>