Merge pull request #1 from mrbalov/agent/fix-specs-20961506630 #31
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: Validate Specs | |
| on: | |
| pull_request: | |
| paths: | |
| - "specs/**/*.spec.md" | |
| - "packages/validate-specs/**" | |
| - ".github/workflows/validate-specs.yml" | |
| - ".github/workflows/fix-specs.yml" | |
| push: | |
| branches: [ main ] | |
| paths: | |
| - "specs/**/*.spec.md" | |
| - "packages/validate-specs/**" | |
| - ".github/workflows/validate-specs.yml" | |
| - ".github/workflows/fix-specs.yml" | |
| jobs: | |
| validate-specs: | |
| name: Validate Specs | |
| runs-on: self-hosted | |
| outputs: | |
| validation-status: ${{ steps.validation.outputs.result }} | |
| validation-summary-json: ${{ steps.expose-validation-summary-json.outputs.validation_summary_json }} | |
| permissions: | |
| contents: read | |
| env: | |
| DIAL_KEY: ${{ secrets.DIAL_KEY }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| - name: Setup bun | |
| uses: oven-sh/setup-bun@v1 | |
| with: | |
| bun-version: latest | |
| - name: Ensure jq is available | |
| run: | | |
| if ! command -v jq >/dev/null 2>&1; then | |
| sudo apt-get update | |
| sudo apt-get install -y jq | |
| fi | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Run specs validation | |
| run: | | |
| mkdir -p .specs-validation | |
| touch .specs-validation/result.json | |
| bun run validate-specs > .specs-validation/result.json | |
| - name: Expose validation result JSON (as base64) | |
| id: expose-validation-summary-json | |
| run: | | |
| SUMMARY_B64=$(base64 < .specs-validation/result.json | tr -d '\n') | |
| echo "validation_summary_json=$SUMMARY_B64" >> "$GITHUB_OUTPUT" | |
| - name: Parse validation result | |
| id: validation | |
| run: | | |
| RESULT=$(jq -r '.result' .specs-validation/result.json) | |
| INVALID_COUNT=$(jq '[.violations[] | select(.severity=="INVALID")] | length' .specs-validation/result.json) | |
| CONDITIONAL_COUNT=$(jq '[.violations[] | select(.severity=="CONDITIONAL")] | length' .specs-validation/result.json) | |
| echo "result=$RESULT" >> "$GITHUB_OUTPUT" | |
| echo "invalid_count=$INVALID_COUNT" >> "$GITHUB_OUTPUT" | |
| echo "conditional_count=$CONDITIONAL_COUNT" >> "$GITHUB_OUTPUT" | |
| - name: Render validation summary | |
| if: always() | |
| run: | | |
| { | |
| echo "# 📋 Specs Validation Result" | |
| echo "" | |
| echo "| Metric | Value |" | |
| echo "|-------|-------|" | |
| echo "| Result | **${{ steps.validation.outputs.result }}** |" | |
| echo "| Critical violations | ${{ steps.validation.outputs.invalid_count }} |" | |
| echo "| Conditional violations | ${{ steps.validation.outputs.conditional_count }} |" | |
| echo "" | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| - name: Render validation violations | |
| if: steps.validation.outputs.result != 'VALID' | |
| run: | | |
| echo "## ❌ Violations" >> "$GITHUB_STEP_SUMMARY" | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "| Spec | Rule | Severity | Description |" >> "$GITHUB_STEP_SUMMARY" | |
| echo "|------|------|----------|-------------|" >> "$GITHUB_STEP_SUMMARY" | |
| jq -r '.violations[] | | |
| "| \(.spec_id // "global") | \(.rule) | **\(.severity)** | \(.description) |" | |
| ' .specs-validation/result.json >> "$GITHUB_STEP_SUMMARY" | |
| fix-specs: | |
| name: Fix Specs | |
| needs: validate-specs | |
| if: needs.validate-specs.outputs.validation-status == 'INVALID' | |
| uses: ./.github/workflows/fix-specs.yml | |
| secrets: inherit | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| with: | |
| summary: ${{ needs.validate-specs.outputs.validation-summary-json }} | |
| finally: | |
| name: Finalize Specs Validation | |
| needs: [validate-specs, fix-specs] | |
| runs-on: self-hosted | |
| steps: | |
| - name: Fail pipeline on failed validation | |
| if: needs.validate-specs.outputs.validation-status == 'INVALID' | |
| run: | | |
| echo "❌ Specs validation failed! Please review the validation summary above and address the issues." | |
| echo "🤖 Or realy on the agent which already tries to fix the issues." | |
| exit 1 |