Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9e5a2c

Browse files
authored
Add a branch parameter to openapi workflow (#33974)
1 parent 37a6e36 commit b9e5a2c

1 file changed

Lines changed: 54 additions & 31 deletions

File tree

.github/workflows/openapi-decorate.yml

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ name: Sync OpenAPI schema
66

77
on:
88
workflow_dispatch:
9+
inputs:
10+
SOURCE_BRANCH:
11+
description: 'Branch to pull the dereferenced OpenAPI source files from in the github/rest-api-descriptions repo.'
12+
type: string
13+
required: true
14+
default: 'main'
915
schedule:
1016
- cron: '20 16 * * *' # Run every day at 16:20 UTC / 8:20 PST
1117

@@ -28,11 +34,6 @@ jobs:
2834
echo 'The repo is currently frozen! Exiting this workflow.'
2935
exit 1 # prevents further steps from running
3036
31-
- name: Label pull requests with 'github-openapi-bot'
32-
uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90
33-
with:
34-
add-labels: 'github-openapi-bot'
35-
3637
- name: Checkout repository code
3738
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
3839

@@ -44,6 +45,9 @@ jobs:
4445
# will be checked out
4546
repository: github/rest-api-description
4647
path: rest-api-description
48+
ref: ${{ github.event.inputs.SOURCE_BRANCH }}
49+
50+
- uses: ./.github/actions/node-npm-setup
4751

4852
- name: Copy dereferenced OpenAPI files
4953
id: rest-api-description
@@ -55,34 +59,53 @@ jobs:
5559
echo "OPENAPI_COMMIT_SHA=$OPENAPI_COMMIT_SHA" >> $GITHUB_OUTPUT
5660
echo "Copied files from github/rest-api-description repo. Commit SHA: $OPENAPI_COMMIT_SHA"
5761
58-
- uses: ./.github/actions/node-npm-setup
59-
6062
- name: Decorate the dereferenced OpenAPI schemas
61-
run: script/rest/update-files.js --decorate-only --open-source
63+
run: |
64+
script/rest/update-files.js --decorate-only --open-source
65+
git status
66+
echo "Deleting the cloned github/rest-api-description repo..."
67+
rm -rf rest-api-description
6268
63-
# This action performs the diff and if no files have been change
64-
# the action exits silently.
6569
- name: Create pull request
66-
id: create-pull-request
67-
uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04
6870
env:
69-
# Disable pre-commit hooks; they don't play nicely here
70-
HUSKY: '0'
71+
# Needed for gh
72+
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
73+
run: |
74+
# If nothing to commit, exit now. It's fine. No orphans.
75+
changes=$(git diff --name-only | wc -l)
76+
if [[ $changes -eq 0 ]]; then
77+
echo "There are no changes to commit after running lib/rest/update-files.js. Exiting..."
78+
exit 0
79+
fi
80+
81+
git config --global user.name "docubot"
82+
git config --global user.email "[email protected]"
83+
84+
branchname=openapi-update-${{ steps.rest-api-description.outputs.OPENAPI_COMMIT_SHA }}
85+
86+
branchCheckout=$(git checkout -b $branchname)
87+
if [[! $? -eq 0 ]]; then
88+
echo "Branch $branchname already exists in `github/docs-internal`. Exiting..."
89+
exit 0
90+
fi
91+
git add .
92+
git commit -m "Add decorated OpenAPI schema files"
93+
git push origin $branchname
94+
95+
echo "Creating pull request..."
96+
gh pr create \
97+
--title "Update OpenAPI Description" \
98+
--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 }})
99+
100+
If CI does not pass or other problems arise, contact #docs-engineering on slack.' \
101+
--repo github/docs-internal \
102+
--label github-openapi-bot
103+
104+
- name: Send Slack notification if workflow fails
105+
uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340
106+
if: ${{ failure() && env.FREEZE != 'true' }}
71107
with:
72-
# Need to use a token with repo and workflow scopes for this step.
73-
# Token should be a PAT because actions performed with GITHUB_TOKEN
74-
# don't trigger other workflows and this action force pushes updates
75-
# from the default branch.
76-
token: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
77-
add-paths: |
78-
- lib/rest/static/apps
79-
- lib/rest/static/decorated
80-
- lib/webhooks/static/decorated
81-
- lib/redirects/static/client-side-rest-api-redirects.json
82-
commit-message: 'Add decorated OpenAPI schema files'
83-
title: Update OpenAPI Description
84-
body: |
85-
'👋 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 }})
86-
87-
If CI does not pass or other problems arise, contact #docs-engineering on slack.'
88-
branch: openapi-update-${{ steps.rest-api-description.outputs.OPENAPI_COMMIT_SHA }}
108+
channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }}
109+
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
110+
color: failure
111+
text: The last Sync OpenAPI schema run for ${{github.repository}} failed. See https://github.com/${{github.repository}}/actions/workflows/sync-openapi.yml

0 commit comments

Comments
 (0)