feat: Add Guardrails System + Code Review Fixes #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Contract Validation | |
| on: | |
| pull_request: | |
| paths: | |
| - 'backend/api/openapi_spec.yaml' | |
| - 'frontend/src/**' | |
| - 'backend/api/src/main/python/openapi_server/impl/**' | |
| push: | |
| branches: [main, dev] | |
| jobs: | |
| validate-contracts: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install Python dependencies | |
| run: | | |
| pip install pyyaml | |
| - name: Run Contract Validation | |
| run: | | |
| ./scripts/validate_contracts.sh | |
| - name: Check for critical mismatches | |
| run: | | |
| # Fail if critical mismatches found | |
| if grep -q "❌ Misaligned: [1-9]" validation-reports/*/contract_report.md; then | |
| echo "❌ Contract validation failed with critical mismatches" | |
| exit 1 | |
| fi | |
| echo "✅ Contract validation passed" | |
| - name: Upload validation report | |
| if: always() | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: contract-validation-report | |
| path: validation-reports/ | |
| - name: Comment on PR | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const glob = require('@actions/glob'); | |
| // Find the latest report | |
| const globber = await glob.create('validation-reports/contract_val_*/contract_report.md'); | |
| const files = await globber.glob(); | |
| if (files.length === 0) { | |
| console.log('No validation report found'); | |
| return; | |
| } | |
| // Read the most recent report | |
| const reportPath = files[files.length - 1]; | |
| const report = fs.readFileSync(reportPath, 'utf8'); | |
| // Extract summary (first 50 lines) | |
| const summary = report.split('\n').slice(0, 50).join('\n'); | |
| // Post comment | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.name, | |
| body: `## 📋 Contract Validation Results\n\n${summary}\n\n[View full report in artifacts]` | |
| }); |