Skip to content

Commit

Permalink
basic tool for deploy releases to github and PlatformIO
Browse files Browse the repository at this point in the history
  • Loading branch information
hpsaturn committed Jul 9, 2022
1 parent 888d655 commit b78c3b4
Showing 1 changed file with 158 additions and 0 deletions.
158 changes: 158 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#!/bin/bash

######################################################
# CanAirIO deploy release utility
#
# Author: @hpsaturn
# 2021
######################################################

SRC_VER=`cat library.properties | grep version | sed -n -e 's/^.*version=//p'`
HDR_VER=`cat src/ESP32WifiCLI.hpp | grep ESP32WIFICLI_VERSION | awk '{ print $3 }'`
SRC_REV=`cat src/ESP32WifiCLI.hpp | grep ESP32WIFICLI_REVISION | awk '{ print $3 }'`
DATE=`date +%Y%m%d`
RELDIR="releases"
gituser="hpsaturn"
gitrepo="esp32-wifi-cli"
RELNAME="ESP32WifiCLI-${SRC_VER}.tar.gz"
OUTPUT="${RELDIR}/${RELNAME}"

showHelp () {
echo ""
echo "************************************************"
echo "** Build and deploy tag and release **"
echo "************************************************"
echo ""
echo "Usage alternatives:"
echo ""
echo "./deploy.sh test"
echo "./deploy.sh clean"
echo "./deploy.sh build"
echo "./deploy.sh github"
echo "./deploy.sh pio"
echo ""
}

validate_version() {
if [ "\"${SRC_VER}\"" != "${HDR_VER}" ]; then
echo ""
echo "Error: Version mistmatch with header version!"
echo ""
echo "revision library: $SRC_REV"
echo "version library : \"$SRC_VER\""
echo "version header : $HDR_VER"
exit 1
fi
}

validate_branch () {
current_branch=`git rev-parse --abbrev-ref HEAD`

if [ ${current_branch} != "master" ]; then
echo ""
echo "Error: you are in ${current_branch} branch please change to master branch."
echo ""
exit 1
fi
}

clean () {
rm -f $OUTPUT
}

runtest () {
pio run --target clean && pio run
}

build () {
mkdir -p $RELDIR
echo ""
echo "***********************************************"
echo "** Building rev$SRC_REV ($SRC_VER)"
echo "***********************************************"
echo ""
pio package pack -o $RELDIR/
echo ""
tar ztf $OUTPUT
echo ""
echo "***********************************************"
echo "************** Build done *********************"
echo "***********************************************"
echo ""
md5sum $OUTPUT
echo ""
}

publish_release () {
echo ""
echo "***********************************************"
echo "********** Publishing release *****************"
echo "***********************************************"
echo ""
COMMIT_LOG=`git log -1 --format='%ci %H %s'`
github-release upload --owner ${gituser} --repo ${gitrepo} --tag "v${SRC_VER}" --release-name "v${SRC_VER} rev${SRC_REV}" --body "${COMMIT_LOG}" $OUTPUT
echo ""
echo "***********************************************"
echo "************* done *********************"
echo "***********************************************"
echo ""
}

publish_pio () {
pio package publish
}

if [ "$1" = "" ]; then
showHelp
else
validate_version
validate_branch
case "$1" in
clean)
clean
;;

test)
runtest
;;

help)
showHelp
;;

--help)
showHelp
;;

-help)
showHelp
;;

-h)
showHelp
;;

print)
printOutput
;;

pio)
publish_pio
;;

publish)
publish_release
;;

github)
publish_release
;;

*)
build $1
;;
esac
fi

exit 0

0 comments on commit b78c3b4

Please sign in to comment.