-
Notifications
You must be signed in to change notification settings - Fork 6
/
update_api.sh
executable file
·138 lines (112 loc) · 3.91 KB
/
update_api.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
CHROME_SRC=${PWD}/../chromium
TEMP_FILEPREFFIX=/tmp/__chromeapis_
TEMP_APP=${TEMP_FILEPREFFIX}apps.json
TEMP_EXT=${TEMP_FILEPREFFIX}extensions.json
GENERATION_TIME=`date -u +%y-%m-%d_%H%M_UTC`
GS_BUCKET=chrome-api
# stop if any command returns uncaught error
set -o pipefail
set -e
DRYRUN=
UPDATE_CHROME=1
# Check for command line flags
while [[ $* ]] ; do
if [ "$1x" == "-nx" ] ; then
echo "Dryrun - no changes will be made on remote repositories"
DRYRUN=1
elif [ "$1x" == "-cx" ] ; then
echo "No Chrome source code update"
UPDATE_CHROME=
elif [ "$1x" == "-dx" -a -n "$2" ] ; then
shift
CHROME_SRC="$1"
else
echo "Unknown switch: $1"
exit 1
fi
shift
done
echo "Using Chrome repo at $CHROME_SRC"
# update own source
git pull
# update index.html
if [ ! $DRYRUN ] ; then
gsutil cp -R -a public-read site gs://${GS_BUCKET}
fi
# update chromium source
pushd ${CHROME_SRC}
if [ $UPDATE_CHROME ] ; then
gclient sync
fi
# remove old temporary files
rm -f ${TEMP_APP} ${TEMP_EXT}
# extract data model from chromium source repository
popd
./generate_ide_agnostic_api.py -t apps -d ${CHROME_SRC}/src/chrome/common/extensions > ${TEMP_APP}
./generate_ide_agnostic_api.py -t extensions -d ${CHROME_SRC}/src/chrome/common/extensions > ${TEMP_EXT}
# check if data model was extracted
if [ -s ${TEMP_APP} -a -s ${TEMP_EXT} ] ; then
# try to parse, to check if generated files are valid JSONs
python -c "import json, io; json.load(open(\"${TEMP_APP}\", \"r\")); json.load(open(\"${TEMP_EXT}\", \"r\"));"
# upload files to Google Cloud Storage, with public read access
if [ ! $DRYRUN ] ; then
gsutil cp -z json -a public-read ${TEMP_APP} gs://${GS_BUCKET}/apps_${GENERATION_TIME}.json
gsutil cp -z json -a public-read ${TEMP_EXT} gs://${GS_BUCKET}/extensions_${GENERATION_TIME}.json
gsutil cp -z json -a public-read ${TEMP_APP} gs://${GS_BUCKET}/apps_latest.json
gsutil cp -z json -a public-read ${TEMP_EXT} gs://${GS_BUCKET}/extensions_latest.json
else
echo "DRYRUN: now I would copy apps_*.json and extensions_*.json to gs://${GS_BUCKET}"
fi
else
echo "Error, could not find valid files at ${TEMP_APP} and ${TEMP_EXT}!"
exit 1
fi
## generate the IDE specific files:
# for Sublime:
SUBLIME_DIR_NAME=ChromeApis
SUBLIME_ROOT_DIR=/tmp
SUBLIME_DIR=${SUBLIME_ROOT_DIR}/${SUBLIME_DIR_NAME}
rm -Rf ${SUBLIME_DIR}
pushd ${SUBLIME_ROOT_DIR}
git clone git@github.com:mangini/chrome-apis-sublime.git ${SUBLIME_DIR_NAME}
popd
python SublimeApiGenerator.py ${TEMP_APP} ${SUBLIME_DIR}/apps.json
python SublimeApiGenerator.py ${TEMP_EXT} ${SUBLIME_DIR}/extensions.json
pushd ${SUBLIME_DIR}
echo "Let's update/commit object models"
git commit -m "updated apps and extensions object models" apps.json extensions.json
if [ ! $DRYRUN ] ; then
git push
else
echo "DRYRUN: now I would push the following changes..."
git log origin/master..HEAD
fi
# applying changes to "published" branch:
git checkout -b published origin/published
git checkout master apps.json extensions.json
git commit -m "Merged apps and extensions object models from trunk"
if [ ! $DRYRUN ] ; then
git push
else
echo "DRYRUN: now I would push the following changes..."
git log origin/published..HEAD
fi
popd
# stable/published version
tar czf /tmp/sublime_chromeapis_plugin_stable.tgz --exclude=".git" -C ${SUBLIME_ROOT_DIR} ${SUBLIME_DIR_NAME}
if [ ! $DRYRUN ] ; then
gsutil cp -a public-read /tmp/sublime_chromeapis_plugin_stable.tgz gs://${GS_BUCKET}
else
echo "DRYRUN: now I would copy /tmp/sublime_chromeapis_plugin_stable.tgz to gs://${GS_BUCKET}"
fi
pushd ${SUBLIME_DIR}
git checkout master
popd
# trunk version
tar czf /tmp/sublime_chromeapis_plugin.tgz --exclude=".git" -C ${SUBLIME_ROOT_DIR} ${SUBLIME_DIR_NAME}
if [ ! $DRYRUN ] ; then
gsutil cp -a public-read /tmp/sublime_chromeapis_plugin.tgz gs://${GS_BUCKET}
else
echo "DRYRUN: now I would copy /tmp/sublime_chromeapis_plugin.tgz to gs://${GS_BUCKET}"
fi