diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 866a544b9..a8eaaf94e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -637,12 +637,12 @@ 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 0 --get-url | 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=$(curl -s https://api.github.com/repos/3MFConsortium/lib3mf/releases | grep "browser_download_url.*lib3mf_sdk.zip" | cut -d '"' -f 4 | sed -n '2p' | xargs)" >> $GITHUB_ENV + echo "SECOND_LATEST_LIB3MF_URL=$(python CI/ci_cd_helper.py 1 --get-url | xargs)" >> $GITHUB_ENV - name: Download latest lib3mf SDK zip run: | diff --git a/CI/ci_cd_helper.py b/CI/ci_cd_helper.py new file mode 100644 index 000000000..e633d23ae --- /dev/null +++ b/CI/ci_cd_helper.py @@ -0,0 +1,38 @@ +import argparse +import urllib.request +import json + +def get_sdk_url(index): + url = "https://api.github.com/repos/3MFConsortium/lib3mf/releases" + + try: + with urllib.request.urlopen(url) as response: + data = response.read().decode('utf-8') + + releases = json.loads(data) + selected_release = releases[index] # Select the release by index + for asset in selected_release['assets']: + asset_name = str(asset['name']) + if asset_name.startswith("lib3mf_sdk") and asset_name.endswith(".zip"): + return asset['browser_download_url'] + return None + except Exception as e: + print(f"Error fetching the SDK URL: {e}") + 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') + + args = parser.parse_args() + + if args.get_url: + url = get_sdk_url(args.index) + if url: + print(url) + else: + print("FAIL") + +if __name__ == "__main__": + main()