Comment DEFI@home validation result #119
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: Comment DEFI@home validation result | |
| on: | |
| workflow_run: | |
| workflows: ["Validate DEFI@home submission"] | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| comment: | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.event == 'pull_request' | |
| steps: | |
| - name: Download validation artifact | |
| id: download | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.payload.workflow_run.id, | |
| }); | |
| const match = artifacts.data.artifacts.find((a) => a.name === 'validate-report'); | |
| if (!match) { | |
| core.info('no validate-report artifact found; nothing to comment on'); | |
| core.setOutput('found', 'false'); | |
| return; | |
| } | |
| const dl = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: match.id, | |
| archive_format: 'zip', | |
| }); | |
| fs.writeFileSync('validate-report.zip', Buffer.from(dl.data)); | |
| core.setOutput('found', 'true'); | |
| - name: Unzip artifact | |
| if: steps.download.outputs.found == 'true' | |
| run: unzip -o validate-report.zip | |
| - name: Post PR comment and labels | |
| if: steps.download.outputs.found == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const report = JSON.parse(fs.readFileSync('validate-report.json', 'utf8')); | |
| const meta = JSON.parse(fs.readFileSync('validate-meta.json', 'utf8')); | |
| const prNumber = parseInt(fs.readFileSync('pr-number.txt', 'utf8').trim(), 10); | |
| const ok = report.ok; | |
| const lines = []; | |
| lines.push(ok ? '✅ **DEFI@home validator — all submissions valid**' : '❌ **DEFI@home validator — issues found**'); | |
| lines.push(''); | |
| for (const r of report.reports) { | |
| lines.push(`### \`${r.file}\``); | |
| if (r.errors.length) { | |
| lines.push('**errors:**'); | |
| for (const e of r.errors) lines.push(`- ${e}`); | |
| } | |
| if (r.warnings.length) { | |
| lines.push('**warnings:**'); | |
| for (const w of r.warnings) lines.push(`- ${w}`); | |
| } | |
| if (r.autoFixed.length) { | |
| lines.push('**auto-fixes applied:**'); | |
| for (const a of r.autoFixed) lines.push(`- ${a}`); | |
| } | |
| if (!r.errors.length && !r.warnings.length && !r.autoFixed.length) { | |
| lines.push('_clean_'); | |
| } | |
| lines.push(''); | |
| } | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: lines.join('\n'), | |
| }); | |
| const labels = ['submission']; | |
| if (meta.slice) labels.push(`slice:${meta.slice}`); | |
| const model = (meta.model || '').toLowerCase(); | |
| if (model.includes('claude')) labels.push('model-family:claude'); | |
| else if (model.includes('gpt') || model.includes('openai')) labels.push('model-family:gpt'); | |
| else if (model.includes('gemini')) labels.push('model-family:gemini'); | |
| else if (model) labels.push('model-family:other'); | |
| if (meta.chat_url) labels.push('chat-url-included'); | |
| if (meta.ok) labels.push('awaiting-quorum'); | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| labels: [...new Set(labels)], | |
| }); |