Check Spec Updates #30
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: Check Spec Updates | |
| on: | |
| schedule: | |
| # Run daily at 08:00 UTC (every day) | |
| - cron: "0 8 * * *" | |
| workflow_dispatch: # Allow manual trigger | |
| permissions: | |
| issues: write | |
| contents: read | |
| jobs: | |
| check-updates: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: pip install pyyaml | |
| - name: Check for spec updates | |
| id: check | |
| run: | | |
| python scripts/check_spec_updates.py --full --json > /tmp/spec_report.json 2>&1 || true | |
| cat /tmp/spec_report.json | |
| echo "report<<EOF" >> $GITHUB_OUTPUT | |
| cat /tmp/spec_report.json >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| # Set has_updates flag | |
| HAS_UPDATES=$(python -c "import json; r=json.load(open('/tmp/spec_report.json')); print('true' if r.get('has_updates') else 'false')") | |
| echo "has_updates=$HAS_UPDATES" >> $GITHUB_OUTPUT | |
| - name: Create issue if updates found | |
| if: steps.check.outputs.has_updates == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const report = JSON.parse(`${{ steps.check.outputs.report }}`); | |
| const changes = report.changes || []; | |
| if (changes.length === 0) return; | |
| // Check if there's already an open issue for spec updates | |
| const { data: existingIssues } = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'spec-update', | |
| per_page: 1, | |
| }); | |
| if (existingIssues.length > 0) { | |
| // Update existing issue with new findings | |
| const issue = existingIssues[0]; | |
| const newBody = issue.body + `\n\n---\n### Update ${new Date().toISOString().split('T')[0]}\n\n` + | |
| changes.map(c => `- **[${c.status}]** \`${c.file}\`: ${c.detail}`).join('\n'); | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| body: newBody, | |
| }); | |
| console.log(`Updated existing issue #${issue.number}`); | |
| return; | |
| } | |
| // Create new issue | |
| const changeList = changes.map(c => | |
| `| \`${c.file}\` | ${c.status} | ${c.detail} |` | |
| ).join('\n'); | |
| const body = `## Amazon Ads API Spec Updates Detected | |
| The daily spec check found **${changes.length}** change(s) in the upstream OpenAPI specifications. | |
| | File | Status | Detail | | |
| |------|--------|--------| | |
| ${changeList} | |
| ### Action Required | |
| 1. Download updated specs: | |
| \`\`\`bash | |
| python download_specs.py | |
| \`\`\` | |
| 2. Regenerate models and clients: | |
| \`\`\`bash | |
| python -m codegen.generate -v | |
| \`\`\` | |
| 3. Run tests: | |
| \`\`\`bash | |
| pytest tests/unit/ -v | |
| \`\`\` | |
| 4. Review changes and commit. | |
| --- | |
| *Auto-generated by [check-spec-updates](.github/workflows/check-spec-updates.yml)* | |
| `.replace(/^ /gm, ''); | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: `[Auto] Amazon Ads API spec updates detected (${changes.length} changes)`, | |
| body: body, | |
| labels: ['spec-update', 'automated'], | |
| }); | |
| console.log('Created new spec update issue'); |