Skip to content

Commit 0716fcd

Browse files
1 parent 2ea057b commit 0716fcd

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: update_command_pages
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
paths:
7+
- data/commands_core.json # run when data/commands_core.json is updated on main
8+
workflow_dispatch: # or run on manual trigger
9+
10+
jobs:
11+
update_command_pages:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
actions: write
17+
steps:
18+
- name: 'Checkout'
19+
uses: 'actions/checkout@v3'
20+
21+
- name: Install dependencies
22+
run: make deps
23+
24+
- name: 'Run build/update_cmds.py script'
25+
env:
26+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
run: |
28+
branch="update_command_pages"
29+
commands_change=false
30+
31+
# check if remote branch already exists
32+
git fetch --all
33+
set +e
34+
git ls-remote --exit-code --heads origin "refs/heads/${branch}"
35+
if [ "$?" -eq 0 ]; then
36+
set -e
37+
# if it does, create local branch off existing remote branch
38+
git checkout -b "${branch}" "origin/${branch}"
39+
git branch --set-upstream-to="origin/${branch}" "${branch}"
40+
git pull
41+
else
42+
set -e
43+
# otherwise, create local branch from main
44+
git checkout -b "${branch}"
45+
fi
46+
47+
python3 build/update_cmds.py
48+
49+
commands_are_different=$(git diff "content/commands/")
50+
51+
if [[ ! -z $commands_are_different ]]; then
52+
commands_change=true
53+
54+
git add "content/commands/"
55+
git config user.email "177626021+redisdocsapp[bot]@users.noreply.github.com"
56+
git config user.name "redisdocsapp[bot]"
57+
git commit -m "Update content/commands/"
58+
fi
59+
60+
if [ "$commands_change" = true ] ; then
61+
git push origin "${branch}"
62+
63+
# If a pr is not already open, create one
64+
set +e
65+
gh search prs -R redis/docs --state open --match title "update command pages" | grep -q "update command pages"
66+
if [ "$?" -eq 1 ]; then
67+
set -e
68+
gh pr create \
69+
--body "update command pages" \
70+
--title "update command pages" \
71+
--head "$branch" \
72+
--base "main"
73+
fi
74+
fi

0 commit comments

Comments
 (0)