-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
192 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters