From 2f98e95757e99ca40ca1dd78ff672d7c3fad5c91 Mon Sep 17 00:00:00 2001 From: Valentin Buira Date: Fri, 2 May 2025 18:51:25 +0200 Subject: [PATCH] Add get_latest_qgis_version.py script --- .github/workflows/try-latest-version.yml | 16 ++++-- scripts/get_latest_qgis_versions.py | 66 ++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 scripts/get_latest_qgis_versions.py diff --git a/.github/workflows/try-latest-version.yml b/.github/workflows/try-latest-version.yml index ff3dfcc465d..aa3767b83f0 100644 --- a/.github/workflows/try-latest-version.yml +++ b/.github/workflows/try-latest-version.yml @@ -11,6 +11,12 @@ jobs: check_version_reported: runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Get version details + run: | + python ./scripts/get_latest_qgis_versions.py --release="stable" --github_token=${{ secrets.GITHUB_TOKEN }} >> $GITHUB_ENV - name: Write comment uses: actions/github-script@v7 with: @@ -53,9 +59,9 @@ jobs: return 0 } - // We need to update these variable when we release a new version - var LATEST_LTR_RELEASE = "3.40.7" - var LATEST_RELEASE = "3.42.3" + // Latest released version identified using get_latest_qgis_versions + var LATEST_LTR_RELEASE = {ENV.QGIS_VERSION_LTR_PATCH} + var LATEST_STABLE_RELEASE = {QGIS_VERSION_STABLE_PATCH} // Match qgis version reported e.g : "3.40.0-Bratislava" var regex = /(\d)\.(\d{2})\.(\d*)-[A-Z]{1}[a-z]+/ @@ -93,10 +99,10 @@ jobs: else if ( compareSemanticVersions(user_version, LATEST_LTR_RELEASE) === 0 ) { console.log("Debug: user is already running latest LTR version") } - else if ( compareSemanticVersions(user_version, LATEST_RELEASE) === -1 ) { + else if ( compareSemanticVersions(user_version, LATEST_STABLE_RELEASE) === -1 ) { console.log("Debug: Suggest user to try latest release") - let comment = `Thanks for reporting, however it looks like you are using an older version of QGIS (version ${user_version}) instead of latest (Version ${LATEST_RELEASE}). Your bug could already resolved in the latest version. \nIt takes a lot of human effort to triage all the bugs in a project like QGIS, could you please retry with the latest version first?` + let comment = `Thanks for reporting, however it looks like you are using an older version of QGIS (version ${user_version}) instead of latest (Version ${LATEST_STABLE_RELEASE}). Your bug could already resolved in the latest version. \nIt takes a lot of human effort to triage all the bugs in a project like QGIS, could you please retry with the latest version first?` github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, diff --git a/scripts/get_latest_qgis_versions.py b/scripts/get_latest_qgis_versions.py new file mode 100644 index 00000000000..8b4f48c6032 --- /dev/null +++ b/scripts/get_latest_qgis_versions.py @@ -0,0 +1,66 @@ +import json +import re + +import click +import requests + + +@click.command() +@click.option( + "--release", + help="Which release to extract. `ltr` or `stable` assume release are tagged as final-x_x_x or ltr-x_x_x", +) +@click.option( + "--github_token", + default=None, + help="Github token. Can help in case of rate limits.", +) +def extract(release, github_token): + r = requests.get( + "https://api.github.com/repos/qgis/QGIS/git/refs/tags", + headers={"Authorization": github_token}, + ) + r.raise_for_status() + tags = json.loads(r.text) + releases = dict() + current_ltr = None + current_release = None + for tag in tags: + ref = tag["ref"] + tag_name = ref.split("/")[-1] + if tag_name.startswith("final-"): + version_parts = re.split(r"[\-_]", tag_name)[1:] + if int(version_parts[0]) >= 3: + releases[version_parts[0] + "." + version_parts[1]] = ".".join( + version_parts + ) + current_release = version_parts[0] + "." + version_parts[1] + if tag_name.startswith("ltr-"): + version_parts = re.split(r"[\-_]", tag_name)[1:] + version = ".".join(version_parts) + if version != current_release: + current_ltr = version + + info = { + "ltr": { + "short_version": current_ltr, + "patch_version": releases[current_ltr], + "tag_name": f'final-{releases[current_ltr].replace(".", "_")}', + }, + "stable": { + "short_version": current_release, + "patch_version": releases[current_release], + "tag_name": f'final-{releases[current_release].replace(".", "_")}', + }, + } + + print(f"QGIS_VERSION_STABLE_PATCH={info['stable']['patch_version']}") + print(f"QGIS_VERSION_LTR_PATCH={info['ltr']['patch_version']}") + + print(f"QGIS_VERSION_SHORT={info[release]['short_version']}") + print(f"QGIS_VERSION_PATCH={info[release]['patch_version']}") + print(f"QGIS_VERSION_TAG={info[release]['tag_name']}") + + +if __name__ == "__main__": + extract()