Skip to content

Commit

Permalink
switch to a script instead
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaiaeroastro committed Jun 3, 2024
1 parent c344f8c commit ff6f11f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
34 changes: 5 additions & 29 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,12 @@ jobs:
submodules: true
- run: ls -al
- run: cat CMakeLists.txt
- name: Extract and set LIB3MF_VERSION
- name: Run version extraction script and set environment variable
run: |
set -e # Exit immediately if a command exits with a non-zero status.
# Extract version components from CMakeLists.txt
LIB3MF_VERSION_MAJOR=$(grep -oP 'set\(LIB3MF_VERSION_MAJOR \K[0-9]+' CMakeLists.txt)
LIB3MF_VERSION_MINOR=$(grep -oP 'set\(LIB3MF_VERSION_MINOR \K[0-9]+' CMakeLists.txt)
LIB3MF_VERSION_MICRO=$(grep -oP 'set\(LIB3MF_VERSION_MICRO \K[0-9]+' CMakeLists.txt)
LIB3MF_VERSION_PRERELEASE=$(grep -oP 'set\(LIB3MF_VERSION_PRERELEASE "\K[^"]+' CMakeLists.txt)
# Debug prints
echo "LIB3MF_VERSION_MAJOR=$LIB3MF_VERSION_MAJOR"
echo "LIB3MF_VERSION_MINOR=$LIB3MF_VERSION_MINOR"
echo "LIB3MF_VERSION_MICRO=$LIB3MF_VERSION_MICRO"
echo "LIB3MF_VERSION_PRERELEASE=$LIB3MF_VERSION_PRERELEASE"
# Combine the version components
if [ -z "$LIB3MF_VERSION_PRERELEASE" ]; then
LIB3MF_VERSION="${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}"
else
LIB3MF_VERSION="${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}-${LIB3MF_VERSION_PRERELEASE}"
fi
# Set the environment variable
# echo "LIB3MF_VERSION=$LIB3MF_VERSION" >> $GITHUB_ENV
# Always exit with success
exit 0
- name: Print GITHUB_ENV contents
run: cat $GITHUB_ENV
version=$(python CI/extract_version.py)
echo "LIB3MF_VERSION=$version" >> $GITHUB_ENV
- name: Print GITHUB_ENV contents
run: cat $GITHUB_ENV
build-linux-memtest:
runs-on: ubuntu-20.04
Expand Down
32 changes: 32 additions & 0 deletions CI/extract_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import re

def extract_version_from_cmake():
cmake_file = 'CMakeLists.txt'

if not os.path.exists(cmake_file):
raise FileNotFoundError(f"{cmake_file} not found in the current directory")

with open(cmake_file, 'r') as file:
content = file.read()

major = re.search(r'set\(LIB3MF_VERSION_MAJOR\s+([0-9]+)\)', content)
minor = re.search(r'set\(LIB3MF_VERSION_MINOR\s+([0-9]+)\)', content)
micro = re.search(r'set\(LIB3MF_VERSION_MICRO\s+([0-9]+)\)', content)
prerelease = re.search(r'set\(LIB3MF_VERSION_PRERELEASE\s+"([^"]*)"\)', content)

if not major or not minor or not micro:
raise ValueError("Could not find version components in CMakeLists.txt")

version = f"{major.group(1)}.{minor.group(1)}.{micro.group(1)}"
if prerelease and prerelease.group(1):
version += f"-{prerelease.group(1)}"

return version

if __name__ == "__main__":
try:
version = extract_version_from_cmake()
print(version)
except Exception as e:
print(f"Error: {str(e)}")

0 comments on commit ff6f11f

Please sign in to comment.