dg init

Scaffold a configuration file and a GitHub Actions workflow into your project. Run once, commit, and Diff Guardian starts protecting your PRs.


Usage

npx dg init

What gets created

The init command creates two files in your project root:

1. dg.config.json

A minimal configuration file with sensible defaults:

dg.config.json
{
  "baseBranch": "main",
  "failOnWarnings": false
}

See Configuration for all available options.

2. .github/workflows/diff-guardian.yml

A ready-to-use GitHub Actions workflow:

.github/workflows/diff-guardian.yml
name: "Diff-Guardian"

on:
  pull_request:
    branches: [ "main", "master" ]

permissions:
  contents: read
  pull-requests: write

jobs:
  analyze:
    name: API Contract Audit
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install Dependencies
        run: npm ci

      - name: Build WASM Grammars
        run: npm run build:grammars

      - name: Build
        run: npm run build

      - name: Run Diff-Guardian
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
        run: npx dg

Skip behavior

If a file already exists, the init command skips it instead of overwriting. This means you can safely re-run npx dg init without losing any customizations you have made.

$ npx dg init

  Diff-Guardian Init

  [skip] .github/workflows/diff-guardian.yml already exists.
  [created] dg.config.json

  Done. 1 file(s) created, 1 skipped.
  Commit these files and push to activate Diff-Guardian on your PRs.

Next steps

  1. Commit both files: git add -A && git commit -m "chore: add diff-guardian"
  2. Push to trigger the workflow on your next PR
  3. Customize dg.config.json as needed
  4. Set up Git Hooks for local enforcement