API drift detection #5
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: API drift detection | |
| on: | |
| schedule: | |
| - cron: '0 8 * * 1' # Every Monday at 8:00 UTC | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| check-api: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout wiki | |
| uses: actions/checkout@v4 | |
| - name: Checkout micropython-steami-lib | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: steamicc/micropython-steami-lib | |
| path: micropython-steami-lib | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Check for API changes | |
| id: drift | |
| run: | | |
| set +e | |
| python scripts/check-api-drift.py micropython-steami-lib/lib scripts/api-snapshot.json > /tmp/api-drift-report.md | |
| EXIT_CODE=$? | |
| set -e | |
| echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT" | |
| if [ "$EXIT_CODE" -eq 0 ]; then | |
| echo "changes=false" >> "$GITHUB_OUTPUT" | |
| elif [ "$EXIT_CODE" -eq 1 ]; then | |
| echo "changes=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "API drift check failed with exit code $EXIT_CODE" >&2 | |
| exit "$EXIT_CODE" | |
| fi | |
| - name: Create issue if changes detected | |
| if: steps.drift.outputs.changes == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const report = fs.readFileSync('/tmp/api-drift-report.md', 'utf8'); | |
| // Check if an open issue already exists | |
| const existing = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'api-drift', | |
| per_page: 1, | |
| }); | |
| if (existing.data.length > 0) { | |
| // Update existing issue | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: existing.data[0].number, | |
| body: `Mise à jour ${new Date().toISOString().split('T')[0]} :\n\n${report}`, | |
| }); | |
| } else { | |
| // Create new issue | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: 'docs: Changements API détectés dans micropython-steami-lib', | |
| body: `${report}\n\n---\n*Détecté automatiquement par le workflow api-drift.*`, | |
| labels: ['api-drift'], | |
| }); | |
| } |