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);
    }
}

@Support -- can we get some eyes on this?

1 Like

Hi Ryan,

I can answer a few questions to help find a path forward.

sources-folder is typically the root folder of your Particle project.

With auto-version enabled, the editing happens automatically. compile-action attempts to detect if there have been any code changes committed to git since the last time the macro was set (using git history). Here is an example of a successful auto version commit from this Action configuration.

Your Action YAML configuration is valid, but this error is challenging to reproduce. It looks like the compile-action is encountering issues finding the current value of PRODUCT_VERSION in your git repo. Sharing a bit of your git history may help: git log d57ec2f00...HEAD and git log d57ec2f00...main

Manually bumping the value of PRODUCT_VERSION can also resolve issues with git history, since a new commit resets the latest version (from the eyes of the auto version feature).

One other note: the auto-version feature is most useful during a release pipeline since it automatically bumps the PRODUCT_VERSION macro before uploading a new firmware binary to a Particle product. You may not need the auto-version feature if your CI pipeline isn't uploading a new firmware binary. Here's an example project that has distinct build and release/upload pipelines. Only the upload pipeline uses the auto-version feature.

3 Likes

Thanks @laupow!

Does the name of the file you have PRODUCT_VERSION(1); in matter for anything (currently app.cpp)? I did change the file name once and am wondering if that has messed with anything.

I agree, I will eventually break out to separate pipelines for CI vs CD. But figured to keep it simple for now while we debug and get it working.

I manually bumped to version 10 just now (I did manual bumping before, so started fresh at 10) but got the same error.

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'

Here is the commit history. I have highlighted the commit sha that the error is referencing d57ec2f.

It is very far back in history. And interestingly is when I renamed that file back to app.cpp (after thinking that the name might be part of the problem).

Edit:
I noticed there are examples (and the tracker code itself) uses a config variable for the version number instead: PRODUCT_VERSION(TRACKER_PRODUCT_VERSION);. Should I attempt that, or does that just make it harder to debug?

Also note that I had the pipeline working before trying to add auto-version back in:

I reproduced an issue where the Action crashed in a method similar to yours. It happened when the file with the PRODUCT_VERSION macro was deleted at one point in the git history. This is likely the bug you're running into. The issue didn't show up when renaming a file, interestingly.

A fix should come out this week. You won't need to change anything to get the changes. I am optimistic it'll solve your specific issue as well.

Does the name of the file you have PRODUCT_VERSION(1); in matter for anything (currently app.cpp)?

Nope, it does not.

I noticed there are examples (and the tracker code itself) uses a config variable for the version number instead: PRODUCT_VERSION(TRACKER_PRODUCT_VERSION);. Should I attempt that, or does that just make it harder to debug?

I don't think this is related to your issue.

But if you're using a derivative or fork of Tracker Edge that has a line like this, I would recommend setting this parameter in your compile-action params to target the line with the version number specifically.

auto-version-macro-name: 'TRACKER_PRODUCT_VERSION'

Awesome! I will check it later. Glad I could be of assistance! Thank you @laupow for debugging and digging in!

This fixed my issue! Thank you!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.