|
| 1 | +name: Extension Validation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - 5.* |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + validate-extensions: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 30 |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 20 | + with: |
| 21 | + fetch-depth: 0 # Fetch full history for git diff |
| 22 | + |
| 23 | + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 |
| 24 | + with: |
| 25 | + python-version: "3.12" |
| 26 | + |
| 27 | + - name: Configure git |
| 28 | + run: | |
| 29 | + git config --global user.email "[email protected]" |
| 30 | + git config --global user.name "GitHub Action" |
| 31 | +
|
| 32 | + - name: Install dependencies |
| 33 | + run: | |
| 34 | + python -m pip install --upgrade pip |
| 35 | + echo "Installing dependencies from requirements.txt:" |
| 36 | + cat scripts/requirements.txt |
| 37 | + pip install -r scripts/requirements.txt |
| 38 | + echo "Verifying installed packages:" |
| 39 | + pip list | grep -E "(jsonschema|requests)" |
| 40 | +
|
| 41 | + - name: Run repository structure validation |
| 42 | + id: structure-validation |
| 43 | + continue-on-error: true |
| 44 | + run: | |
| 45 | + mkdir -p /tmp/validation-reports |
| 46 | + python scripts/check_repository_structure.py \ |
| 47 | + > /tmp/validation-reports/repository-structure-report.md |
| 48 | +
|
| 49 | + - name: Get changed files |
| 50 | + run: | |
| 51 | + echo "Event: ${{ github.event_name }}" |
| 52 | + mkdir -p /tmp/validation-reports |
| 53 | + if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 54 | + # For pull requests, compare against the base branch |
| 55 | + BASE_REF="${{ github.event.pull_request.base.ref }}" |
| 56 | + echo "Base ref: $BASE_REF" |
| 57 | + git diff --name-only "origin/$BASE_REF"...HEAD > /tmp/validation-reports/changed_files.txt 2>/dev/null |
| 58 | + else |
| 59 | + # For pushes, compare against the previous commit or get all JSON files if it's the first commit |
| 60 | + git diff --name-only HEAD~1 HEAD > /tmp/validation-reports/changed_files.txt 2>/dev/null |
| 61 | + fi |
| 62 | + echo "Changed JSON files:" |
| 63 | + cat /tmp/validation-reports/changed_files.txt |
| 64 | +
|
| 65 | + - name: Run extension validation |
| 66 | + id: extension-validation |
| 67 | + continue-on-error: true |
| 68 | + run: | |
| 69 | + mkdir -p /tmp/validation-reports |
| 70 | + python scripts/check_description_files.py \ |
| 71 | + $(cat /tmp/validation-reports/changed_files.txt | tr '\n' ' ') \ |
| 72 | + > /tmp/validation-reports/extension-validation-report.md |
| 73 | +
|
| 74 | + - name: Combine validation reports and display summary |
| 75 | + if: always() |
| 76 | + run: | |
| 77 | + mkdir -p /tmp/validation-reports |
| 78 | + if [ -f /tmp/validation-reports/repository-structure-report.md ]; then |
| 79 | + cat /tmp/validation-reports/repository-structure-report.md >> /tmp/validation-reports/validation-report.md |
| 80 | + else |
| 81 | + echo "❌ Repository structure validation report not generated" >> /tmp/validation-reports/validation-report.md |
| 82 | + fi |
| 83 | + echo "" >> /tmp/validation-reports/validation-report.md |
| 84 | + if [ -f /tmp/validation-reports/extension-validation-report.md ]; then |
| 85 | + cat /tmp/validation-reports/extension-validation-report.md >> /tmp/validation-reports/validation-report.md |
| 86 | + else |
| 87 | + echo "❌ Extension validation report not generated" >> /tmp/validation-reports/validation-report.md |
| 88 | + fi |
| 89 | + if [ -f /tmp/validation-reports/validation-report.md ]; then |
| 90 | + cat /tmp/validation-reports/validation-report.md >> $GITHUB_STEP_SUMMARY |
| 91 | + else |
| 92 | + echo "❌ Validation report not generated" >> $GITHUB_STEP_SUMMARY |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: Upload validation reports |
| 96 | + if: always() |
| 97 | + uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 |
| 98 | + with: |
| 99 | + name: validation-reports |
| 100 | + path: | |
| 101 | + /tmp/validation-reports/validation-report.md |
| 102 | + /tmp/validation-reports/repository-structure-report.md |
| 103 | + /tmp/validation-reports/extension-validation-report.md |
| 104 | + /tmp/validation-reports/changed_files.txt |
| 105 | + retention-days: 30 |
| 106 | + |
| 107 | + - name: Comment PR with report |
| 108 | + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && always() |
| 109 | + uses: actions/github-script@e69ef5462fd455e02edcaf4dd7708eda96b9eda0 # v7.0.1 |
| 110 | + with: |
| 111 | + script: | |
| 112 | + const fs = require('fs'); |
| 113 | +
|
| 114 | + // Check if validation report exists |
| 115 | + if (!fs.existsSync('/tmp/validation-reports/validation-report.md')) { |
| 116 | + console.log('Validation report not found'); |
| 117 | + return; |
| 118 | + } |
| 119 | +
|
| 120 | + const report = fs.readFileSync('/tmp/validation-reports/validation-report.md', 'utf8'); |
| 121 | +
|
| 122 | + // Find existing comment using the HTML comment marker |
| 123 | + const { data: comments } = await github.rest.issues.listComments({ |
| 124 | + owner: context.repo.owner, |
| 125 | + repo: context.repo.repo, |
| 126 | + issue_number: context.issue.number, |
| 127 | + }); |
| 128 | +
|
| 129 | + const botComment = comments.find(comment => |
| 130 | + comment.body.includes('<!-- extension-validation-report -->') |
| 131 | + ); |
| 132 | +
|
| 133 | + const commentBody = '<!-- extension-validation-report -->\n' + |
| 134 | + '# Extension Validation Report\n\n' + |
| 135 | + report + '\n\n' + |
| 136 | + '***\n' + |
| 137 | + '*This report was automatically generated by the Extension Validation workflow and it is updated automatically when files are modified.*'; |
| 138 | +
|
| 139 | + if (botComment) { |
| 140 | + console.log('Updating existing comment with ID:', botComment.id); |
| 141 | + // Update existing comment |
| 142 | + await github.rest.issues.updateComment({ |
| 143 | + owner: context.repo.owner, |
| 144 | + repo: context.repo.repo, |
| 145 | + comment_id: botComment.id, |
| 146 | + body: commentBody |
| 147 | + }); |
| 148 | + } else { |
| 149 | + console.log('Creating new comment'); |
| 150 | + // Create new comment |
| 151 | + await github.rest.issues.createComment({ |
| 152 | + owner: context.repo.owner, |
| 153 | + repo: context.repo.repo, |
| 154 | + issue_number: context.issue.number, |
| 155 | + body: commentBody |
| 156 | + }); |
| 157 | + } |
| 158 | +
|
| 159 | + - name: Check validation results |
| 160 | + if: always() |
| 161 | + run: | |
| 162 | + echo "Checking validation results..." |
| 163 | + STRUCTURE_RESULT="${{ steps.structure-validation.outcome }}" |
| 164 | + EXTENSION_RESULT="${{ steps.extension-validation.outcome }}" |
| 165 | +
|
| 166 | + echo "Repository structure validation: $STRUCTURE_RESULT" |
| 167 | + echo "Extension validation: $EXTENSION_RESULT" |
| 168 | +
|
| 169 | + if [ "$STRUCTURE_RESULT" != "success" ] || [ "$EXTENSION_RESULT" != "success" ]; then |
| 170 | + echo "❌ One or more validation steps failed" |
| 171 | + exit 1 |
| 172 | + else |
| 173 | + echo "✅ All validation steps passed" |
| 174 | + fi |
0 commit comments