diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0b01bf090..c21078bf5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/CI/extract_version.py b/CI/extract_version.py new file mode 100644 index 000000000..4fc0b0d53 --- /dev/null +++ b/CI/extract_version.py @@ -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)}") \ No newline at end of file