A GitHub Action to run Spectr
GitHub Action for validating spec-driven development projects using Spectr
This action automatically validates your specification-driven codebase by running spectr validate --all --json and reporting issues as GitHub annotations.
Spectr is a spec-driven development tool that helps teams maintain consistency between specifications and implementations. It enforces that all changes are properly documented through proposals, specifications, and structured deltas.
This action:
- Installs the specified version of Spectr (or latest)
- Runs comprehensive validation on your
spectr/directory - Creates GitHub annotations for any errors, warnings, or info messages
- Fails the workflow if validation errors or warnings are found
- Provides detailed file locations and line numbers for issues
Use this action as part of your CI/CD pipeline for projects that follow spec-driven development:
- On every pull request to validate proposed changes
- On push to main/master to ensure spec integrity
- As a required status check before merging
- In combination with other validation steps
Add this to your workflow file (e.g., .github/workflows/spectr.yml):
name: Spectr Validation
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: connerohnesorge/spectr-action@v1That's it! The action will use the latest version of Spectr.
Description: The version of Spectr to use (e.g., 0.1.0).
Required: No
Default: latest
Description: GitHub token used to increase rate limits when retrieving versions and downloading Spectr. Uses the default GitHub Actions token automatically.
Required: No
Default: ${{ github.token }}
Description: Enable GitHub Issues sync for change proposals. When enabled, creates GitHub Issues for each active change proposal and keeps them synchronized.
Required: No
Default: false
Description: Comma-separated labels to apply to synced issues.
Required: No
Default: spectr,change-proposal
Description: Prefix for issue titles.
Required: No
Default: [Spectr Change]
Description: Close issues when changes are archived. Set to false to keep issues open when the associated change is archived.
Required: No
Default: true
Description: Update existing issues when proposal content changes. Set to false to skip updates.
Required: No
Default: true
Description: Label used to identify Spectr-managed issues.
Required: No
Default: spectr-managed
Description: The version of Spectr that was installed and used for validation.
Description: Number of GitHub Issues created during sync (only when sync-issues is enabled).
Description: Number of GitHub Issues updated during sync (only when sync-issues is enabled).
Description: Number of GitHub Issues closed during sync (archived changes, only when sync-issues is enabled).
Description: Total number of active change proposals discovered (only when sync-issues is enabled).
Example usage:
- uses: connerohnesorge/spectr-action@v1
id: spectr
- name: Print version
run: echo "Used Spectr version ${{ steps.spectr.outputs.spectr-version }}"The action automatically creates GitHub annotations for all validation issues:
- Errors (red): Critical problems that must be fixed
- Warnings (yellow): Issues that should be addressed
- Info (blue): Informational messages
Each annotation includes:
- File path relative to repository root
- Line number where the issue occurs
- Clear description of the problem
- Suggested fixes (when applicable)
Annotations appear:
- In the workflow run logs
- On the "Files changed" tab in pull requests
- In the GitHub UI wherever the file is displayed
The simplest way to get started - validates on every push and pull request:
name: Spectr Validation
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: connerohnesorge/spectr-action@v1Pin to a specific Spectr version for consistency:
name: Spectr Validation
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: connerohnesorge/spectr-action@v1
with:
version: "0.1.0"Full production-ready workflow with proper triggers and permissions:
name: Validate Spectr
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
checks: write
jobs:
validate:
name: Validate Specifications
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate specs with Spectr
uses: connerohnesorge/spectr-action@v1
id: spectr
with:
version: latest
- name: Print validation summary
if: always()
run: |
echo "Spectr version used: ${{ steps.spectr.outputs.spectr-version }}"
echo "Validation complete"Run validation only on pull requests to specific branches:
name: PR Validation
on:
pull_request:
branches: [main, develop]
jobs:
validate-specs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: connerohnesorge/spectr-action@v1
with:
version: "0.1.0"
github-token: ${{ secrets.GITHUB_TOKEN }}Capture and use the Spectr version output:
name: Validation with Outputs
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Spectr validation
uses: connerohnesorge/spectr-action@v1
id: spectr
with:
version: latest
- name: Display version info
run: echo "Used Spectr version ${{ steps.spectr.outputs.spectr-version }}"
- name: Conditional step based on validation
if: success()
run: echo "Validation passed, ready to merge!"Enable automatic GitHub Issues sync for change proposals:
name: Spectr Validation with Issue Sync
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
checks: write
issues: write # Required for issue sync
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: connerohnesorge/spectr-action@v1
id: spectr
with:
sync-issues: "true"
issue-labels: "spectr,change-proposal,tracking"
issue-title-prefix: "[Change Proposal]"
- name: Report sync results
if: always()
run: |
echo "Issues created: ${{ steps.spectr.outputs.issues-created }}"
echo "Issues updated: ${{ steps.spectr.outputs.issues-updated }}"
echo "Issues closed: ${{ steps.spectr.outputs.issues-closed }}"
echo "Total changes: ${{ steps.spectr.outputs.total-changes }}"A complete production workflow showing best practices:
name: Validate Spectr
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
checks: write
pull-requests: read
jobs:
validate:
name: Validate Specifications
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better analysis
- name: Run Spectr validation
uses: connerohnesorge/spectr-action@v1
id: spectr-validate
with:
version: latest
github-token: ${{ github.token }}
- name: Report validation results
if: always()
run: |
echo "Validation completed"
echo "Spectr version: ${{ steps.spectr-validate.outputs.spectr-version }}"
if [ "${{ job.status }}" == "success" ]; then
echo "All specs are valid!"
else
echo "Validation failed - check annotations for details"
exit 1
fiThe issue sync feature automatically creates and maintains GitHub Issues for your change proposals. This provides better visibility, enables discussion via issue comments, and integrates with GitHub's existing PR linking (Fixes #N).
- Discovery: Scans
spectr/changes/for active proposals withproposal.md - Creation: Creates a GitHub Issue for each new change proposal
- Tracking: Uses a hidden HTML marker (
<!-- spectr-change-id:ID -->) to link issues to changes - Updates: Syncs content changes when
proposal.mdortasks.mdis modified - Closure: Closes issues when changes are archived to
spectr/changes/archive/
When using issue sync, your workflow needs the issues: write permission:
permissions:
contents: read
issues: writeEach synced issue includes:
- The full content of
proposal.md - List of affected specs (from the
specs/subdirectory) - Tasks from
tasks.mdortasks.json(if present) - A footer indicating the issue is managed by Spectr
By default, issues are created with these labels:
spectr- Indicates Spectr-related contentchange-proposal- Marks it as a change proposalspectr-managed- Used internally to identify managed issues
You can customize labels using the issue-labels and spectr-label inputs.
Once issues are created, you can link PRs to them using GitHub's standard syntax:
Fixes #123
Closes #123
Resolves #123
This will automatically close the issue when the PR is merged.
The action outputs validation results in the workflow logs:
✓ Spec validation passed
- 12 specs validated
- 3 active changes validated
- 0 errors, 0 warnings
Or when issues are found:
✗ Spec validation failed
- 12 specs validated
- 3 active changes validated
- 2 errors, 1 warning
Errors:
spectr/changes/add-new-feature/specs/auth/spec.md:15
Missing required scenario for requirement
Warnings:
spectr/specs/api/spec.md:42
Scenario formatting recommendation
- Workflow Run: Click on the failed job to see annotated files
- Files Changed (in PRs): Annotations appear inline next to the code
- Commit Status: The action sets commit status with validation results
-
Error: Validation rule violation that must be fixed
- Missing required sections
- Invalid spec format
- Broken references
-
Warning: Best practice violations that should be addressed
- Formatting recommendations
- Potential improvements
- Style inconsistencies
-
Info: Helpful information
- Successful validations
- Suggestions for improvement
Problem: The action can't find or download Spectr.
Solutions:
- Check if the specified version exists
- Verify network connectivity to GitHub releases
- Try specifying
version: "latest" - Check if the
github-tokenhas sufficient permissions
- uses: connerohnesorge/spectr-action@v1
with:
version: "latest"
github-token: ${{ secrets.GITHUB_TOKEN }}Problem: Environment variables not set correctly.
Solutions:
- Ensure you're using
actions/checkout@v4before this action - Verify you're running on a supported runner (ubuntu-latest, macos-latest, windows-latest)
- Check that the workflow has proper permissions
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Required!
- uses: connerohnesorge/spectr-action@v1Problem: Spectr output format changed or is invalid.
Solutions:
- Update to the latest action version
- Check the spectr version compatibility
- Run
spectr validate --all --jsonlocally to debug
- uses: connerohnesorge/spectr-action@v1 # Uses latest action
with:
version: "0.1.0" # Use known good spectr versionProblem: The action can't find your spectr/ directory.
Solutions:
- Verify
spectr/directory exists in repository root - Ensure you've checked out the repository with
actions/checkout@v4 - Check that
spectr/contains proper structure:spectr/specs/for current specificationsspectr/changes/for active change proposalsspectr/project.mdfor project configuration
Expected structure:
repository-root/
├── .github/
│ └── workflows/
│ └── spectr.yml
├── spectr/
│ ├── project.md
│ ├── specs/
│ │ └── [capability]/
│ │ └── spec.md
│ └── changes/
│ └── [change-name]/
│ ├── proposal.md
│ └── specs/
└── ...
Problem: The action reports errors on specs that appear correct.
Solutions:
- Run
spectr validate --alllocally to see detailed output - Check for invisible characters or formatting issues
- Verify spec format follows Spectr conventions (see Spectr documentation)
- Ensure all requirements have at least one scenario with
#### Scenario:format
Problem: The action takes a long time to complete.
Solutions:
- Pin to a specific Spectr version instead of using
latest(caches better) - Reduce the number of specs/changes being validated
- Split validation across multiple jobs if you have many specs
- uses: connerohnesorge/spectr-action@v1
with:
version: "0.1.0" # Cached after first downloadFor this action to work properly, your project must:
- Have a
spectr/directory in the repository root - Contain valid spec structure:
spectr/project.md- Project conventionsspectr/specs/- Current specificationsspectr/changes/- Active change proposals (optional)
- Be a git repository (required by GitHub Actions)
- Use the
actions/checkoutaction before spectr-action
Minimal valid structure:
repository-root/
├── spectr/
│ ├── project.md
│ └── specs/
│ └── example-capability/
│ └── spec.md
└── .github/
└── workflows/
└── spectr.yml
Issues and pull requests are welcome at the spectr-action repository.
For issues with the Spectr tool itself, see the main Spectr repository.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Spectr - The spec-driven development CLI tool
- Spectr Documentation - Full documentation and guides