Skip to content

Commit

Permalink
fix: Dynamic versioning should cut off initial v on prefixed semver (#70
Browse files Browse the repository at this point in the history
)
  • Loading branch information
doosuu authored Sep 14, 2023
1 parent e007dde commit 8ef265d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/sdk-build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ jobs:
images: |
ghcr.io/${{ github.repository }}
- name: Generate version.txt
run: |
pip install conan==1.60.2
conan export .
cat ./version.txt
- name: "Build image"
id: image_build
uses: docker/[email protected]
Expand All @@ -65,3 +71,4 @@ jobs:
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: .
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ conan_imports_manifest.txt

# conan home
.conan_home

# auto-generated SDK version
version.txt
13 changes: 10 additions & 3 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
import subprocess
import os
import re

class VehicleAppCppSdkConan(ConanFile):
name = "vehicle-app-sdk"
Expand Down Expand Up @@ -46,16 +47,22 @@ class VehicleAppCppSdkConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

exports = "version.txt"

# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = ".scripts/common.sh", "build.sh", "install_dependencies.sh", "CMakeLists.txt", "sdk/*", "examples/*", "conanfile.py", ".conan/profiles/*", "version.txt"

def set_version(self):
try:
git = tools.Git(folder=".")
version = git.get_tag() if git.get_tag() is not None else git.get_branch()
tag = git.get_tag()
if tag is not None:
version_tag_pattern = re.compile(r"^v[0-9]+(\.[0-9]+){0,2}")
if version_tag_pattern.match(tag):
tag = tag[1:] # cut off initial v if a semver tag

version = tag if tag is not None else git.get_branch()
if version == "HEAD (no branch)":
version = git.get_commit()
open("./version.txt", mode="w", encoding="utf-8").write(version)
Expand Down
3 changes: 2 additions & 1 deletion sdk/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ COPY . /sdk
RUN --mount=type=cache,target=/root/.conan

RUN cd /sdk && \
./install_dependencies.sh -r --build-all-deps
./install_dependencies.sh -r --build-all-deps && \
cd / && rm -rf /sdk

0 comments on commit 8ef265d

Please sign in to comment.