-
Notifications
You must be signed in to change notification settings - Fork 16
/
full_auto_updater.sh
115 lines (78 loc) · 2.16 KB
/
full_auto_updater.sh
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#
# Script to fully automate updating and pull request.
#
# That is,
# - Checks out LookML code
# - Runs updater
# - if and only if any changes made:
# - commits
# - pushes to remote
# - creates a pull request.
#
# Author: Carl Anderson ([email protected])
#
# to run, you will need to set:
# 1) GITHUB_TOKEN
# 2) REMOTE
# 3) source of definitions (in config)
brew install hub
#this is your github access token for hub
GITHUB_TOKEN='xxx'
# alternatively, set GITHUB_USER, GITHUB_PASSWORD
TIMESTAMP=$(date "+%Y%m%d_%H%M%S")
#######################################
# generate the config
#######################################
REMOTE="https://github.com/someorg/somerepo.git"
GITREPO="auto_gitrepo_${TIMESTAMP}"
cat > auto.config <<- EOM
{
"git": {
"url": "${REMOTE}",
"folder": "${GITREPO}"
},
"use_hub": true,
"use_basename": true,
"definitions": {
"type": "CsvDefinitionsProvider",
"filename": "definitions.csv"
}
}
EOM
#######################################
# pull down the LookML to process
#######################################
python run_git_clone.py --config auto.config
cd ${GITREPO}
#######################################
# create a new branch
#######################################
BRANCHNAME="lookml_updater_${TIMESTAMP}"
echo "Creating a new branch ${BRANCHNAME}"
git pull
git checkout -b ${BRANCHNAME}
#git push origin ${BRANCHNAME}
#######################################
# run the updater
#######################################
cd ..
for file in ${GITREPO}/dim_location.view.lkml
do
echo $file
python run_updater.py --config auto.config --infile $file --outfile $file
done
#######################################
# push changes to remote and create PR
#######################################
cd ${GITREPO}
if [ -z $(git status --porcelain) ];
then
echo "No changes were made"
else
echo "Files were changed!"
git add *.view.lkml
git commit -m "modifications for lookml updater run at ${TIMESTAMP}"
git push --set-upstream origin ${BRANCHNAME}
hub pull-request -m "modifications for lookml updater run at ${TIMESTAMP}"
hub push
fi