112 lines
4.7 KiB
YAML
112 lines
4.7 KiB
YAML
name: Sync OpenAPI schema
|
|
|
|
# **What it does**: Once a day, this workflow syncs the dereferenced files from github/rest-api-description and creates a pull request if there are updates to any of the static files we generate from the OpenAPI.
|
|
# **Why we have it**: So we can consume OpenAPI changes.
|
|
# **Who does it impact**: Anyone making OpenAPI changes in `github/github`, and wanting to get them published on the docs site.
|
|
|
|
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
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
|
|
# This allows a subsequently queued workflow run to interrupt previous runs
|
|
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:
|
|
- if: ${{ env.FREEZE == 'true' }}
|
|
run: |
|
|
echo 'The repo is currently frozen! Exiting this workflow.'
|
|
exit 1 # prevents further steps from running
|
|
|
|
- name: Checkout repository code
|
|
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
|
|
|
|
# Check out a nested repository inside of previous checkout
|
|
- name: Checkout rest-api-description repo
|
|
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
|
|
with:
|
|
# By default, only the most recent commit of the `main` branch
|
|
# 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
|
|
run: |
|
|
mkdir ./src/rest/data/dereferenced
|
|
find rest-api-description/descriptions-next -type f -name "*.deref.json" -exec sh -c 'cp $1 ./src/rest/data/dereferenced' sh {} \;
|
|
cd rest-api-description
|
|
OPENAPI_COMMIT_SHA=$(git rev-parse HEAD)
|
|
echo "OPENAPI_COMMIT_SHA=$OPENAPI_COMMIT_SHA" >> $GITHUB_OUTPUT
|
|
echo "Copied files from github/rest-api-description repo. Commit SHA: $OPENAPI_COMMIT_SHA"
|
|
|
|
- name: Decorate the dereferenced OpenAPI schemas
|
|
run: |
|
|
src/rest/scripts/update-files.js --decorate-only --open-source
|
|
git status
|
|
echo "Deleting the cloned github/rest-api-description repo..."
|
|
rm -rf rest-api-description
|
|
|
|
- name: Create pull request
|
|
env:
|
|
# 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 src/rest/scripts/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@1d367080235edfa53df415bd8e0bbab480f29bad
|
|
if: ${{ failure() && env.FREEZE != 'true' }}
|
|
with:
|
|
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
|