Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix get latest grafana versions python script #354

Merged
merged 8 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/354-fix-find-grafana-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
trivial:
- fix find grafana versions python script comparation
6 changes: 3 additions & 3 deletions hacking/check_fragment.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#!/usr/bin/env bash

function fail() {
cat << EOF
cat <<EOF
Dear contributor,
Thank you for you Pull Request !
Expand All @@ -10,7 +10,7 @@ function fail() {
It will help your change be released faster !
Thank you !
EOF
exit 1
exit 1
}

FRAGMENTS=$(git fetch && git diff --name-only --diff-filter=ACMRT origin/main..HEAD | grep "changelogs")
Expand Down
29 changes: 14 additions & 15 deletions hacking/find_grafana_versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python

import json
import requests
Expand All @@ -7,32 +7,31 @@
def get_by_major(version):
if version.startswith("v"):
version = version[1:]
return (version[0], version, int(version.replace(".", "")))
return int(version.split(".")[0]), version, tuple(map(int, version.split(".")))


def get_grafana_releases():
r = requests.get(
"https://api.github.com/repos/grafana/grafana/releases?per_page=50",
"https://api.github.com/repos/grafana/grafana/releases?per_page=100",
headers={"Accept": "application/vnd.github.v3+json"},
)
if r.status_code != 200:
raise Exception("Failed to get releases from GitHub")
return r.json()


by_major = {}

if __name__ == "__main__":
releases = get_grafana_releases()
for item in releases:
if item.get("prerelease"):
by_major = {}

for release in releases:
if release.get("prerelease"):
continue
major, version, as_int = get_by_major(item.get("tag_name"))
if major not in by_major.keys() or by_major[major]["as_int"] < as_int:
by_major[major] = {"version": version, "as_int": as_int}
latest_3_majors = sorted(list(by_major.keys()), reverse=True)[:3]

latest_releases = []
for idx in latest_3_majors:
latest_releases.append(by_major[idx]["version"])
major, version, as_tuple = get_by_major(release.get("tag_name"))
if major not in by_major.keys() or by_major[major]["as_tuple"] < as_tuple:
by_major[major] = {"version": version, "as_tuple": as_tuple}

latest_3_majors = sorted(list(by_major.keys()))[:3]
latest_releases = [by_major[idx]["version"] for idx in latest_3_majors]

print(json.dumps(latest_releases))
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def run_command_ls():
def run_command_install_zip():
STDERR = ""
STDOUT = """
installing alexanderzobnin-grafana-zabbix @
installing alexanderzobnin-grafana-zabbix @
from: /home/grafana//alexanderzobnin-grafana-zabbix-v3.10.5-1-g2219691.zip
into: /var/lib/grafana/plugins

Expand Down
Loading