[Resource]: catchup #344
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 Resource Submission | |
| on: | |
| issues: | |
| types: [opened, edited] | |
| permissions: | |
| contents: read | |
| jobs: | |
| validate-resource: | |
| name: Validate Resource Submission | |
| if: contains(github.event.issue.labels.*.name, 'resource-submission') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v7 | |
| with: | |
| sparse-checkout: | | |
| resources/ | |
| config.yaml | |
| THE_RESOURCES_TABLE_NEW.csv | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pyyaml | |
| - name: Parse and validate submission | |
| env: | |
| ISSUE_BODY: ${{ github.event.issue.body }} | |
| PYTHONPATH: ${{ github.workspace }} | |
| run: | | |
| python -m resources.parse_issue_form --validate 2>&1 | tail -n 1 > validation_result.json | |
| echo "=== Validation Result ===" | |
| python -m json.tool validation_result.json || cat validation_result.json | |
| - name: Remove old validation comments | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.issue.number; | |
| const comments = await github.rest.issues.listComments({ owner, repo, issue_number }); | |
| for (const c of comments.data) { | |
| if (c.user.type === 'Bot' && c.body.includes('## 🤖 Validation Results')) { | |
| await github.rest.issues.deleteComment({ owner, repo, comment_id: c.id }); | |
| } | |
| } | |
| - name: Post validation results | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const result = JSON.parse(fs.readFileSync('validation_result.json', 'utf8')); | |
| let body = '## 🤖 Validation Results\n\n'; | |
| if (result.valid) { | |
| body += '✅ **All validation checks passed!** Your submission is ready for a maintainer to review.\n\n'; | |
| body += '### Parsed data\n```json\n' + JSON.stringify(result.data, null, 2) + '\n```\n'; | |
| } else { | |
| body += '❌ **Validation failed.** Please fix the following and edit your issue:\n\n'; | |
| for (const e of result.errors) body += `- ❗ ${e}\n`; | |
| } | |
| if (result.warnings && result.warnings.length) { | |
| body += '\n### Warnings\n'; | |
| for (const w of result.warnings) body += `- ⚠️ ${w}\n`; | |
| } | |
| body += '\n---\n<sub>Re-runs automatically when you edit the issue.</sub>'; | |
| await github.rest.issues.createComment({ ...context.repo, issue_number: context.issue.number, body }); | |
| - name: Update issue labels | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const result = JSON.parse(fs.readFileSync('validation_result.json', 'utf8')); | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.issue.number; | |
| const { data: issue } = await github.rest.issues.get({ owner, repo, issue_number }); | |
| let labels = issue.labels.map(l => l.name).filter(l => | |
| !['validation-passed', 'validation-failed', 'validation-pending'].includes(l)); | |
| labels.push(result.valid ? 'validation-passed' : 'validation-failed'); | |
| await github.rest.issues.setLabels({ owner, repo, issue_number, labels }); | |
| - name: Cleanup | |
| if: always() | |
| run: rm -f validation_result.json |