name: Sync OpenAPI schema # Updates REST, Webhooks, and GitHub Apps docs from github/rest-api-description. # Opens a PR when generated OpenAPI data files change. on: workflow_dispatch: inputs: SOURCE_BRANCH: description: 'Branch to pull the dereferenced OpenAPI source files from in the github/rest-api-descriptions repo.' type: string required: true default: 'main' repository_dispatch: types: [sync-openapi] schedule: - cron: '20 16 * * 1-5' # Run Mon-Fri at 16:20 UTC / 8:20 PST permissions: contents: write pull-requests: write # Cancel older syncs so stale OpenAPI data does not open older PRs. concurrency: group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' cancel-in-progress: true jobs: generate-decorated-files: if: github.repository == 'github/docs-internal' runs-on: ubuntu-latest steps: - name: Checkout repository code uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - name: Checkout rest-api-description repo uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: repository: github/rest-api-description path: rest-api-description ref: ${{ inputs.SOURCE_BRANCH || github.event.client_payload.ref || 'main' }} - uses: ./.github/actions/node-npm-setup - name: Sync the REST, Webhooks, and GitHub Apps schemas env: GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }} NODE_OPTIONS: '--max-old-space-size=8192' run: | npm run sync-rest -- \ --source-repos rest-api-description \ --output rest github-apps webhooks rest-redirects git status echo "Deleting the cloned github/rest-api-description repo..." rm -rf rest-api-description - name: Get the rest-api-description SHA being synced id: rest-api-description run: | OPENAPI_COMMIT_SHA=$(cat src/rest/lib/config.json | jq -r '.sha') echo "OPENAPI_COMMIT_SHA=$OPENAPI_COMMIT_SHA" >> $GITHUB_OUTPUT echo "Copied files from github/rest-api-description repo. Commit SHA: $OPENAPI_COMMIT_SHA" if [ -z $OPENAPI_COMMIT_SHA ]; then echo "OpenAPI commit SHA is empty!" exit 1 fi - name: Create pull request env: GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }} run: | # Exit before branch creation so a no-op sync does not leave an orphan branch. changes=$(git diff --name-only | wc -l) if [[ $changes -eq 0 ]]; then echo "There are no changes to commit after running 'npm run sync-rest'. Exiting..." exit 0 fi git config --global user.name "docs-bot" git config --global user.email "77750099+docs-bot@users.noreply.github.com" branchname=openapi-update-${{ steps.rest-api-description.outputs.OPENAPI_COMMIT_SHA }} remotesha=$(git ls-remote --heads origin $branchname) if [ -n "$remotesha" ]; then echo "Branch $branchname already exists in 'github/docs-internal'. Exiting..." exit 0 fi git checkout -b $branchname git add . git commit -m "Add decorated OpenAPI schema files" git push origin $branchname echo "Creating pull request..." gh pr create \ --title "Update OpenAPI Description" \ --body '👋 humans. This PR updates the OpenAPI description with the latest changes. (Synced from github/rest-api-description@${{ steps.rest-api-description.outputs.OPENAPI_COMMIT_SHA }}) Docs First Responders should follow [the acting-as-the-first-responder instructions](https://github.com/github/technical-content/blob/main/contributing-to-docs/first-responder/acting-as-the-first-responder.md?plain=1#L156). If CI does not pass or other problems arise, contact #technical-content on slack. _Generated by the [Sync OpenAPI schema](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow run._' \ --repo github/docs-internal \ --label github-openapi-bot,workflow-generated \ --head=$branchname \ - uses: ./.github/actions/create-workflow-failure-issue id: create-failure-issue if: ${{ failure() && github.event_name != 'workflow_dispatch' }} with: token: ${{ secrets.DOCS_BOT_PAT_BASE }} - uses: ./.github/actions/slack-alert if: ${{ failure() && github.event_name != 'workflow_dispatch' }} with: slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} issue_url: ${{ steps.create-failure-issue.outputs.issue_url }}