forked from redis/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (63 loc) · 2.38 KB
/
rc_supported_regions_sync.yaml
File metadata and controls
74 lines (63 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: rc_supported_regions_sync
on:
schedule:
- cron: '0 0 * * 1' # run every Monday at midnight UTC time
workflow_dispatch: # or run on manual trigger
jobs:
rc_supported_regions_sync:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
actions: write
steps:
- name: 'Checkout'
uses: 'actions/checkout@v3'
- name: 'Install dependencies'
run: pip3 install requests
- name: 'Run rc_supported_regions_sync.py'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RC_API_KEY: ${{ secrets.RC_API_KEY }}
RC_API_SECRET_KEY: ${{ secrets.RC_API_SECRET_KEY }}
run: |
branch="rc_supported_regions_sync"
regions_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
python3 build/rc_supported_regions_sync.py
regions_are_different=$(git diff data/rc_supported_regions.json)
if [[ ! -z $regions_are_different ]]; then
regions_change=true
git add "data/rc_supported_regions.json"
git config user.email "177626021+redisdocsapp[bot]@users.noreply.github.com"
git config user.name "redisdocsapp[bot]"
git commit -m "Update data/rc_supported_regions.json"
fi
if [ "$regions_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 supported regions" | grep -q "update rc supported regions"
if [ "$?" -eq 1 ]; then
set -e
gh pr create \
--body "update rc supported regions" \
--title "update rc supported regions" \
--head "$branch" \
--base "main"
fi
fi