|
| 1 | +name: Weekly GitHub OpenAPI Spec Sync |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run every Monday at 04:00 UTC |
| 6 | + - cron: '0 4 * * 1' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + spec-sync: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v6 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Setup Dart SDK |
| 26 | + uses: dart-lang/setup-dart@v1 |
| 27 | + with: |
| 28 | + sdk: stable |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: dart pub get |
| 32 | + |
| 33 | + - name: Check for upstream OpenAPI specification updates |
| 34 | + id: check_upstream |
| 35 | + run: | |
| 36 | + mkdir -p .dart_tool |
| 37 | + dart run tool/spec_sync.dart --offline --report-json > .dart_tool/spec_report_before.json |
| 38 | + echo "Checked current spec baseline." |
| 39 | +
|
| 40 | + - name: Regenerate OpenAPI catalog and docs |
| 41 | + id: run_sync |
| 42 | + run: | |
| 43 | + dart run tool/spec_sync.dart --update |
| 44 | + git status --porcelain > .dart_tool/git_status.txt |
| 45 | + if [ -s .dart_tool/git_status.txt ]; then |
| 46 | + echo "changes_detected=true" >> "$GITHUB_OUTPUT" |
| 47 | + else |
| 48 | + echo "changes_detected=false" >> "$GITHUB_OUTPUT" |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Validate generated code and contracts |
| 52 | + if: steps.run_sync.outputs.changes_detected == 'true' |
| 53 | + run: | |
| 54 | + dart format --output=none --set-exit-if-changed . |
| 55 | + dart analyze --fatal-infos |
| 56 | + dart test |
| 57 | + dart pub publish --dry-run |
| 58 | +
|
| 59 | + - name: Create or update spec-sync pull request |
| 60 | + if: steps.run_sync.outputs.changes_detected == 'true' |
| 61 | + env: |
| 62 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + run: | |
| 64 | + BRANCH_NAME="automation/github-openapi-spec-sync" |
| 65 | + git config user.name "github-actions[bot]" |
| 66 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 67 | +
|
| 68 | + git checkout -B "$BRANCH_NAME" |
| 69 | + git add lib/src/common/generated/rest_contracts.g.dart docs/api-coverage.md tool/spec/ |
| 70 | + git commit -m "chore(spec): synchronize GitHub OpenAPI specification contracts" |
| 71 | + git push --force origin "$BRANCH_NAME" |
| 72 | +
|
| 73 | + PR_TITLE="chore(spec): synchronize GitHub OpenAPI specification contracts" |
| 74 | + PR_BODY="## GitHub OpenAPI Specification Sync |
| 75 | +
|
| 76 | + This automated pull request synchronizes the GitHub OpenAPI description contracts and coverage reports. |
| 77 | +
|
| 78 | + ### Summary of Changes |
| 79 | + - Regenerated \`lib/src/common/generated/rest_contracts.g.dart\` |
| 80 | + - Updated API coverage documentation in \`docs/api-coverage.md\` |
| 81 | +
|
| 82 | + ### Validation |
| 83 | + - \`dart format\` verified |
| 84 | + - \`dart analyze --fatal-infos\` passed |
| 85 | + - \`dart test\` passed |
| 86 | + - \`dart pub publish --dry-run\` verified |
| 87 | +
|
| 88 | + **Notice**: Review only. Never auto-merged." |
| 89 | +
|
| 90 | + gh pr create \ |
| 91 | + --title "$PR_TITLE" \ |
| 92 | + --body "$PR_BODY" \ |
| 93 | + --base master \ |
| 94 | + --head "$BRANCH_NAME" \ |
| 95 | + --label "automation,spec-sync" || \ |
| 96 | + gh pr edit "$BRANCH_NAME" \ |
| 97 | + --title "$PR_TITLE" \ |
| 98 | + --body "$PR_BODY" |
0 commit comments