2727 with :
2828 token : ${{ steps.generate-token.outputs.token }}
2929
30- - name : ' Generate modules-api-ref.md file and push if necessary'
30+ - name : ' Generate modules-api-ref.md and commands.json files and push if necessary'
3131 env :
3232 GH_TOKEN : ${{ steps.generate-token.outputs.token }}
3333 run : |-
@@ -39,27 +39,57 @@ jobs:
3939 pushd redis
4040 git fetch origin --tags
4141 git checkout "tags/${RELEASE}"
42+ make 1>/dev/null
43+ src/redis-server &
44+ utils/generate-commands-json.py > generated-commands.json
4245 utils/generate-module-api-doc.rb > generated-modules-api-ref.md
4346 popd
4447
45- git checkout -b "${BRANCH}"
48+ # check if remote branch already exists
49+ git ls-remote --exit-code --heads origin "refs/heads/${BRANCH}"
50+ if [ "$?" -eq 0 ]; then
51+ # if it does, create local branch off existing remote branch
52+ git checkout -b "${BRANCH}" "origin/${BRANCH}"
53+ git branch --set-upstream-to="origin/${BRANCH}" "${BRANCH}"
54+ git pull
55+ else
56+ # otherwise, create local branch from main
57+ git checkout -b "${BRANCH}"
58+ fi
4659
4760 mv redis/generated-modules-api-ref.md content/develop/reference/modules/modules-api-ref.md
61+ mv redis/generated-commands.json data/commands_core.json
4862
4963 # Apply frontmatter patch
5064 git apply content/develop/reference/modules/modules-api-ref-frontmatter.patch
51-
65+
5266 # Check if there are any changes
67+ commands_core_is_different=$(git diff data/commands_core.json)
5368 modules_api_is_different=$(git diff content/develop/reference/modules/modules-api-ref.md)
5469
55- # If file has changed, push it to repo
70+ # If commands_core file has changed, commit it
71+ if [[ ! -z $commands_core_is_different ]]; then
72+ git add data/commands_core.json
73+ git config user.email "177626021+redisdocsapp[bot]@users.noreply.github.com"
74+ git config user.name "redisdocsapp[bot]"
75+ git commit -m "Update commands_core.json for release ${RELEASE}"
76+ fi
77+
78+ # If modules-api-ref file has changed, commit it
5679 if [[ ! -z $modules_api_is_different ]]; then
5780 git add content/develop/reference/modules/modules-api-ref.md
5881 git config user.email "177626021+redisdocsapp[bot]@users.noreply.github.com"
5982 git config user.name "redisdocsapp[bot]"
6083 git commit -m "Update modules-api-ref.md for release ${RELEASE}"
84+ fi
85+
86+ if [[ ! -z $commands_core_is_different || ! -z $modules_api_is_different ]]; then
6187 git push origin "${BRANCH}"
88+ fi
6289
90+ # If a pr is not already open, create one
91+ gh search prs -R redis-learn/docs --state open --match title "redis docs ${RELEASE}" | grep -q "redis docs ${RELEASE}"
92+ if [ "$?" -eq 1 ]; then
6393 gh pr create \
6494 --body "redis docs sync ${RELEASE}" \
6595 --title "redis docs sync ${RELEASE}" \
0 commit comments