Skip to content

Commit a7a57c2

Browse files
authored
Merge pull request #973 from redis/DOC-4621
Automate creation of Redis Cloud API spec
2 parents c7f12af + 2757380 commit a7a57c2

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.github/workflows/rc_api_sync.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: rc_api_sync
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # run every day at midnight UTC time
6+
workflow_dispatch: # or run on manual trigger
7+
8+
jobs:
9+
rc_api_sync:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
actions: write
15+
steps:
16+
- name: 'Checkout'
17+
uses: 'actions/checkout@v3'
18+
19+
- name: 'Fetch openapi json file'
20+
env:
21+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
run: |
23+
branch="rc_api_sync"
24+
spec_change=false
25+
26+
# check if remote branch already exists
27+
git fetch --all
28+
set +e
29+
git ls-remote --exit-code --heads origin "refs/heads/${branch}"
30+
if [ "$?" -eq 0 ]; then
31+
set -e
32+
# if it does, create local branch off existing remote branch
33+
git checkout -b "${branch}" "origin/${branch}"
34+
git branch --set-upstream-to="origin/${branch}" "${branch}"
35+
git pull
36+
else
37+
set -e
38+
# otherwise, create local branch from main
39+
git checkout -b "${branch}"
40+
fi
41+
42+
curl -Ls https://api.redislabs.com/v1/cloud-api-docs \
43+
| jq '(.. | .example? | try select(test("^{"))) |= fromjson' > content/operate/rc/api/api-reference/openapi.json
44+
45+
spec_is_different=$(git diff content/operate/rc/api/api-reference/openapi.json)
46+
47+
if [[ ! -z $spec_is_different ]]; then
48+
spec_change=true
49+
50+
git add "content/operate/rc/api/api-reference/openapi.json"
51+
git config user.email "177626021+redisdocsapp[bot]@users.noreply.github.com"
52+
git config user.name "redisdocsapp[bot]"
53+
git commit -m "Update content/operate/rc/api/api-reference/openapi.json"
54+
fi
55+
56+
if [ "$spec_change" = true ] ; then
57+
git push origin "${branch}"
58+
59+
# If a pr is not already open, create one
60+
set +e
61+
gh search prs -R redis/docs --state open --match title "update rc openapi spec" | grep -q "update rc openapi spec"
62+
if [ "$?" -eq 1 ]; then
63+
set -e
64+
gh pr create \
65+
--body "update rc openapi spec" \
66+
--title "update rc openapi spec" \
67+
--head "$branch" \
68+
--base "main"
69+
fi
70+
fi

0 commit comments

Comments
 (0)