name: VirtFusion API Change Detection on: schedule: - cron: '0 9 * * 1' # Monday 9am UTC workflow_dispatch: jobs: check-api: runs-on: ubuntu-latest permissions: contents: write issues: write pull-requests: write steps: - uses: actions/checkout@v4 - name: Download current API spec run: curl -sSL -o /tmp/openapi-current.yaml https://docs.virtfusion.com/api/openapi.yaml - name: Compare with baseline id: diff run: | if [ ! -f docs/openapi-baseline.yaml ]; then echo "No baseline found — creating initial baseline" cp /tmp/openapi-current.yaml docs/openapi-baseline.yaml echo "changed=initial" >> "$GITHUB_OUTPUT" elif ! diff -q docs/openapi-baseline.yaml /tmp/openapi-current.yaml > /dev/null 2>&1; then echo "API spec has changed" diff docs/openapi-baseline.yaml /tmp/openapi-current.yaml > /tmp/api-diff.txt || true echo "changed=true" >> "$GITHUB_OUTPUT" else echo "No changes detected" echo "changed=false" >> "$GITHUB_OUTPUT" fi - name: Create issue on change if: steps.diff.outputs.changed == 'true' uses: actions/github-script@v7 with: script: | const fs = require('fs'); const diff = fs.readFileSync('/tmp/api-diff.txt', 'utf8').substring(0, 60000); await github.rest.issues.create({ owner: context.repo.owner, repo: context.repo.repo, title: `VirtFusion API spec changed (${new Date().toISOString().split('T')[0]})`, body: `The VirtFusion OpenAPI spec has been updated.\n\n
Diff\n\n\`\`\`diff\n${diff}\n\`\`\`\n
\n\nReview the changes and update the module if needed.`, labels: ['api-sync'] }); - name: Update baseline and create PR if: steps.diff.outputs.changed == 'true' || steps.diff.outputs.changed == 'initial' run: | cp /tmp/openapi-current.yaml docs/openapi-baseline.yaml git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" BRANCH="api-sync/$(date +%Y-%m-%d)" git checkout -b "$BRANCH" git add docs/openapi-baseline.yaml git commit -m "chore: update VirtFusion API baseline spec" git push origin "$BRANCH" gh pr create --title "chore: update VirtFusion API baseline" --body "Automated update of the VirtFusion OpenAPI baseline spec." --base main env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}