Skip to content
Merged
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
85 changes: 54 additions & 31 deletions .github/workflows/openapi-decorate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ name: Sync OpenAPI schema

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'
schedule:
- cron: '20 16 * * *' # Run every day at 16:20 UTC / 8:20 PST

Expand All @@ -28,11 +34,6 @@ jobs:
echo 'The repo is currently frozen! Exiting this workflow.'
exit 1 # prevents further steps from running

- name: Label pull requests with 'github-openapi-bot'
uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90
with:
add-labels: 'github-openapi-bot'

- name: Checkout repository code
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8

Expand All @@ -44,6 +45,9 @@ jobs:
# will be checked out
repository: github/rest-api-description
path: rest-api-description
ref: ${{ github.event.inputs.SOURCE_BRANCH }}

- uses: ./.github/actions/node-npm-setup

- name: Copy dereferenced OpenAPI files
id: rest-api-description
Expand All @@ -55,34 +59,53 @@ jobs:
echo "OPENAPI_COMMIT_SHA=$OPENAPI_COMMIT_SHA" >> $GITHUB_OUTPUT
echo "Copied files from github/rest-api-description repo. Commit SHA: $OPENAPI_COMMIT_SHA"

- uses: ./.github/actions/node-npm-setup

- name: Decorate the dereferenced OpenAPI schemas
run: script/rest/update-files.js --decorate-only --open-source
run: |
script/rest/update-files.js --decorate-only --open-source
git status
echo "Deleting the cloned github/rest-api-description repo..."
rm -rf rest-api-description

# This action performs the diff and if no files have been change
# the action exits silently.
- name: Create pull request
id: create-pull-request
uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04
env:
# Disable pre-commit hooks; they don't play nicely here
HUSKY: '0'
# Needed for gh
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
run: |
# If nothing to commit, exit now. It's fine. No orphans.
changes=$(git diff --name-only | wc -l)
if [[ $changes -eq 0 ]]; then
echo "There are no changes to commit after running lib/rest/update-files.js. Exiting..."
exit 0
fi

git config --global user.name "docubot"
git config --global user.email "67483024+docubot@users.noreply.github.com"

branchname=openapi-update-${{ steps.rest-api-description.outputs.OPENAPI_COMMIT_SHA }}

branchCheckout=$(git checkout -b $branchname)
if [[! $? -eq 0 ]]; then
echo "Branch $branchname already exists in `github/docs-internal`. Exiting..."
exit 0
fi
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 }})

If CI does not pass or other problems arise, contact #docs-engineering on slack.' \
--repo github/docs-internal \
--label github-openapi-bot

- name: Send Slack notification if workflow fails
uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340
if: ${{ failure() && env.FREEZE != 'true' }}
with:
# Need to use a token with repo and workflow scopes for this step.
# Token should be a PAT because actions performed with GITHUB_TOKEN
# don't trigger other workflows and this action force pushes updates
# from the default branch.
token: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
add-paths: |
- lib/rest/static/apps
- lib/rest/static/decorated
- lib/webhooks/static/decorated
- lib/redirects/static/client-side-rest-api-redirects.json
commit-message: 'Add decorated OpenAPI schema files'
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 }})

If CI does not pass or other problems arise, contact #docs-engineering on slack.'
branch: openapi-update-${{ steps.rest-api-description.outputs.OPENAPI_COMMIT_SHA }}
channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }}
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
color: failure
text: The last Sync OpenAPI schema run for ${{github.repository}} failed. See https://github.com/${{github.repository}}/actions/workflows/sync-openapi.yml