From 10964782deb5808fc4b49861f16444ebbeb9ca38 Mon Sep 17 00:00:00 2001 From: AntoinePrv Date: Thu, 21 Dec 2023 10:00:47 +0100 Subject: [PATCH] Strong dev and pre release check --- .github/workflows/release.yml | 4 +++- fetch_release.py | 42 ++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0ea677f..2850ff1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,9 @@ jobs: - shell: bash -l {0} id: fetch-release - run: python fetch_release.py ${{ github.event.inputs.version }} + run: | + python -m pip install packaging + python fetch_release.py ${{ github.event.inputs.version }} - name: Release uses: softprops/action-gh-release@v1 diff --git a/fetch_release.py b/fetch_release.py index 703d69b..3b7c594 100644 --- a/fetch_release.py +++ b/fetch_release.py @@ -3,22 +3,24 @@ import requests import rich from pathlib import Path -from datetime import timedelta import hashlib import subprocess import sys +from packaging.version import Version + cache = {} known_subdirs = { - 'linux-64', - 'linux-ppc64le', - 'linux-aarch64', - 'osx-64', - 'osx-arm64', - 'win-64' + "linux-64", + "linux-ppc64le", + "linux-aarch64", + "osx-64", + "osx-arm64", + "win-64", } + def get_all_tags_github(): url = "https://api.github.com/repos/mamba-org/micromamba-releases/tags" r = requests.get(url, timeout=10) @@ -26,15 +28,20 @@ def get_all_tags_github(): tags = [t["name"] for t in r.json()] return set(tags) + def extract_with_microamamba(archive, outdir): - subprocess.check_call(["micromamba", "package", "extract", str(archive), str(outdir)]) + subprocess.check_call( + ["micromamba", "package", "extract", str(archive), str(outdir)] + ) + def set_output(name, value): if os.environ.get("GITHUB_OUTPUT"): - with open(os.environ.get("GITHUB_OUTPUT"), 'a') as fh: - print(f'{name}={value}\n', file=fh) + with open(os.environ.get("GITHUB_OUTPUT"), "a") as fh: + print(f"{name}={value}\n", file=fh) -def get_micromamba(version='latest'): + +def get_micromamba(version="latest"): url = f"https://api.anaconda.org/release/conda-forge/micromamba/{version}" existing_tags = get_all_tags_github() print("Getting Anaconda.org API") @@ -48,13 +55,13 @@ def get_micromamba(version='latest'): if not known_subdirs.issubset(all_subdirs): raise ValueError(f"Missing subdirs: {known_subdirs - all_subdirs}") - + all_versions = set([d["version"] for d in rj["distributions"]]) - assert(len(all_versions) == 1) + assert len(all_versions) == 1 version = all_versions.pop() - if "alpha" in version or "beta" in version: - print("Skipping alpha/beta version") + if (v := Version(version)).is_devrelease or v.is_prerelease: + print(f"Skipping dev and pre releases version '{version}'") set_output("MICROMAMBA_NEW_VERSION", "false") return @@ -78,11 +85,10 @@ def get_micromamba(version='latest'): dplat = d["attrs"]["subdir"] - # fetch file and extract it + # fetch file and extract it r = requests.get(f"https:{url}", timeout=10) r.raise_for_status() - path = Path(d["basename"]) if d["basename"].endswith(".tar.bz2"): ext = ".tar.bz2" @@ -138,4 +144,4 @@ def get_micromamba(version='latest'): if len(sys.argv) > 1: get_micromamba(sys.argv[1]) else: - get_micromamba() \ No newline at end of file + get_micromamba()