-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate creation of Redis Cloud API spec page
- Loading branch information
1 parent
842b54b
commit 2757380
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: rc_api_sync | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' # run every day at midnight UTC time | ||
workflow_dispatch: # or run on manual trigger | ||
|
||
jobs: | ||
rc_api_sync: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
actions: write | ||
steps: | ||
- name: 'Checkout' | ||
uses: 'actions/checkout@v3' | ||
|
||
- name: 'Fetch openapi json file' | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
branch="rc_api_sync" | ||
spec_change=false | ||
# check if remote branch already exists | ||
git fetch --all | ||
set +e | ||
git ls-remote --exit-code --heads origin "refs/heads/${branch}" | ||
if [ "$?" -eq 0 ]; then | ||
set -e | ||
# if it does, create local branch off existing remote branch | ||
git checkout -b "${branch}" "origin/${branch}" | ||
git branch --set-upstream-to="origin/${branch}" "${branch}" | ||
git pull | ||
else | ||
set -e | ||
# otherwise, create local branch from main | ||
git checkout -b "${branch}" | ||
fi | ||
curl -Ls https://api.redislabs.com/v1/cloud-api-docs \ | ||
| jq '(.. | .example? | try select(test("^{"))) |= fromjson' > content/operate/rc/api/api-reference/openapi.json | ||
spec_is_different=$(git diff content/operate/rc/api/api-reference/openapi.json) | ||
if [[ ! -z $spec_is_different ]]; then | ||
spec_change=true | ||
git add "content/operate/rc/api/api-reference/openapi.json" | ||
git config user.email "177626021+redisdocsapp[bot]@users.noreply.github.com" | ||
git config user.name "redisdocsapp[bot]" | ||
git commit -m "Update content/operate/rc/api/api-reference/openapi.json" | ||
fi | ||
if [ "$spec_change" = true ] ; then | ||
git push origin "${branch}" | ||
# If a pr is not already open, create one | ||
set +e | ||
gh search prs -R redis/docs --state open --match title "update rc openapi spec" | grep -q "update rc openapi spec" | ||
if [ "$?" -eq 1 ]; then | ||
set -e | ||
gh pr create \ | ||
--body "update rc openapi spec" \ | ||
--title "update rc openapi spec" \ | ||
--head "$branch" \ | ||
--base "main" | ||
fi | ||
fi |