GitHub Actions - Could not find current product version macro

Hello community!

I am using the Grove temperature sensor on a Boron, and using their example app. I've added the product version macro to the top of the file like so:

#include "Grove_Temperature_And_Humidity_Sensor.h"

PRODUCT_VERSION(1);

// An example of DHT11 for PHOTON

Compiling in Workbench is successful. I am trying to setup a GitHub action to compile the firmware. Here is my build.yaml:

name: Particle Firmware Build

on:
  push:
    branches:
      - main
    # paths:
    #   - src/**
    #   - .github/build.yaml

jobs:
  compile:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Compile Firmware
        id: compile
        uses: particle-iot/compile-action@v1
        with:
          particle-platform-name: "boron"
          device-os-version: '^4.2.0'
          particle-access-token: ${{ secrets.PARTICLE_ACCESS_TOKEN }}
          # auto-version: 'true'

I would like to get the auto-version to work, but have it commented out for now until I can ensure the product version macro is working, else it will error.

With the auto-version commented out, the GitHub action does succeed, but with this warning:

Could not find current product version macro, firmware-verion output will be undefined.

I'm sure I'm probably missing something simple or obvious, but have been over the documentation and videos several times now without beign able to pinpoint it. Any help would be much appreciated!

Thank you!
-Ryan

There's a better explanation of how auto-versioning works in the Github action source:

Hello Rick! Thank you for your response!

I have been through that documentation as well, and believe I have followed it. But since I am still at a loss, and you have pointed me there, I will try to ask some more clarifying questions around the document to make sure I'm not missing something.

Usage section:

I have followed the 1st and 2nd steps here. Step 2 was perfectly fine to add. Adding step 1 is where I get my errors.

Could not find current product version macro, firmware-verion output will be undefined.

I have left step 3 off, assuming it will use the default PRODUCT_VERSION macro.

How It Works section:

This section confuses me. What is a sources-folder? Is that simply where I have my app.cpp file? Does the editing happen automatically? Is this the macro code that sets it? PRODUCT_VERSION(1); Will auto-version change that 1 on it's own?

Also, when auto-version is turned on, what is changed (code, file, other) that then gets committed back to the git repository to store the version for next release?

The GitHub action step where this is done:

      - name: Commit updated version file
        id: commit
        if: steps.compile.outputs.firmware-version-updated == 'true'
        run: |
          git config user.name 'github-actions[bot]'
          git config user.email 'github-actions[bot]@users.noreply.github.com'
          git commit -m "Update firmware version" -a
          echo "updated-version-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

Like I side in OP, I must be missing something simple, but I still can't get it to work.

Thank you for your help!
Ryan

Yes, you need to include this:

PRODUCT_VERSION(1);

The action will update the source code to update the 1 on each build and commit the change. This is intended to be part of a release action, not a continuous integration test build.

The PRODUCT_VERSION macros sets a global variable in the source code, and this value is sent to the cloud when the device comes online. It's how the cloud knows which product firmware version you are running. There is no default value.

This needs to match the version that you set when you upload product firmware to a product, manually from the console, using the cloud API, or using the Github action. The cloud checks to make sure the constant in the code matches the version number you set in the request.

The version number increments by exactly one on each upload.

Thank you Rick. This is great, and definitely seems straight forward. Instead of my previous error:

Could not find current product version macro, firmware-verion output will be undefined.

I am now getting a new error (hopefully that is progress!):

Run particle-iot/compile-action@v1
with:
particle-platform-name: boron
device-os-version: ^4.2.0
particle-access-token: ***
auto-version: true
sources-folder: .
auto-version-macro-name: PRODUCT_VERSION
Auto-versioning is enabled, checking if firmware version should be incremented
Error: fatal: path 'src/app.cpp' exists on disk, but not in 'd57ec2f00a8c3447f8a4a33efdba9e9fff251b50'

I still seem to be missing something. Note that commit d57ec2f is several commits behind HEAD, not sure if that has something to do with it. Is there a relation of the version number to the file name?

Here is my whole build.yaml file:

# Particle Compile Action Workflow
# This workflow uses the Particle compile-action to compile Particle application firmware.
# Make sure to set the particle-platform-name for your project.
# For complete documentation, please refer to https://github.com/particle-iot/compile-action

name: Particle Firmware Build

on:
  push:
    branches:
      - main
    # paths:
    #   - src/**
    #   - .github/build.yaml

jobs:
  compile:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Compile Firmware
        id: compile
        uses: particle-iot/compile-action@v1
        with:
          particle-platform-name: "boron"
          device-os-version: '^4.2.0'
          particle-access-token: ${{ secrets.PARTICLE_ACCESS_TOKEN }}
          auto-version: 'true'

      - name: Upload Firmware as Artifact
        uses: actions/upload-artifact@v3
        with:
          name: firmware-artifact
          path: |
            ${{ steps.compile.outputs.firmware-path }}
            ${{ steps.compile.outputs.target-path }}

      # - name: Commit updated version file
      #   id: commit
      #   if: steps.compile.outputs.firmware-version-updated == 'true'
      #   run: |
      #     git config user.name 'github-actions[bot]'
      #     git config user.email 'github-actions[bot]@users.noreply.github.com'
      #     git commit -m "Update firmware version" -a
      #     echo "updated-version-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

      # - name: Flash device
      #   uses: particle-iot/flash-device-action@v1
      #   with:
      #     particle-access-token: ${{ secrets.PARTICLE_ACCESS_TOKEN }}
      #     device-id: 'abc123'
      #     firmware-path: ${{ steps.compile.outputs.firmware-path }}

And here is the whole app.cpp file:

#include "Grove_Temperature_And_Humidity_Sensor.h"

PRODUCT_VERSION(1);

// An example of DHT11 for PHOTON

#define DHTPIN D2 // set pin

unsigned long lastPublished = 0;
const long interval = 30000;

DHT dht(DHTPIN);

void setup()
{
    Serial.begin(9600);
    Serial.println("DHT11 Begin!!!");

    dht.begin();
}

void loop()
{
    unsigned long currentMillis = millis();

    if (currentMillis - lastPublished >= interval)
    {
        lastPublished = currentMillis;

        float h = dht.getHumidity();
        float t = dht.getTempCelcius();
        float f = dht.getTempFarenheit();

        if (isnan(h) || isnan(t) || isnan(f))
        {
            Serial.println("Failed to read from DHT11 sensor!");
            return;
        }

        Particle.publish("data", "{humidity:" + String(h) + ",tempc:" + String(t) + ",tempf:" + String(f) + "}", PRIVATE);
    }
}