Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
BASE_REF="origin/${{ github.base_ref }}"
HEAD_REF="HEAD"
echo "Comparing API surface: $BASE_REF..$HEAD_REF"
node dist/cli.js "$BASE_REF..$HEAD_REF" --entrypoint src/index.ts || true
node dist/cli.js "$BASE_REF..$HEAD_REF" --entrypoint src/index.ts --check
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ npx sigdiff --entrypoint src/index.ts

# JSON output
npx sigdiff --json

# Exit with code 1 if breaking changes are detected (useful for CI)
npx sigdiff --check
```

## Example output
Expand Down Expand Up @@ -67,6 +70,18 @@ Changes are classified as `major`, `minor`, or `patch` per semver rules.
| Config required | None | Yes | Yes | Yes |
| Git ref comparison | Any ref | N/A | N/A | Baseline file |

## CI integration

Use `--check` to fail your pipeline when breaking changes are introduced:

```yaml
# .github/workflows/ci.yml
- name: API surface check
run: npx sigdiff origin/main..HEAD --entrypoint src/index.ts --check
```

Without `--check`, sigdiff always exits 0 and just prints the diff. With `--check`, it exits 1 if any breaking changes are detected, making it easy to gate PRs.

## Programmatic API

```typescript
Expand Down
11 changes: 9 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ cli
.command('[range]', 'Diff the public API surface between two git refs')
.option('--entrypoint <path>', 'Scope to a specific file')
.option('--json', 'Output as JSON instead of markdown')
.action((range: string | undefined, options: { entrypoint?: string; json?: boolean }) => {
.option('--check', 'Exit with code 1 if breaking changes are detected')
.action(
(range: string | undefined, options: { entrypoint?: string; json?: boolean; check?: boolean }) => {
try {
assertGitRepo();

Expand All @@ -28,14 +30,19 @@ cli
const output = format(result, { json: options.json });

process.stdout.write(output);

if (options.check && result.breaking.length > 0) {
process.exit(1);
}
} catch (err) {
if (err instanceof SigdiffException) {
process.stderr.write(`Error: ${err.error.message}\n`);
process.exit(1);
}
throw err;
}
});
},
);

cli.help();
cli.version(pkgVersion);
Expand Down
Loading