|
1 | | -name: Check Spec Updates |
2 | | - |
3 | | -on: |
4 | | - schedule: |
5 | | - # Run daily at 08:00 UTC (every day) |
6 | | - - cron: "0 8 * * *" |
7 | | - workflow_dispatch: # Allow manual trigger |
8 | | - |
9 | | -permissions: |
10 | | - issues: write |
11 | | - contents: read |
12 | | - |
13 | | -jobs: |
14 | | - check-updates: |
15 | | - runs-on: ubuntu-latest |
16 | | - |
17 | | - steps: |
18 | | - - uses: actions/checkout@v4 |
19 | | - |
20 | | - - name: Set up Python |
21 | | - uses: actions/setup-python@v5 |
22 | | - with: |
23 | | - python-version: "3.12" |
24 | | - |
25 | | - - name: Install dependencies |
26 | | - run: pip install pyyaml |
27 | | - |
28 | | - - name: Check for spec updates |
29 | | - id: check |
30 | | - run: | |
31 | | - python scripts/check_spec_updates.py --full --json > /tmp/spec_report.json 2>&1 || true |
32 | | - cat /tmp/spec_report.json |
33 | | - echo "report<<EOF" >> $GITHUB_OUTPUT |
34 | | - cat /tmp/spec_report.json >> $GITHUB_OUTPUT |
35 | | - echo "EOF" >> $GITHUB_OUTPUT |
36 | | -
|
37 | | - # Set has_updates flag |
38 | | - HAS_UPDATES=$(python -c "import json; r=json.load(open('/tmp/spec_report.json')); print('true' if r.get('has_updates') else 'false')") |
39 | | - echo "has_updates=$HAS_UPDATES" >> $GITHUB_OUTPUT |
40 | | -
|
41 | | - - name: Create issue if updates found |
42 | | - if: steps.check.outputs.has_updates == 'true' |
43 | | - uses: actions/github-script@v7 |
44 | | - with: |
45 | | - script: | |
46 | | - const report = JSON.parse(`${{ steps.check.outputs.report }}`); |
47 | | - const changes = report.changes || []; |
48 | | -
|
49 | | - if (changes.length === 0) return; |
50 | | -
|
51 | | - // Check if there's already an open issue for spec updates |
52 | | - const { data: existingIssues } = await github.rest.issues.listForRepo({ |
53 | | - owner: context.repo.owner, |
54 | | - repo: context.repo.repo, |
55 | | - state: 'open', |
56 | | - labels: 'spec-update', |
57 | | - per_page: 1, |
58 | | - }); |
59 | | -
|
60 | | - if (existingIssues.length > 0) { |
61 | | - // Update existing issue with new findings |
62 | | - const issue = existingIssues[0]; |
63 | | - const newBody = issue.body + `\n\n---\n### Update ${new Date().toISOString().split('T')[0]}\n\n` + |
64 | | - changes.map(c => `- **[${c.status}]** \`${c.file}\`: ${c.detail}`).join('\n'); |
65 | | -
|
66 | | - await github.rest.issues.update({ |
67 | | - owner: context.repo.owner, |
68 | | - repo: context.repo.repo, |
69 | | - issue_number: issue.number, |
70 | | - body: newBody, |
71 | | - }); |
72 | | -
|
73 | | - console.log(`Updated existing issue #${issue.number}`); |
74 | | - return; |
75 | | - } |
76 | | -
|
77 | | - // Create new issue |
78 | | - const changeList = changes.map(c => |
79 | | - `| \`${c.file}\` | ${c.status} | ${c.detail} |` |
80 | | - ).join('\n'); |
81 | | -
|
82 | | - const body = `## Amazon Ads API Spec Updates Detected |
83 | | -
|
84 | | - The daily spec check found **${changes.length}** change(s) in the upstream OpenAPI specifications. |
85 | | -
|
86 | | - | File | Status | Detail | |
87 | | - |------|--------|--------| |
88 | | - ${changeList} |
89 | | -
|
90 | | - ### Action Required |
91 | | -
|
92 | | - 1. Download updated specs: |
93 | | - \`\`\`bash |
94 | | - python download_specs.py |
95 | | - \`\`\` |
96 | | -
|
97 | | - 2. Regenerate models and clients: |
98 | | - \`\`\`bash |
99 | | - python -m codegen.generate -v |
100 | | - \`\`\` |
101 | | -
|
102 | | - 3. Run tests: |
103 | | - \`\`\`bash |
104 | | - pytest tests/unit/ -v |
105 | | - \`\`\` |
106 | | -
|
107 | | - 4. Review changes and commit. |
108 | | -
|
109 | | - --- |
110 | | - *Auto-generated by [check-spec-updates](.github/workflows/check-spec-updates.yml)* |
111 | | - `.replace(/^ /gm, ''); |
112 | | -
|
113 | | - await github.rest.issues.create({ |
114 | | - owner: context.repo.owner, |
115 | | - repo: context.repo.repo, |
116 | | - title: `[Auto] Amazon Ads API spec updates detected (${changes.length} changes)`, |
117 | | - body: body, |
118 | | - labels: ['spec-update', 'automated'], |
119 | | - }); |
120 | | -
|
121 | | - console.log('Created new spec update issue'); |
| 1 | +name: Check Spec Updates |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run daily at 08:00 UTC (every day) |
| 6 | + - cron: "0 8 * * *" |
| 7 | + workflow_dispatch: # Allow manual trigger |
| 8 | + |
| 9 | +permissions: |
| 10 | + issues: write |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-updates: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: "3.12" |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: pip install pyyaml |
| 27 | + |
| 28 | + - name: Check for spec updates |
| 29 | + id: check |
| 30 | + run: | |
| 31 | + python scripts/check_spec_updates.py --full --json > /tmp/spec_report.json 2>&1 || true |
| 32 | + cat /tmp/spec_report.json |
| 33 | + echo "report<<EOF" >> $GITHUB_OUTPUT |
| 34 | + cat /tmp/spec_report.json >> $GITHUB_OUTPUT |
| 35 | + echo "EOF" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + # Set has_updates flag |
| 38 | + HAS_UPDATES=$(python -c "import json; r=json.load(open('/tmp/spec_report.json')); print('true' if r.get('has_updates') else 'false')") |
| 39 | + echo "has_updates=$HAS_UPDATES" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + - name: Create issue if updates found |
| 42 | + if: steps.check.outputs.has_updates == 'true' |
| 43 | + uses: actions/github-script@v7 |
| 44 | + with: |
| 45 | + script: | |
| 46 | + const report = JSON.parse(`${{ steps.check.outputs.report }}`); |
| 47 | + const changes = report.changes || []; |
| 48 | +
|
| 49 | + if (changes.length === 0) return; |
| 50 | +
|
| 51 | + // Check if there's already an open issue for spec updates |
| 52 | + const { data: existingIssues } = await github.rest.issues.listForRepo({ |
| 53 | + owner: context.repo.owner, |
| 54 | + repo: context.repo.repo, |
| 55 | + state: 'open', |
| 56 | + labels: 'spec-update', |
| 57 | + per_page: 1, |
| 58 | + }); |
| 59 | +
|
| 60 | + if (existingIssues.length > 0) { |
| 61 | + // Update existing issue with new findings |
| 62 | + const issue = existingIssues[0]; |
| 63 | + const newBody = issue.body + `\n\n---\n### Update ${new Date().toISOString().split('T')[0]}\n\n` + |
| 64 | + changes.map(c => `- **[${c.status}]** \`${c.file}\`: ${c.detail}`).join('\n'); |
| 65 | +
|
| 66 | + await github.rest.issues.update({ |
| 67 | + owner: context.repo.owner, |
| 68 | + repo: context.repo.repo, |
| 69 | + issue_number: issue.number, |
| 70 | + body: newBody, |
| 71 | + }); |
| 72 | +
|
| 73 | + console.log(`Updated existing issue #${issue.number}`); |
| 74 | + return; |
| 75 | + } |
| 76 | +
|
| 77 | + // Create new issue |
| 78 | + const changeList = changes.map(c => |
| 79 | + `| \`${c.file}\` | ${c.status} | ${c.detail} |` |
| 80 | + ).join('\n'); |
| 81 | +
|
| 82 | + const body = `## Amazon Ads API Spec Updates Detected |
| 83 | +
|
| 84 | + The daily spec check found **${changes.length}** change(s) in the upstream OpenAPI specifications. |
| 85 | +
|
| 86 | + | File | Status | Detail | |
| 87 | + |------|--------|--------| |
| 88 | + ${changeList} |
| 89 | +
|
| 90 | + ### Action Required |
| 91 | +
|
| 92 | + 1. Download updated specs: |
| 93 | + \`\`\`bash |
| 94 | + python download_specs.py |
| 95 | + \`\`\` |
| 96 | +
|
| 97 | + 2. Regenerate models and clients: |
| 98 | + \`\`\`bash |
| 99 | + python -m codegen.generate -v |
| 100 | + \`\`\` |
| 101 | +
|
| 102 | + 3. Run tests: |
| 103 | + \`\`\`bash |
| 104 | + pytest tests/unit/ -v |
| 105 | + \`\`\` |
| 106 | +
|
| 107 | + 4. Review changes and commit. |
| 108 | +
|
| 109 | + --- |
| 110 | + *Auto-generated by [check-spec-updates](.github/workflows/check-spec-updates.yml)* |
| 111 | + `.replace(/^ /gm, ''); |
| 112 | +
|
| 113 | + await github.rest.issues.create({ |
| 114 | + owner: context.repo.owner, |
| 115 | + repo: context.repo.repo, |
| 116 | + title: `[Auto] Amazon Ads API spec updates detected (${changes.length} changes)`, |
| 117 | + body: body, |
| 118 | + labels: ['spec-update', 'automated'], |
| 119 | + }); |
| 120 | +
|
| 121 | + console.log('Created new spec update issue'); |
0 commit comments