Versioning and ESP32 OTA updates.
I have this thing running on an ESP32 I also need to update it over the air (OTA) and it depends on version numbers that change per release.
The Apache server links to the code. The version file need to be updated each time a realease is, cough, released.
How to deal with such things?
I use git, who doesn't, and derive my version numbers from the last commit date plus the commit count for that day.
So I get version that look like 20210307-5, which is the 7'th commit on the date 2021-03-07. Simple as fuck right?
I'm using a modified version of https://github.com/olivergregorius/micropython_ota to do the OTA updates. It's modfied beacause I have subdirectories for web stuff that it doesn't cope with and it works well. My version numbers are generated with a git hook. However a version is not a release. Id really like to use git tags to generate the release verion the the micropython_ota uses to update the code in the ESP32.
I need to modify the hook to create a release file of similar format. My post-commit hook looks like:
#!/usr/bin/bash
# Update a version header file.
# Only run this branch is main, bug branches don't have releases.
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if
then
exit 1
fi
ROOT=$(git rev-parse --show-toplevel)
DATE=$(date +%Y%m%d)
#How many commits today?
COMMITS=$(git rev-list HEAD --count --since="yesterday" -- $ROOT/src/)
COMMITS=$(echo "$COMMITS" | bc)
REV=$DATE.$COMMITS
#RELEASE=$(git describe --tags --abbrev=0)
RELEASE=V$REV
echo $RELEASE
# For C or C++ projects. This assumes the path src exists.
if [ -f $ROOT/src/version.h ]
then
echo "/* Version number by date and daily commits.*/" > $ROOT/src/version.h
echo "#include <avr/eeprom.h>" >> $ROOT/src/version.h
echo "const char version[18] EEMEM = \"Ver: $REV\";" >> $ROOT/src/version.h
git add $ROOT/src/version.h
fi
# For Python projects
if [ -f $ROOT/src/version.py ]
then
echo "# Version number by date and daily commits." > $ROOT/src/version.py
echo "__version__ = \"$REV\"" >> $ROOT/src/version.py
echo "Creating links and version."
echo $RELEASE > $ROOT/version
#rm $ROOT/$RELEASE
ln -s $ROOT/src $ROOT/$RELEASE
echo $RELEASE > $ROOT/src/release
fi
I just need to use this to make the micropython_ota and Apache links play nice without have be root anytime I create a new release.
An identical hook, or a link, name post-merge enables bug development on a separeate branch and the versions are updated when meged into main. If it's not "main" branch then the hooks are ignored.
Last changed: 8. March, 2023 at 22:59
Back to Overview