Skip to content
Draft
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
112 changes: 112 additions & 0 deletions .github/workflows/generate-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Generate and Validate Schema

on:
push:
branches: [ main, schema-for-programmatic-consumption ]
paths:
- 'techniques/**/*.md'
- 'mitigations/**/*.md'
- 'README.md'
- 'scripts/**/*.py'
- 'schemas/**/*.json'
pull_request:
branches: [ main ]
paths:
- 'techniques/**/*.md'
- 'mitigations/**/*.md'
- 'README.md'
- 'scripts/**/*.py'
- 'schemas/**/*.json'
workflow_dispatch:

jobs:
generate-and-validate:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install jsonschema pyyaml

- name: Parse markdown files to JSON
run: |
python3 scripts/parse_markdown.py --root-dir . --output data/safe-mcp-index.json

- name: Validate schema (non-blocking)
id: validate
continue-on-error: true
run: |
python3 scripts/validate_schema.py --root-dir . --data-file data/safe-mcp-index.json

- name: Check if data files changed
id: check_changes
run: |
git diff --quiet data/ || echo "changed=true" >> $GITHUB_OUTPUT

- name: Upload generated files as artifacts
uses: actions/upload-artifact@v4
with:
name: generated-schema-files
path: |
data/safe-mcp-index.json
retention-days: 90

- name: Create Release with Data Files
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: softprops/action-gh-release@v1
with:
tag_name: latest-data
name: Latest Generated Data
body: |
Auto-generated SAFE-MCP data files from markdown sources.

**Files:**
- `safe-mcp-index.json` - Complete JSON index

**Generated:** ${{ github.event.head_commit.timestamp }}
**Commit:** ${{ github.sha }}
files: |
data/safe-mcp-index.json
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create comment on PR with statistics
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('data/safe-mcp-index.json', 'utf8'));
const jsonSize = fs.statSync('data/safe-mcp-index.json').size;

const body = `## Schema Generation Results

✅ Successfully generated schema files from markdown sources.

### Statistics
- **Tactics**: ${data.metadata.total_tactics}
- **Techniques**: ${data.metadata.total_techniques}
- **Mitigations**: ${data.metadata.total_mitigations}

### File Size
- **JSON**: ${(jsonSize / 1024).toFixed(1)} KB

The generated files are available as workflow artifacts.`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,23 @@ local_settings.py
*.pem
*.p12
secrets/
credentials/
credentials/
# Python
__pycache__/
*.py[cod]
*.class
.Python
*.so

# Virtual environments
venv/
ENV/
env/

# Generated data files (recreated by CI)
data/*.json
data/*.toon

# Keep directory structure
!data/.gitkeep

Empty file added data/.gitkeep
Empty file.
Loading