Skip to content

Commit

Permalink
improved and added deploy tool for pio projects
Browse files Browse the repository at this point in the history
  • Loading branch information
hpsaturn committed Jan 14, 2024
1 parent fb87c2d commit bc4e63b
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 5 deletions.
145 changes: 145 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/bin/bash

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

NAME=`cat platformio.ini | grep 'name =' | awk '{print $3}'`

if [[ -z "$NAME" ]]; then
NAME=`basename "$PWD"`
else
NAME=`echo "$NAME" | dos2unix`
fi

SRC_VER="${2}"
BUILD_DIR=.pio/build
DATE=`date +%Y%m%d`
RELDIR="releases"
RELNAME="${NAME}-v${SRC_VER}.zip"
OUTPUT="${RELDIR}/${RELNAME}"

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

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 -rf .pio
rm -f $OUTPUT
}

build () {
echo ""
echo "***********************************************"
echo "** Building v${SRC_VER}"
echo "***********************************************"
echo ""
cd $BUILD_DIR
array=(*/)
mkdir "tmp"
for dir in "${array[@]}"; do
flavor=`basename "${dir}"`
cp $dir/firmware.bin "tmp/${flavor}_firmware.bin"
cp $dir/partitions.bin "tmp/${flavor}_partitions.bin"
done
zip -r ../../${OUTPUT} tmp/*.bin
rm -r tmp
cd ../..
echo ""
echo "***********************************************"
echo "************** Build done *********************"
echo "***********************************************"
echo ""
md5sum $OUTPUT
du -hs $OUTPUT
echo ""
}

publish_release () {
echo ""
echo "***********************************************"
echo "********** Publishing release *****************"
echo "***********************************************"
echo ""
echo "Publishing release: v${SRC_VER}"
echo "uploading: ${OUTPUT}"
COMMIT_LOG=`git log -1 --format='%ci %H %s'`
git tag -a "${SRC_VER}" -m "release v${SRC_VER}"
git push origin "${SRC_VER}"
git log -n 10 --pretty=format:"%h %s" | gh release create "v${SRC_VER}" -F - -t "${SRC_VER}" -p ${OUTPUT}
echo ""
echo "***********************************************"
echo "************* done *********************"
echo "***********************************************"
echo ""
}

publish_pio () {
pio package publish
}

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

help)
showHelp
;;

--help)
showHelp
;;

-help)
showHelp
;;

-h)
showHelp
;;

print)
printOutput
;;

github)
publish_release
;;

*)
build $1
;;
esac
fi

exit 0

10 changes: 5 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
; https://docs.platformio.org/page/projectconf.html

[env]
version = 0.1.2

[env:esp32dev]
name = dcf77hat
platform = espressif32 @ 4.4.0
board = esp32dev
framework = arduino
upload_speed = 1500000
monitor_speed = 115200
Expand All @@ -22,5 +19,8 @@ monitor_filters =
build_flags =
-D CORE_DEBUG_LEVEL=0
lib_deps =
https://github.com/hpsaturn/M5StickC-Plus.git
https://github.com/hpsaturn/Arduino-DCF77.git
https://github.com/hpsaturn/M5StickC-Plus.git

[env:m5stickCplus]
board = esp32dev

0 comments on commit bc4e63b

Please sign in to comment.