Pulling Git Version Semantic tag into Project

Apologies if I have missed any other posts on this.

Using Perspective, 8.3.1. Windows server 2022.

I am using GitHub as SCS for a global perspective project that many sites will use. To ensure alignment on the versions of the app being used across sites I am using tags in Git to record app commit versions.

When testing this week I am cloning the project from GitHub to a new server/gateway and I can see the tag value in the project folder structure: in ‘.git’. Happy days!

Trying to pull that string value, say v1.3.1, into a gateway tag to use for a visual is the next challenge.

I have tried some clunky gateway scripts that look for the latest value in the project folder structure, but it does not feel slick, feels like a workaround.

With more SCS ‘fluency’ in 8.3 is there an easier way to do this? Have I missed something?

Or would this be a suggestion? Maybe push the most recent value into the Views session props?

My own clunky way..

`def onUpdate(actor, resources):
#Grabbing the git tag latest version to write into a gateway tag
#Thank you Co-Pilot!!!!
import subprocess
logger = system.util.getLogger('clockInApp')

#Repo & Git
project_path = r"C:\Program Files\Inductive Automation\Ignition\data\projects\ClockIn"
git_exe = r"C:\Program Files\Git\bin\git.exe"
#Git wants forward slashes in safe.directory
safe_path = project_path.replace("\\", "/")

def run_git(args):
    cmd = [git_exe, "-c", "safe.directory=%s" % safe_path] + args
    return subprocess.check_output(cmd, cwd=project_path).strip()

try:
    #Try describe first
    try:
        latest_tag = run_git(["describe", "--tags", "--abbrev=0"])
    except subprocess.CalledProcessError:
        # Fallback to newest tag by date
        tags = run_git(["tag", "--sort=-creatordate"]).splitlines()
        latest_tag = tags[0] if tags else "<no tag>"
            
    logger.info("Resolved latest tag: %s" % latest_tag)
    system.tag.writeBlocking("[default]ClockIn/versionNum", [latest_tag])

except Exception as e:
    logger.error("Git command failed: %s" % e)`


Calling out to a git describe sub-process on project update and storing the result in a tag is the method we use in our system. I did use the --always and --broken options to git describe so that we always get something even if the system somehow lands on an unexpected or corrupted spot in git.

Thank you Justin, glad to hear someone is doing it in a similar way.

I did add your suggestions, but did not like seeing -dirty in my app front screen :slight_smile:

Have added..

latest_tag = run_git([    "describe", "--tags", "--abbrev=0", "--always", "--broken", "--dirty="])
1 Like