@@ -8,14 +8,30 @@ function abort {
88 exit 1
99}
1010
11+ function confirm {
12+ echo " ${1} [y/N]"
13+ read confirmation
14+
15+ if [ " ${confirmation} " != " y" ]; then
16+ exit 0
17+ fi
18+ }
19+
1120[ -z " ${GITHUB_TOKEN} " ] && abort " Missing GITHUB_TOKEN env variable."
1221[ -z " ${GITHUB_USER} " ] && abort " Missing GITHUB_USER env variable."
1322[ -z " ${GITHUB_REPO} " ] && abort " Missing GITHUB_REPO env variable."
1423
15- VERSION=$( grep " version" lua_cliargs-* .rockspec | cut -d' ' -f3 | sed ' s/"//g' )
24+ VERSION=$1
25+ SRC_FILE=" src/cliargs.lua"
26+ # VERSION=$(grep "version" lua_cliargs-*.rockspec | cut -d' ' -f3 | sed 's/"//g')
1627SRC_VERSION=$( grep " _VERSION" src/cliargs.lua | sed -e ' s/.*=//' -e ' s/.* //' -e ' s/"//g' )
1728
18- [ " ${VERSION} " != " ${SRC_VERSION} " ] && abort " Verion in rockspec does not match source"
29+ NEW_ROCKSPEC=" lua_cliargs-${VERSION} .rockspec"
30+ OLD_ROCKSPEC=" lua_cliargs-${SRC_VERSION} .rockspec"
31+
32+ if [ " ${VERSION} " == " ${SRC_VERSION} " ]; then
33+ abort " Version specified is the same as the current one in rockspec"
34+ fi
1935
2036# Publish to GitHub
2137JSON_PAYLOAD=$(
@@ -32,6 +48,31 @@ JSON_PAYLOAD=$(
3248echo $JSON_PAYLOAD
3349echo " Releasing version ${VERSION} ..."
3450
51+ if [ ! -f $OLD_ROCKSPEC ]; then
52+ abort " Version in ${SRC_FILE} does not match the rockspec file!"
53+ fi
54+
55+ # rename rockspec file
56+ mv $OLD_ROCKSPEC $NEW_ROCKSPEC
57+
58+ # bump version in rockspec
59+ perl -p -i -e " s/${SRC_VERSION} /${VERSION} /g" $NEW_ROCKSPEC
60+
61+ # bump version in src
62+ perl -p -i -e " s/${SRC_VERSION} /${VERSION} /" $SRC_FILE
63+
64+ confirm " rockspec and source file have been modified, please confirm the changes. Proceed?"
65+
66+ echo " Creating git release v${VERSION} ..."
67+
68+ git add $NEW_ROCKSPEC
69+ git rm $OLD_ROCKSPEC
70+ git add $SRC_FILE
71+ git commit -m " Release v${VERSION} "
72+
73+ echo " Done."
74+ confirm " Create a new GitHub release?"
75+
3576# the API will automatically create the tag for us, no need to do it manually!
3677curl \
3778 --data " $JSON_PAYLOAD " \
@@ -40,4 +81,10 @@ curl \
4081 -H " Accept: application/json" \
4182 " https://api.github.com/repos/${GITHUB_USER} /${GITHUB_REPO} /releases?access_token=${GITHUB_TOKEN} "
4283
84+ echo " Done."
85+
86+ confirm " Publish to luarocks?"
87+
88+ luarocks upload $NEW_ROCKSPEC
89+
4390echo -e " \e[00;32m[ SUCCESS ]\e[00m"
0 commit comments