Platformio version increment

Hi all,
I have released this script:

to automatically increment version number when building your software using platformio.

I think that a feature like this should be implemented in platformio :slight_smile:

5 Likes

Oh… VERY NICE! :smiley: :heart: :heart: I’ll be using that in future! A perfect example of the power of PlatformIO and extra_scripts! :wink:

1 Like

thank you I really appreciate it.

I must be doing something wrong. When I try and install the scripts I get this error (I am running the CLI text in platformio window, if I should be running it somewhere else, please say so)
PS C:\Users\jim\OneDrive\Documents\PlatformIO\Projects\VE_BMV_MPPT_Display_V3-07> git submodule add GitHub - sblantipodi/platformio_version_increment: Simple versioning Python script for PlatformIO platformio_version_increment
fatal: not a git repository (or any of the parent directories): .git
PS C:\Users\jim\OneDrive\Documents\PlatformIO\Projects\VE_BMV_MPPT_Display_V3-07>

Found my issue - the project I was testing this in was not configured in git

2 Likes

Hi, your script sounds awesome. Exactly what I am looking for.
Can you explain to a beginner how to install?
Do I understand it correct that I have to run the command “git submodule add GitHub - sblantipodi/platformio_version_increment: Simple versioning Python script for PlatformIO platformio_version_increment” in the terminal in PlatformIO (in Visual Studio Code)?
It says

Do I have to do something to implement git?

Would be awesome if somebody could help or give me a hint where to find good explanation.

You need to have git installed and in your PATH (Git - Downloads).

1 Like

Perfect, its working :slight_smile: thanks!

I have found there another script which does an auto-increment of the version, maybe you can add some of these defines to your script as well, they might be usefull.

#define _VERSION_MAJOR 0 
#define _VERSION_MINOR 0
#define _VERSION_PATCH 1 
#define _VERSION_BUILD 41 
#define _VERSION_DATE 04-07-2020 
#define _VERSION_TIME 14:40:18 
#define _VERSION_ONLY 0.0.1 
#define _VERSION_NOBUILD 0.0.1 (04-07-2020) 
#define _VERSION 2.0.3+41 (04-07-2020)

I actually would add even more details like #define _VERSION_DATE_YEAR, #define _VERSION_DATE_MONTH, ... to make it more easy to access it within the program.

1 Like

Well these fancy solutions should work fine, but for me I did not need that overhead, therefore for my use-case I did NOT necessarily need an incremental number that is always increased by one, but any kind of ascending numbers is fine, therefore using timeticks was for me just fine.

In your platformio.ini:

[common]
firmware_version = '"0.1.0.${UNIX_TIME}"'

[env:release]
build_flags =
	-D FIRMWARE_VERSION=${common.firmware_version}

This shall give you a macro definition in the following format:

#define FIRMWARE_VERSION "0.1.0.1615469592"

According to my answer here:

1 Like

I know this thread is a bit old and i have tested a few of these options but is there a way to simply output the filename i.e. firmware.hex as firmware11_2_2021 0200 or something to that effect, I added #include “Version.h” to the top of my MarlinCore.cpp along with everything else needed but i do not get any incrementing, i still see firmware.hex in the build dir with a new timestamp

Follow the docs to implement any abitrary firmware naming logic you want.

Thank you, so are you saying use the

print(defines)

env.Replace(PROGNAME=“firmware_%s” % defines.get(“VERSION”)) along with this script or in place of? It really makes no difference to me what it’s called so long as it increments when i press build. Not really sure how this is not a checkbox option in Platformio. " Incrementing build names" Yes No? then just give a default option of date or time or random text.

The docs I linked you to show an example of how an extra script can use the information injected by build_flags = -D VERSION=13 to produce the firmware name firmware_13.elf (and .bin). It does not implement any date-time or increment logic, it’s just a starting point for programming that logic in yourself. You can e.g. combine that with the logic described in the repo in the first post to get the logic you want.

There’s no built-in “name firmware file with incrementing version and current date”, the default is firmware.bin/.elf, but with PlatformIO’s scripting capabilities, any logic is possible.

Thank you!, that really clears things up! much appreciated

I give up, i cannot get this to increment by 1 or time or anything. I will simply rename the previous firmware.hex and build new. I am guessing either something changed in the 2 years since sblantopodi’s release or configuring it requires MUCH more than is in the directions.

It just works. If I create a simple Uno project

mkdir ver_test
cd ver_test
pio init -b uno
git init 
git submodule add https://github.com/sblantipodi/platformio_version_increment.git platformio_version_increment

add

extra_scripts =
   pre:platformio_version_increment/version_increment_pre.py
   post:platformio_version_increment/version_increment_post.py

to platformio.ini.
src\main.cpp as

#include <Arduino.h>
#include <Version.h>

void setup() {
   Serial.begin(9600);
}
void loop() {
   Serial.println("Project version: " + String(VERSION));
   Serial.println("Build timestamp:" + String(BUILD_TIMESTAMP));
   delay(1000);
}

First upload & monitor:

>pio run -t upload -t monitor
[..]
====================== [SUCCESS] Took 5.27 seconds ======================
--- Miniterm on COM14  9600,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Project version: 0.1.0
Build timestamp:2021-11-04 14:22:31.948054
[..]

Next upload & monitor

>pio run -t upload -t monitor
[..]
--- Miniterm on COM14  9600,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Project version: 0.1.1
Build timestamp:2021-11-04 14:25:45.787950

Nicely version incremented and timestamp updated.

very interesting indeed!, i noticed i do not have a main.cpp so i added
#include <Version.h> to my MarlinCore.cpp, is that the correct location or should it be added to MarlinCore.h?
upon deeper inspection i also noticed my version.h is not being updated with
// AUTO GENERATED FILE, DO NOT EDIT THIS FILE
#ifndef VERSION
#define VERSION “0.1.0”
#endif
#ifndef BUILD_TIMESTAMP
#define BUILD_TIMESTAMP “2020-04-10 17:58:52.937616”
#endif

…You’re trying to add this in Marlin, okay. This is pretty much one of the most complicated and pimped-out PlatformIO projects there is. I thought you wanted version increments in your own small project.

Even if you add the platformio_version_increment project to it, if no code ever uses the Version.h header and uses the macros defined in it, it will effectly go unused. You’d have to add custom references to it.

What is the logic you want here in relation to marlin? Name the produced binaries after the Marlin version (e.g.) and current date? Marlin already has such a Version.h header (Marlin/Marlin/Version.h at 2.0.x · MarlinFirmware/Marlin · GitHub) that is auto-generated (Marlin/buildroot/bin/generate_version at 2.0.x · MarlinFirmware/Marlin · GitHub). It would conflict with the platformio_version_increment through both using Version.h.

Haha, of course i pick the most pimped out project there is…just my luck. perhaps i am going about this all wrong, I simply need/want/prefer upon pressing build in Platformio instead of the next firmware.hex overwriting the last, a new firmware_anything012021.hex is created and incremented, heck at this point i’d be happy with pressing build and a “Save As” dialogue box pop up but that seems even further away…lol