|
| 1 | +name: Update Ads API reference |
| 2 | +on: |
| 3 | + # Triggered from the Ads service repository whenever its OpenAPI contract changes: |
| 4 | + # gh api repos/THEOplayer/documentation/dispatches -f event_type=update-ads-api-docs |
| 5 | + repository_dispatch: |
| 6 | + types: [update-ads-api-docs] |
| 7 | + workflow_dispatch: |
| 8 | +jobs: |
| 9 | + update: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + env: |
| 15 | + # The branch that will receive the regenerated API reference (will be created if it doesn't exist) |
| 16 | + # Will automatically open a new PR (if no PR exists yet) |
| 17 | + UPDATE_BRANCH: update-ads-api-docs |
| 18 | + steps: |
| 19 | + - name: Create app token |
| 20 | + uses: actions/create-github-app-token@v3 |
| 21 | + id: app-token |
| 22 | + with: |
| 23 | + client-id: ${{ vars.THEOPLAYER_BOT_CLIENT_ID }} |
| 24 | + private-key: ${{ secrets.THEOPLAYER_BOT_PRIVATE_KEY }} |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v7 |
| 27 | + with: |
| 28 | + token: ${{ steps.app-token.outputs.token }} |
| 29 | + fetch-depth: 1 |
| 30 | + - name: Configure Git user |
| 31 | + run: | |
| 32 | + git config user.name 'theoplayer-bot[bot]' |
| 33 | + git config user.email '873105+theoplayer-bot[bot]@users.noreply.github.com' |
| 34 | + - name: Create or checkout update branch |
| 35 | + # language=bash |
| 36 | + run: | |
| 37 | + if git fetch --depth 1 origin refs/heads/$UPDATE_BRANCH ; then |
| 38 | + git checkout -b $UPDATE_BRANCH FETCH_HEAD |
| 39 | + else |
| 40 | + git checkout -b $UPDATE_BRANCH HEAD |
| 41 | + fi |
| 42 | + - name: Setup Node.JS |
| 43 | + uses: actions/setup-node@v7 |
| 44 | + with: |
| 45 | + node-version: '24' |
| 46 | + cache: 'npm' |
| 47 | + cache-dependency-path: ./package-lock.json |
| 48 | + - name: Install dependencies |
| 49 | + run: npm ci |
| 50 | + - name: Regenerate Ads API reference |
| 51 | + run: npm run refresh-ads-api-docs |
| 52 | + - name: Check for changes |
| 53 | + id: check_changes |
| 54 | + # language=bash |
| 55 | + run: | |
| 56 | + if [[ -z "$(git status --porcelain ads/api/reference)" ]]; then |
| 57 | + echo "No API reference changes detected." |
| 58 | + else |
| 59 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 60 | + fi |
| 61 | + - name: Commit and push changes |
| 62 | + if: ${{ steps.check_changes.outputs.changed }} |
| 63 | + # language=bash |
| 64 | + run: | |
| 65 | + git add ads/api/reference |
| 66 | + git commit -m 'Update Ads API reference' |
| 67 | + git push --force origin HEAD:$UPDATE_BRANCH |
| 68 | + - name: Check if pull request already exists |
| 69 | + if: ${{ steps.check_changes.outputs.changed }} |
| 70 | + id: check_pr_exists |
| 71 | + # language=bash |
| 72 | + run: | |
| 73 | + pr_count=$(gh pr list --base main --head "$UPDATE_BRANCH" --state open --limit 1 --json number --jq length) |
| 74 | + if ((pr_count > 0)); then |
| 75 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 76 | + fi |
| 77 | + env: |
| 78 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 79 | + - name: Create pull request |
| 80 | + if: ${{ steps.check_changes.outputs.changed && !steps.check_pr_exists.outputs.exists }} |
| 81 | + # language=bash |
| 82 | + run: | |
| 83 | + gh pr create \ |
| 84 | + --base main \ |
| 85 | + --head "$UPDATE_BRANCH" \ |
| 86 | + --title "Update Ads API reference" \ |
| 87 | + --body "This PR regenerates the OptiView Ads API reference from the latest OpenAPI contract." |
| 88 | + env: |
| 89 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
0 commit comments