Skip to content

Commit

Permalink
refactor python scripts to reuse from ci-release-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsergio committed Nov 28, 2024
1 parent 2c3feea commit 7cf4d22
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
# SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only

Expand All @@ -16,6 +16,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: true

- name: Update
run: ./update_all.py
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "ci-release-tools"]
path = ci-release-tools
[submodule "ci_release_tools"]
path = ci_release_tools
url = [email protected]:KDABLabs/ci-release-tools.git
33 changes: 6 additions & 27 deletions utils.py → brew_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT

import os
import sys, os

from ci_release_tools.src.utils import *
from ci_release_tools.src.gh_utils import *
from brew_utils import *

formulas = {
'kddockwidgets-qt5.rb': {"repo": "KDAB/KDDockWidgets"},
Expand Down Expand Up @@ -35,23 +39,6 @@ def unique_repos():

return unique_repo_list

def exit_because(reason):
print(reason)
exit(1)

def run_command(command, fatal = True):
if os.system(command) == 0:
return True;

if fatal:
exit_because(f"Failed to run command: {command}")

return False

def run_command_with_output(command):
output = os.popen(command).read()
return output

# Gets the package version from an .rb file
def get_version_in_brew(filename):
lines = run_command_with_output(f"brew info --formula {filename}").split('\n')
Expand All @@ -60,14 +47,6 @@ def get_version_in_brew(filename):
first_line = lines[0]
return first_line.split(' ')[3].rstrip(',')

def get_latest_version_in_github(repo):
lines = run_command_with_output(f"gh release list --repo {repo} --limit 1").split('\n')
# example:
# TITLE TYPE TAG NAME PUBLISHED
# KDReports 2.3.0 Latest kdreports-2.3.0 about 2 months ago
version = lines[0].split('\t')[2]
return version

# removes v suffix and stuff like that
def clean_version(version):
version = version.replace('v', '')
Expand Down Expand Up @@ -96,7 +75,7 @@ def get_outdated_packages():
for filename in formulas:
current_version = get_version_in_brew(filename)
repo = formulas[filename]["repo"]
github_version = get_latest_version_in_github(repo)
github_version = get_latest_release_tag_in_github(repo)
github_version_numeric = clean_version(github_version)

# print(f"testing {repo} {current_version} {github_version_numeric}")
Expand Down
1 change: 0 additions & 1 deletion ci-release-tools
Submodule ci-release-tools deleted from 93c532
1 change: 1 addition & 0 deletions ci_release_tools
Submodule ci_release_tools added at e9a060
5 changes: 4 additions & 1 deletion update_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#
# Script called by CI to update any outdated package

from utils import *
import sys, os

from ci_release_tools.src.utils import *
from brew_utils import *

outdated_packages = get_outdated_packages()

Expand Down
2 changes: 1 addition & 1 deletion update_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import argparse, os
import hashlib
from utils import *
from ci_release_tools.src.utils import *

# Returns the sha256 of the .tar.gz file
def get_tarball_sha256(url):
Expand Down

0 comments on commit 7cf4d22

Please sign in to comment.