forked from mockturtl/cinnamon-weather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package
executable file
·185 lines (157 loc) · 3.55 KB
/
package
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/sh -e
VERSION=$1
BASEDIR="${HOME}/Desktop"
TESTDIR="${HOME}/.local/share/cinnamon/applets"
AUTHOR="mockturtl"
PACKAGE="weather@mockturtl"
TARGET="${BASEDIR}/${PACKAGE}"
DEV_BRANCH="master"
STAGE_BRANCH="staging"
DEPLOY_BRANCH="master"
REMOTE="origin"
MANIFEST="MANIFEST"
VERSION_FILE="metadata.json"
GIT_HOST="https://github.com"
PROJECT="cinnamon-weather"
DEPLOY_URL="${GIT_HOST}/${AUTHOR}/${PROJECT}/zipball/v${VERSION}"
COMMENTS='/^\s*#/'
if [ -z $VERSION ]; then
cat << EOF
ERROR: You must provide a version number, like:
$ ./package 1.2.3
EOF
exit 2
fi
check_pgp() {
if [ -z $GH_KEY_ID ]; then
cat << EOF
Define a GH_KEY_ID variable for signing git tags.
Typically this is the email address associated with your public PGP key.
EOF
exit 11
fi
}
check_version() {
# exit code 1 means no match; see grep(1)
set +e
grep -q ${VERSION} ${VERSION_FILE}
VERSION_MATCH=$?
set -e
# { "JSON": "beware of colons!" }
if [ $VERSION_MATCH -ne 0 ]; then
cat << EOF
WARNING: { $(grep version ${VERSION_FILE}) } in ${VERSION_FILE} does not match the package version provided.
You may have forgotten to tag this release. (v$VERSION)
EOF
fi
}
validate_version() {
check_version
if [ $VERSION_MATCH -ne 0 ]; then
cat << EOF
ERROR: Invalid version. Fix ${VERSION_FILE} to push. You may wish to revert the last commit.
EOF
exit 13
fi
}
do_package() {
check_version
rm -rf ${TARGET}*
mkdir -p ${TARGET}/
# strip comment lines
cat ${MANIFEST} | sed -r ${COMMENTS}d | xargs -i cp -r '{}' ${TARGET}
rm -rf ${TARGET}/po/*.po~
cd ${BASEDIR}
local zipfile=${PACKAGE}-${VERSION}
zip -q -r ${zipfile}.zip ${PACKAGE}
cat << EOF
Done. Release ${VERSION} is ready to publish at:
${BASEDIR}/${zipfile}.zip
EOF
}
do_tag() {
check_pgp
cat << EOF
Rebasing ${STAGE_BRANCH} onto ${DEV_BRANCH}...
EOF
git checkout ${STAGE_BRANCH}
git rebase ${DEV_BRANCH}
cat << EOF
Bumping version (${VERSION}) in ${VERSION_FILE}...
EOF
# major.minor.patch with optional suffix
sed -i "s/[0-9]\+\.[0-9]\+\.[0-9]\+[0-9A-Za-z.+~-]*/$VERSION/" ${VERSION_FILE}
cat << EOF
Creating tag...
EOF
git add ${VERSION_FILE}
# allow manual version-bump commits; see git-diff(1)
git diff --quiet --staged || git commit -m 'bump version'
git tag -u ${GH_KEY_ID} --cleanup=whitespace v${VERSION}
cat << EOF
Done. Now run './deploy ${VERSION}' to merge into ${DEPLOY_BRANCH} and push.
EOF
git checkout ${DEV_BRANCH}
}
do_deploy() {
git checkout ${DEPLOY_BRANCH}
git merge ${STAGE_BRANCH}
validate_version
git push ${REMOTE} ${DEPLOY_BRANCH}
git push --tags
cat << EOF
Your new tag is at ${DEPLOY_URL}.
EOF
}
do_translate() {
LOCALES="$(cat po/LINGUAS)"
UUID="$(find po/ -name *.pot | xargs -i basename {} .pot)"
cat << EOF
WARNING: not updating template for ${UUID}; please investigate!
EOF
# python mode is OK for javascript
#xgettext -d ${UUID} -o po/${UUID}.pot -L python --keyword=_ applet.js
# settings-schema.json translation
# not idempotent! the xgettext call above will remove those lines
#cinnamon-json-makepot po/${UUID}.pot
cat << EOF
Merging existing translation files with new template...
EOF
for LOCALE in ${LOCALES}; do
msgmerge -U po/${LOCALE}.po po/${UUID}.pot
done
cat << EOF
Done.
EOF
}
do_test() {
do_package
cat<<EOF
Updating...
EOF
rm -rf ${TESTDIR}/${PACKAGE} 2>/dev/null
cp -r ${BASEDIR}/${PACKAGE} ${TESTDIR}
}
case `basename $0` in
"tag")
do_tag
;;
"package")
do_package
;;
"test")
do_test
;;
"deploy")
do_deploy
;;
"translate")
do_translate
;;
*)
cat << EOF
Usage: tag | deploy | package | translate | test
EOF
exit 2
;;
esac