|
1 | 1 | # FileName: check-update.py
|
2 |
| -# SPDX-FileCopyrightText: (C) 2023 SeongTae Jeong <seongtaejg@gmail.com> |
| 2 | +# SPDX-FileCopyrightText: (C) 2024 SeongTae Jeong <seongtaejg@sqlitebrowser.org> |
3 | 3 | # SPDX-License-Identifier: BSD-2-Clause
|
4 | 4 |
|
5 | 5 | """
|
6 | 6 | This script checks whether the package version of the formulae we're defining
|
7 |
| -has been updated, and if so, notifies the maintainer by creating a Github Issue. |
| 7 | +has been updated, and if so, notifies the maintainer by creating a GitHub issue. |
8 | 8 | """
|
9 | 9 |
|
| 10 | +import json |
10 | 11 | import os
|
11 |
| -import re |
12 |
| -import requests |
13 | 12 | import subprocess
|
14 | 13 | from enum import Enum
|
15 | 14 |
|
@@ -79,73 +78,31 @@ def check_if_issue_exists():
|
79 | 78 | )
|
80 | 79 |
|
81 | 80 |
|
82 |
| -def get_version_from_formula(formula_name): |
83 |
| - filepath = os.path.join(os.getcwd(), "Formula", formula_name + ".rb") |
84 |
| - with open(filepath, "r") as formula: |
85 |
| - formula_content = formula.read() |
86 |
| - version = re.search(r'version "(.*?)"', formula_content).group(1) |
| 81 | +def return_package_name_from_formula(formula): |
| 82 | + if formula == "sqlb-openssl@3": |
| 83 | + return Package.OPENSSL |
| 84 | + elif formula == "sqlb-qt@5": |
| 85 | + return Package.QT |
| 86 | + elif formula == "sqlb-sqlcipher": |
| 87 | + return Package.SQLCIPHER |
| 88 | + elif formula == "sqlb-sqlite": |
| 89 | + return Package.SQLITE |
87 | 90 |
|
88 |
| - return version |
89 | 91 |
|
90 |
| - |
91 |
| -def check_sqlcipher_version(): |
92 |
| - current_version = get_version_from_formula("sqlb-sqlcipher") |
93 |
| - |
94 |
| - release_list = subprocess.check_output( |
95 |
| - "gh release list --repo sqlcipher/sqlcipher --limit 1", shell=True, text=True |
96 |
| - ) |
97 |
| - latest_version = release_list.split()[0][1:] |
98 |
| - |
99 |
| - if current_version != latest_version: |
100 |
| - return (Package.SQLCIPHER, current_version, latest_version) |
101 |
| - |
102 |
| - |
103 |
| -def check_sqlite_version(): |
104 |
| - current_version = get_version_from_formula("sqlb-sqlite") |
105 |
| - |
106 |
| - response = requests.get("https://sqlite.org/index.html") |
107 |
| - latest_version = ( |
108 |
| - re.search(r"href=.*?releaselog/v?(\d+(?:[._]\d+)+)\.html", response.text) |
109 |
| - .group(1) |
110 |
| - .replace("_", ".") |
111 |
| - ) |
112 |
| - |
113 |
| - if current_version != latest_version: |
114 |
| - return (Package.SQLITE, current_version, latest_version) |
115 |
| - |
116 |
| - |
117 |
| -def check_openssl_version(): |
118 |
| - current_version = get_version_from_formula("sqlb-openssl@3") |
119 |
| - |
120 |
| - response = requests.get("https://www.openssl.org/source/") |
121 |
| - latest_version = re.findall( |
122 |
| - r"href=.*?openssl[._-]v?(\d+(?:\.\d+)+)\.t", response.text |
123 |
| - )[-1] |
124 |
| - |
125 |
| - if current_version != latest_version: |
126 |
| - return (Package.OPENSSL, current_version, latest_version) |
127 |
| - |
128 |
| - |
129 |
| -def check_qt_version(): |
130 |
| - current_version = get_version_from_formula("sqlb-qt@5") |
131 |
| - |
132 |
| - response = requests.get( |
133 |
| - "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/q/qt%405.rb" |
| 92 | +if __name__ == "__main__": |
| 93 | + data = json.loads( |
| 94 | + subprocess.run( |
| 95 | + "brew livecheck sqlb-openssl sqlb-qt sqlb-sqlcipher sqlb-sqlite --json", |
| 96 | + shell=True, |
| 97 | + capture_output=True, |
| 98 | + text=True, |
| 99 | + ).stdout.strip() |
134 | 100 | )
|
135 |
| - latest_version = re.search(r'url "(.*?)"', response.text).group(1).split("/")[-3] |
136 |
| - |
137 |
| - if current_version != latest_version: |
138 |
| - return (Package.QT, current_version, latest_version) |
139 |
| - |
| 101 | + for formula in data: |
| 102 | + if formula["version"]["current"] != formula["version"]["latest"]: |
| 103 | + generate_issue( |
| 104 | + return_package_name_from_formula(formula["formula"]), |
| 105 | + formula["version"]["current"], |
| 106 | + formula["version"]["latest"], |
| 107 | + ) |
140 | 108 |
|
141 |
| -if __name__ == "__main__": |
142 |
| - functions = [ |
143 |
| - check_sqlite_version, |
144 |
| - check_sqlcipher_version, |
145 |
| - check_openssl_version, |
146 |
| - check_qt_version, |
147 |
| - ] |
148 |
| - for function in functions: |
149 |
| - response = function() |
150 |
| - if response is not None: |
151 |
| - generate_issue(response[0], response[1], response[2]) |
0 commit comments