GitHub Action

FakeDataDSL provides a reusable GitHub Action for CI/CD pipelines. Validate schemas, generate data, run diff checks, and more directly in your workflows.

Quick Start

# .github/workflows/schemas.yml
name: Schema Validation

on: [push, pull_request]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: fake-data-dsl/action@v1
        with:
          command: validate
          schema_dir: schemas/

Available Commands

validate

Validate all schemas for syntax errors:

- uses: fake-data-dsl/action@v1
  with:
    command: validate
    schema_dir: schemas/
    strict: true  # Fail on warnings too

lint

Run linter checks on schemas:

- uses: fake-data-dsl/action@v1
  with:
    command: lint
    schema_dir: schemas/
    config: .fake_data_dsl.yml

diff

Check for breaking changes between schema versions:

- uses: fake-data-dsl/action@v1
  with:
    command: diff
    base_ref: ${{ github.base_ref }}
    head_ref: ${{ github.head_ref }}
    schema_dir: schemas/
    breaking_only: true

generate

Generate sample data for testing:

- uses: fake-data-dsl/action@v1
  with:
    command: generate
    schema: User
    count: 100
    output: test_data/users.json
    seed: 42

export

Export schemas to other formats:

- uses: fake-data-dsl/action@v1
  with:
    command: export
    schema_dir: schemas/
    format: openapi
    output: docs/openapi.yaml

test

Run schema-related tests:

- uses: fake-data-dsl/action@v1
  with:
    command: test
    schema_dir: schemas/
    test_dir: spec/schemas/

Input Parameters

Input Description Default
command Command to run validate
schema_dir Schema directory schemas/
schema Specific schema name -
config Config file path .fake_data_dsl.yml
output Output file path -
format Export format -
count Number of records 10
seed Random seed -
mode Generation mode random
strict Strict validation false
breaking_only Only report breaking changes false
base_ref Base Git ref for diff -
head_ref Head Git ref for diff -
ruby_version Ruby version 3.2

Output Variables

Output Description
valid Whether schemas are valid
warnings Number of warnings
errors Number of errors
breaking_changes Number of breaking changes
generated_file Path to generated file

Examples

Complete CI Workflow

name: Schema CI

on:
  push:
    branches: [main]
  pull_request:
    paths:
      - 'schemas/**'
      - '.github/workflows/schemas.yml'

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Validate Schemas
        uses: fake-data-dsl/action@v1
        with:
          command: validate
          schema_dir: schemas/
          strict: true

  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Lint Schemas
        uses: fake-data-dsl/action@v1
        with:
          command: lint
          schema_dir: schemas/

  breaking-changes:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Check Breaking Changes
        id: diff
        uses: fake-data-dsl/action@v1
        with:
          command: diff
          schema_dir: schemas/
          base_ref: ${{ github.base_ref }}
          head_ref: ${{ github.head_ref }}
          breaking_only: true

      - name: Comment on PR
        if: steps.diff.outputs.breaking_changes > 0
        uses: actions/github-script@v6
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: '⚠️ Breaking schema changes detected!'
            })

  generate-docs:
    runs-on: ubuntu-latest
    needs: [validate, lint]
    if: github.ref == 'refs/heads/main'
    steps:
      - uses: actions/checkout@v4

      - name: Generate OpenAPI
        uses: fake-data-dsl/action@v1
        with:
          command: export
          schema_dir: schemas/
          format: openapi
          output: docs/api/openapi.yaml

      - name: Generate TypeScript Types
        uses: fake-data-dsl/action@v1
        with:
          command: export
          schema_dir: schemas/
          format: typescript
          output: frontend/src/types/schemas.ts

      - name: Commit Generated Files
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "chore: regenerate schema exports"
          file_pattern: "docs/api/* frontend/src/types/*"

Generate Test Data

name: Generate Test Data

on:
  workflow_dispatch:
    inputs:
      schema:
        description: 'Schema name'
        required: true
      count:
        description: 'Number of records'
        default: '1000'

jobs:
  generate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Generate Data
        uses: fake-data-dsl/action@v1
        with:
          command: generate
          schema: ${{ inputs.schema }}
          count: ${{ inputs.count }}
          output: test_data/${{ inputs.schema }}.json
          seed: 42

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: test-data
          path: test_data/

Schema Release

name: Schema Release

on:
  push:
    tags:
      - 'schema-v*'

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Validate
        uses: fake-data-dsl/action@v1
        with:
          command: validate
          schema_dir: schemas/
          strict: true

      - name: Export All Formats
        uses: fake-data-dsl/action@v1
        with:
          command: export
          schema_dir: schemas/
          format: all
          output: dist/

      - name: Create Release
        uses: softprops/action-gh-release@v1
        with:
          files: |
            dist/openapi.yaml
            dist/schemas.ts
            dist/schemas.proto
            dist/schemas.json

Configuration File

Create .fake_data_dsl.yml for action configuration:

# .fake_data_dsl.yml
schema_dir: schemas/
strict: true

validation:
  require_descriptions: true
  max_depth: 10

lint:
  rules:
    - naming_convention
    - required_fields
    - type_consistency

diff:
  breaking_changes:
    - field_removed
    - type_changed
    - required_added

  warnings:
    - field_added
    - optional_to_required

export:
  openapi:
    version: "3.1.0"
    info:
      title: "My API"
      version: "1.0.0"

  typescript:
    style: interface
    export_style: named

Self-Hosted Runner

For private schemas or faster builds:

jobs:
  validate:
    runs-on: self-hosted
    container:
      image: ruby:3.2
    steps:
      - uses: actions/checkout@v4

      - name: Install FakeDataDSL
        run: gem install fake_data_dsl

      - name: Validate
        run: fake_data_dsl validate schemas/

Troubleshooting

Action Not Found

Make sure you're using the correct action reference:

# Correct
- uses: fake-data-dsl/action@v1

# Or from GitHub Marketplace
- uses: fake-data-dsl/fake-data-dsl-action@v1

Schema Validation Errors

Check the action output for details:

- name: Validate
  id: validate
  uses: fake-data-dsl/action@v1
  with:
    command: validate
    schema_dir: schemas/

- name: Show Errors
  if: failure()
  run: echo "${{ steps.validate.outputs.errors }}"

Permission Issues

For actions that write files:

permissions:
  contents: write  # For committing generated files

jobs:
  generate:
    # ...

See Also