Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/api-drift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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,
Comment on lines +58 to +63
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ignore labeled pull requests when looking up existing drift issue

The workflow uses github.rest.issues.listForRepo with labels: 'api-drift' and immediately reuses the first result, but this endpoint can return pull requests as well as issues. If an open PR is labeled api-drift, existing.data[0] can point to that PR, so the job comments on the PR instead of the tracking issue and may never create/update the intended drift issue.

Useful? React with 👍 / 👎.

});

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'],
});
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules/
build/
.docusaurus/
.external/
__pycache__/
*.pyc
Loading
Loading