Skip to content

Commit

Permalink
Cleaned a little more. All Integration tests should pass now.
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaiaeroastro committed Jul 9, 2024
1 parent b26e6e6 commit 1ea936f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 41 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Run version extraction script and set environment variable
id: set-version
run: |
LIB3MF_VERSION=$(python CI/extract_version.py)
LIB3MF_VERSION=$(python CI/ci_cd_helper.py extract-version)
echo "LIB3MF_VERSION=$LIB3MF_VERSION" >> $GITHUB_OUTPUT
- name: Echo version for debug
run: echo "LIB3MF_VERSION=${{ steps.set-version.outputs.LIB3MF_VERSION }}"
Expand Down Expand Up @@ -563,7 +563,7 @@ jobs:
- name: Get latest lib3mf SDK release info from GitHub API
id: get_lib3mf_release
run: |
echo "LATEST_LIB3MF_URL=$(curl -s https://api.github.com/repos/3MFConsortium/lib3mf/releases/latest | grep "browser_download_url.*lib3mf_sdk.zip" | cut -d '"' -f 4 | xargs)" >> $GITHUB_ENV
echo "LATEST_LIB3MF_URL=$(python CI/ci_cd_helper.py fetch-sdk-url 0 | xargs)" >> $GITHUB_ENV
- name: Download latest lib3mf SDK zip
run: |
Expand Down Expand Up @@ -637,12 +637,12 @@ jobs:
- name: Get latest lib3mf SDK release info from GitHub API
id: get_latest_release
run: |
echo "LATEST_LIB3MF_URL=$(python CI/ci_cd_helper.py 0 --get-url | xargs)" >> $GITHUB_ENV
echo "LATEST_LIB3MF_URL=$(python CI/ci_cd_helper.py fetch-sdk-url 0 | xargs)" >> $GITHUB_ENV
- name: Get second latest lib3mf SDK release info from GitHub API
id: get_second_latest_release
run: |
echo "SECOND_LATEST_LIB3MF_URL=$(python CI/ci_cd_helper.py 1 --get-url | xargs)" >> $GITHUB_ENV
echo "SECOND_LATEST_LIB3MF_URL=$(python CI/ci_cd_helper.py fetch-sdk-url 1 | xargs)" >> $GITHUB_ENV
- name: Download latest lib3mf SDK zip
run: |
Expand All @@ -655,6 +655,8 @@ jobs:
- name: Unpack the latest SDK
run: |
unzip latest_lib3mf_sdk.zip -d latest_lib3mf_sdk
mv latest_lib3mf_sdk/lib3mf_sdk/* latest_lib3mf_sdk
rmdir latest_lib3mf_sdk/lib3mf_sdk
- name: Unpack the second latest SDK
run: |
Expand Down Expand Up @@ -871,7 +873,7 @@ jobs:
- name: Get latest lib3mf SDK release info from GitHub API
id: get_latest_release
run: |
echo "LATEST_LIB3MF_URL=$(curl -s https://api.github.com/repos/3MFConsortium/lib3mf/releases/latest | grep "browser_download_url.*lib3mf_sdk.zip" | cut -d '"' -f 4 | xargs)" >> $GITHUB_ENV
echo "LATEST_LIB3MF_URL=$(python CI/ci_cd_helper.py fetch-sdk-url 0 | xargs)" >> $GITHUB_ENV
LATEST_RELEASE_NAME=$(curl -s https://api.github.com/repos/3MFConsortium/lib3mf/releases/latest | grep '"tag_name"' | cut -d '"' -f 4)
echo "LATEST_RELEASE_NAME=${LATEST_RELEASE_NAME}" >> $GITHUB_ENV
Expand Down
48 changes: 44 additions & 4 deletions CI/ci_cd_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import argparse
import urllib.request
import json
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

def get_sdk_url(index):
url = "https://api.github.com/repos/3MFConsortium/lib3mf/releases"
Expand All @@ -21,18 +46,33 @@ def get_sdk_url(index):
return None

def main():
parser = argparse.ArgumentParser(description="Fetch a specific release URL for the 3MFConsortium/lib3mf repository.")
parser.add_argument('index', type=int, help='Index of the release (0 for latest, 1 for second latest, etc.)')
parser.add_argument('--get-url', action='store_true', help='Get the specified release URL')
parser = argparse.ArgumentParser(description="Multi-utility script for CI/CD.")

subparsers = parser.add_subparsers(dest='command')

# Subparser for the fetch-sdk-url command
parser_fetch_sdk_url = subparsers.add_parser('fetch-sdk-url', help='Fetch the SDK URL for a specific release index.')
parser_fetch_sdk_url.add_argument('index', type=int, help='Index of the release (0 for latest, 1 for second latest, etc.)')

# Subparser for the extract-version command
parser_extract_version = subparsers.add_parser('extract-version', help='Extract the version from CMakeLists.txt.')

args = parser.parse_args()

if args.get_url:
if args.command == 'fetch-sdk-url':
url = get_sdk_url(args.index)
if url:
print(url)
else:
print("FAIL")
elif args.command == 'extract-version':
try:
version = extract_version_from_cmake()
print(version)
except Exception as e:
print("FAIL")
else:
parser.print_help()

if __name__ == "__main__":
main()
32 changes: 0 additions & 32 deletions CI/extract_version.py

This file was deleted.

0 comments on commit 1ea936f

Please sign in to comment.