Skip to content

Commit

Permalink
Merge pull request #25 from KDAB/work/sergio
Browse files Browse the repository at this point in the history
Make CI refresh packages via nightly workflow
  • Loading branch information
iamsergio authored Nov 18, 2024
2 parents fc29d31 + 24501d8 commit f39863c
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 72 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only

name: nightly update

on:
schedule:
- cron: "0 3 * * *"
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Update
run: ./update_all.py
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ See outdated versions with:
Update a version with:

```bash
./update.py kdreports-qt6.rb 2.3.0
./update_one.py kdreports-qt6.rb 2.3.0
```

Or to open a PR automatically:

```bash
./update.py kdreports-qt6.rb 2.3.0 --pr KDAB/homebrew-tap
./update_one.py kdreports-qt6.rb 2.3.0 --pr KDAB/homebrew-tap
```

## Documentation
Expand Down
76 changes: 8 additions & 68 deletions info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,11 @@
# SPDX-License-Identifier: MIT

# prints packages that have an outdated version in brew than in github
# they are candidates for update.py
# they are candidates for update_all.py
#

from utils import *

formulas = {
'kddockwidgets-qt5.rb': {"repo": "KDAB/KDDockWidgets"},
'kddockwidgets-qt6.rb': {"repo": "KDAB/KDDockWidgets"},
'kdsingleapplication-qt5.rb': {"repo": "KDAB/KDSingleApplication"},
'kdsingleapplication-qt6.rb': {"repo": "KDAB/KDSingleApplication"},
'kdsoap-qt5.rb': {"repo": "KDAB/KDSoap"},
'kdsoap-qt6.rb': {"repo": "KDAB/KDSoap"},
'kdchart-qt5.rb': {"repo": "KDAB/KDChart"},
'kdchart-qt6.rb': {"repo": "KDAB/KDChart"},
'kdreports-qt5.rb': {"repo": "KDAB/KDReports"},
'kdreports-qt6.rb': {"repo": "KDAB/KDReports"},
'gammaray-qt5.rb': {"repo": "KDAB/Gammaray"},
'kdmactouchbar-qt5.rb': {"repo": "KDAB/KDMacTouchBar"},
# 'kdstatemachineeditor-qt5.rb': {"repo": "KDAB/KDStateMachineEditor"},
# 'kdstatemachineeditor-qt6.rb': {"repo": "KDAB/KDStateMachineEditor"},
}

def unique_repos():
seen_repos = set()
unique_repo_list = []

for filename in formulas:
repo = formulas[filename]["repo"]
if repo not in seen_repos:
unique_repo_list.append(repo)
seen_repos.add(repo)

return unique_repo_list

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')

# example: ==> kdstatemachineeditor-qt6: stable 2.0.0-beta2, HEAD
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', '')
version = version.split('-')[-1]
return version

def print_current_brew_versions():
print("\nCurrent Homebrew versions:")
for filename in formulas:
Expand All @@ -77,20 +22,15 @@ def print_latest_github_versions():
print(f"{repo}: {version}")

def print_outdated_packages():
print("\nOutdated packages:")
has_outdated = False

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_numeric = clean_version(github_version)
outdated_packages = get_outdated_packages()
has_outdated = outdated_packages != []

if current_version != github_version_numeric:
has_outdated = True
filename = filename.ljust(30)
if has_outdated:
print("\nOutdated packages:")

print(f"{filename}: {current_version} => {github_version}")
for outdated in outdated_packages:
filename = outdated[0].ljust(30)
print(f"{filename}: {outdated[1]} => {outdated[2]}")

if not has_outdated:
print("No outdated packages found")
Expand Down
16 changes: 16 additions & 0 deletions update_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
#
# Script called by CI to update any outdated package

from utils import *

outdated_packages = get_outdated_packages()

for package in outdated_packages:
filename = package[0]
new_tag = package[2]
if not run_command(f"./update_one.py {filename} {new_tag} --pr KDAB/homebrew-tap"):
exit_because("Failed to run update_one.py")

exit(0)
11 changes: 9 additions & 2 deletions update.py → update_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ def get_new_url(old_url, new_tag):
elif '/releases/download/' in old_url:
# Example: https://github.com/KDAB/KDSingleApplication/releases/download/v1.1.0/kdsingleapplication-1.1.0.tar.gz
pkg_name = old_url.split('/')[-1].split('-')[0]
pkg_version = new_tag.lstrip('v')
return old_url.rsplit('/', 2)[0] + '/' + pkg_name + '-' + new_tag + '/' + pkg_name + '-' + pkg_version + '.tar.gz'

if pkg_name in new_tag:
# KDSoap/KDReports have tags like kdreports-2.2.0, here we don't prefix package name
tar_filename = new_tag + '.tar.gz'
else:
pkg_version = new_tag.lstrip('v')
tar_filename = pkg_name + '-' + pkg_version + '.tar.gz'

return old_url.rsplit('/', 2)[0] + '/' + new_tag + '/' + tar_filename

# updates the url and sha1 and returns whether the file was edited or not
def update(filename, new_tag) -> bool:
Expand Down
72 changes: 72 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@

import os

formulas = {
'kddockwidgets-qt5.rb': {"repo": "KDAB/KDDockWidgets"},
'kddockwidgets-qt6.rb': {"repo": "KDAB/KDDockWidgets"},
'kdsingleapplication-qt5.rb': {"repo": "KDAB/KDSingleApplication"},
'kdsingleapplication-qt6.rb': {"repo": "KDAB/KDSingleApplication"},
'kdsoap-qt5.rb': {"repo": "KDAB/KDSoap"},
'kdsoap-qt6.rb': {"repo": "KDAB/KDSoap"},
'kdchart-qt5.rb': {"repo": "KDAB/KDChart"},
'kdchart-qt6.rb': {"repo": "KDAB/KDChart"},
'kdreports-qt5.rb': {"repo": "KDAB/KDReports"},
'kdreports-qt6.rb': {"repo": "KDAB/KDReports"},
'gammaray-qt5.rb': {"repo": "KDAB/Gammaray"},
'kdmactouchbar-qt5.rb': {"repo": "KDAB/KDMacTouchBar"},
# 'kdstatemachineeditor-qt5.rb': {"repo": "KDAB/KDStateMachineEditor"},
# 'kdstatemachineeditor-qt6.rb': {"repo": "KDAB/KDStateMachineEditor"},
}

def unique_repos():
seen_repos = set()
unique_repo_list = []

for filename in formulas:
repo = formulas[filename]["repo"]
if repo not in seen_repos:
unique_repo_list.append(repo)
seen_repos.add(repo)

return unique_repo_list

def exit_because(reason):
print(reason)
exit(1)
Expand All @@ -16,6 +45,32 @@ def run_command(command, fatal = True):

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')

# example: ==> kdstatemachineeditor-qt6: stable 2.0.0-beta2, HEAD
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', '')
version = version.split('-')[-1]
return version

# Returns the url of the tar.gz
def get_url(filename) -> str:
try:
Expand All @@ -29,3 +84,20 @@ def get_url(filename) -> str:

exit_because("Could not find url in file")
return ""

# returns the packages that need upgrading
# the result is a list of tuples, for example:
# [('kdmactouchbar-qt5.rb', 'v1.0.0', 'v1.1.3')]
def get_outdated_packages():
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_numeric = clean_version(github_version)

# print(f"testing {repo} {current_version} {github_version_numeric}")
if current_version != github_version_numeric:
packages.append((filename, current_version, github_version))

return packages

0 comments on commit f39863c

Please sign in to comment.