Skip to content

Commit

Permalink
amend workflow build and versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoKle committed Apr 9, 2024
1 parent cf672d8 commit 1701450
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 21 deletions.
42 changes: 33 additions & 9 deletions .github/workflows/build-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,50 @@ name: Build Plugin Dev Release
on:
push:
branches:
- develop
- "develop"

env:
DLL_NAME: vACDM.dll
BUILD_CONFIGURATION: Release
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: "0"
DEV_RELEASE: "-1"

jobs:
build-and-test:
formatting-check:
uses: ./.github/workflows/clang-format.yml

build:
needs: formatting-check
runs-on: windows-latest
name: "Build plugin"

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub
- name: Run version handler
env:
REPOSITORY: ${{ github.repository }}
REF: ${{ github.ref }}
run: |
python .github/workflows/version_handler.py
- name: Determine DEV_RELEASE value
id: find_latest_dev_release
env:
REPOSITORY: ${{ github.repository }}
run: python .github/workflows/determine_dev_release.py

- name: Install MSVC toolset
run: choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"

Expand All @@ -28,23 +57,18 @@ jobs:
Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"
- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_CONFIGURATION}} -A Win32
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_CONFIGURATION}} -A Win32 -DDEV_BUILD=ON -DDEV_RELEASE_NUMBER="${{ env.DEV_RELEASE }}"

- name: Build DLL
run: cmake --build build --config ${{env.BUILD_CONFIGURATION}}

- name: Extract version from CMakeLists.txt
run: |
$version = Select-String -Path CMakeLists.txt -Pattern 'PROJECT\(.*?VERSION\s+"(\d+\.\d+\.\d+)"' | ForEach-Object { $_.Matches.Groups[1].Value }
echo "VERSION=${version}-dev" >> $env:GITHUB_ENV
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: v${{ env.VERSION }}
release_name: v${{ env.VERSION }}
draft: false
draft: true # to allow amendment of release notes
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
29 changes: 23 additions & 6 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ env:
DLL_NAME: vACDM.dll
BUILD_CONFIGURATION: Release
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: "0"

jobs:
build-and-test:
formatting-check:
uses: ./.github/workflows/clang-format.yml

build:
needs: formatting-check
runs-on: windows-latest
name: "Build plugin"

Expand All @@ -21,6 +26,23 @@ jobs:
- name: Install MSVC toolset
run: choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub
- name: Run version handler
env:
REPOSITORY: ${{ github.repository }}
REF: ${{ github.ref }}
run: |
python .github/workflows/version_handler.py
- name: Set up MSVC environment
shell: pwsh
run: |
Expand All @@ -33,11 +55,6 @@ jobs:
- name: Build DLL
run: cmake --build build --config ${{env.BUILD_CONFIGURATION}}

- name: Extract version from CMakeLists.txt
run: |
$version = Select-String -Path CMakeLists.txt -Pattern 'PROJECT\(.*?VERSION\s+"(\d+\.\d+\.\d+)"' | ForEach-Object { $_.Matches.Groups[1].Value }
echo "VERSION=${version}" >> $env:GITHUB_ENV
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: clang-format Check
on: [push, pull_request]
on: [workflow_call, pull_request]
jobs:
formatting-check:
name: Formatting Check
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/cmake_project_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
""" Finds the project version defined in CMakeLists.txt"""

import sys
import re


def extract_version_from_cmakelists():
# Define the pattern to search for in the file
pattern = r'PROJECT\(.*?VERSION\s+"(\d+\.\d+\.\d+)"'

# Read the contents of CMakeLists.txt
with open("CMakeLists.txt", "r") as file:
contents = file.read()

# Search for the pattern
match = re.search(pattern, contents)

# If a match is found, extract the version
if match:
print("Found version number in CMakeLists.txt: ", match.group(1))
return match.group(1)

# exit if the version could not be found
print("Could not find version in CMakeLists.txt")
sys.exit(1)
57 changes: 57 additions & 0 deletions .github/workflows/determine_dev_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import sys
import re
from github import Github


def parse_semantic_version(version):
# Parse the semantic version and extract major and minor versions
match = re.match(r"v?(\d+)\.(\d+)\.(\d+)", version)
if match:
print(match.groups())
major, minor, patch = match.groups()
return int(major), int(minor), int(patch)
else:
return None


def find_highest_dev_release(repo, major, minor):
# Initialize a GitHub instance
g = Github()

# Get the repository object
repository = g.get_repo(repo)

# Fetch all releases
releases = repository.get_releases()

# Filter pre-releases with matching major and minor versions in their titles
pre_releases = [
release
for release in releases
if release.prerelease and release.title.startswith(f"v{major}.{minor}")
]

# Extract DEV_RELEASE numbers from titles
dev_releases = [int(release.title.split(".")[-1]) for release in pre_releases]

# Find the highest DEV_RELEASE number
highest_dev_release = max(dev_releases, default=0)

return highest_dev_release


def determine_dev_release(version, repository):
if version == "0":
result = 0
else:
# Parse the semantic version to extract major and minor versions
major, minor, _ = parse_semantic_version(version)
if major is not None and minor is not None:
result = find_highest_dev_release(repository, major, minor)
else:
print("Invalid semantic version format")
sys.exit(1)

print("Determined dev release version as ", result)

return result
34 changes: 34 additions & 0 deletions .github/workflows/version_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
""" """

import sys
import os
import re

from cmake_project_version import extract_version_from_cmakelists
from determine_dev_release import determine_dev_release

REPOSITORY_NAME = os.environ.get("REPOSITORY")
REF = os.environ.get("REF")

# determine the branch that triggered the workflow
match = re.match(r"refs/heads/(.*)", REF)
if not match:
sys.exit(1)

branch_name = match.group(1)
print("Determined branch name: ", branch_name)

version = extract_version_from_cmakelists()

is_dev_branch = branch_name == "develop"
dev_release = None
if is_dev_branch:
last_dev_release = determine_dev_release(version, REPOSITORY_NAME)
dev_release = str(last_dev_release + 1)
version += "-dev." + dev_release

# Write the version and dev release to GitHub environment variable
with open(os.getenv("GITHUB_ENV"), "a") as env_file:
env_file.write(f"VERSION={version}\n")
if is_dev_branch and dev_release:
env_file.write(f"DEV_RELEASE={dev_release}\n")
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.14)

PROJECT(vACDM VERSION "1.3.1")
PROJECT(vACDM VERSION "1.3.0")
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -23,8 +23,13 @@ IF (MSVC)
ADD_DEFINITIONS(/D_USRDLL)
ENDIF ()

if(DEV_BUILD)
ADD_DEFINITIONS(-DDEV_BUILD)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-DDEBUG_BUILD=1)
ADD_DEFINITIONS(-DDEBUG_BUILD=1) # enables log output to console window
ADD_DEFINITIONS(-DDEV_BUILD)
endif()

CONFIGURE_FILE(
Expand Down
11 changes: 8 additions & 3 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"cmakeCommandArgs": "-DDEV_BUILD=ON",
"ctestCommandArgs": "",
"inheritEnvironments": ["msvc_x86"],
"variables": []
"variables": [
{
"name": "DEV_RELEASE_NUMBER",
"value": "-1",
"type": "STRING"
}
]
}
]
}
4 changes: 4 additions & 0 deletions src/Version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
// prevents C2018 during compilation
namespace {
const char *PLUGIN_NAME{ "vACDM" };
#if DEV_BUILD
const char *PLUGIN_VERSION{ "@CMAKE_PROJECT_VERSION@-DEV.@DEV_RELEASE_NUMBER@"};
#else
const char *PLUGIN_VERSION{ "@CMAKE_PROJECT_VERSION@" };
#endif
const char *PLUGIN_AUTHOR{ "vACDM Team" };
const char *PLUGIN_LICENSE{ "GPLv3" };

Expand Down

0 comments on commit 1701450

Please sign in to comment.