Skip to content

Commit 5d8893f

Browse files
committed
Initial commit
0 parents  commit 5d8893f

13 files changed

+848
-0
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
- package-ecosystem: "pip"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"

.github/scripts/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This script checks whether the package version of the formulae we're defining <br>
2+
has been updated, and if so, notifies the maintainer by creating a Github Issue.

.github/scripts/check-update.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# FileName: check-update.py
2+
# SPDX-FileCopyrightText: (C) 2023 SeongTae Jeong <[email protected]>
3+
# SPDX-License-Identifier: BSD-2-Clause
4+
5+
"""
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.
8+
"""
9+
10+
import os
11+
import re
12+
import requests
13+
import subprocess
14+
from enum import Enum
15+
16+
17+
class IssueVersionStatus(Enum):
18+
NONE = 0
19+
EXISTS = 1
20+
EXISTS_BUT_OUTDATED = 2
21+
22+
23+
class Package(Enum):
24+
OPENSSL = "OpenSSL"
25+
QT = "Qt"
26+
SQLCIPHER = "SQLCipher"
27+
SQLITE = "SQLite"
28+
29+
30+
def generate_issue(package_name, current_version, latest_version):
31+
def check_if_issue_exists():
32+
issue = subprocess.check_output(
33+
'gh issue list --label "{}" --limit 1 --state "open" --repo "{}"'.format(
34+
package_name.value, os.environ["GITHUB_REPOSITORY"]
35+
),
36+
shell=True,
37+
text=True,
38+
)
39+
40+
if len(issue) == 0:
41+
return (IssueVersionStatus.NONE, None)
42+
43+
issue_number = issue.split("\t")[0]
44+
version_from_issue = "".join(issue.split("\t")[2].split()[-1:])
45+
if latest_version == version_from_issue:
46+
return (IssueVersionStatus.EXISTS, issue_number)
47+
else:
48+
return (IssueVersionStatus.EXISTS_BUT_OUTDATED, issue_number)
49+
50+
issue_info = check_if_issue_exists()
51+
# Abort function execution because there is already an issue
52+
if issue_info[0] == IssueVersionStatus.EXISTS:
53+
return
54+
# If already have an issue, but the version reported in that issue is already out of date
55+
elif issue_info[0] == IssueVersionStatus.EXISTS_BUT_OUTDATED:
56+
os.system(
57+
'gh issue close {} --repo "{}"'.format(
58+
issue_info[1], os.environ["GITHUB_REPOSITORY"]
59+
)
60+
)
61+
os.system(
62+
"""
63+
gh issue create \
64+
--assignee "{}" \
65+
--body "{} has been updated from {} to {}." \
66+
--label "{}" \
67+
--title "{} has been updated to {}" \
68+
--repo "{}"
69+
""".format(
70+
os.environ["ASSIGNEES"],
71+
package_name.value,
72+
current_version,
73+
latest_version,
74+
package_name.value,
75+
package_name.value,
76+
latest_version,
77+
os.environ["GITHUB_REPOSITORY"],
78+
)
79+
)
80+
81+
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)
87+
88+
return version
89+
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"
134+
)
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+
140+
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])

.github/scripts/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
certifi==2024.6.2
2+
charset-normalizer==3.3.2
3+
idna==3.7
4+
requests==2.32.3
5+
urllib3==2.2.1
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Check for packages updates
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 0' # Every Sunday at 00:00 UTC
6+
workflow_dispatch:
7+
8+
jobs:
9+
check:
10+
name: Check for packages updates
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
cache: 'pip'
19+
python-version: '3.11.5'
20+
21+
- name: Install dependencies
22+
run: pip install -r ./.github/scripts/requirements.txt
23+
24+
- name: Run the script
25+
env:
26+
ASSIGNEES: ${{ vars.ASSIGNEES }}
27+
GITHUB_REPO: ${{ github.repository }}
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: python3 ./.github/scripts/check-update.py

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
venv/

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @lucydodo

Formula/[email protected]

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# FIXME: This formula conflicts with the Homebrew official 'openssl@3' formula. (https://github.com/sqlitebrowser/homebrew-tap/issues/1)
2+
# Until fixed, you can install this formula before running 'brew unlink openssl@3'
3+
class SqlbOpensslAT3 < Formula
4+
desc "Cryptography and SSL/TLS Toolkit"
5+
homepage "https://openssl.org/"
6+
version "3.3.1"
7+
url "https://github.com/openssl/openssl/releases/download/openssl-#{version}/openssl-#{version}.tar.gz"
8+
mirror "https://www.openssl.org/source/openssl-#{version}.tar.gz"
9+
mirror "http://fresh-center.net/linux/misc/openssl-#{version}.tar.gz"
10+
sha256 "777cd596284c883375a2a7a11bf5d2786fc5413255efab20c50d6ffe6d020b7e"
11+
license "Apache-2.0"
12+
13+
bottle do
14+
root_url "https://nightlies.sqlitebrowser.org/homebrew_bottles"
15+
rebuild 1
16+
sha256 arm64_sonoma: "bcb2e8ee2006e8e107c2b25058b639f785e249a7096a9c4f527ad0bc798ec7dc"
17+
end
18+
19+
livecheck do
20+
url "https://www.openssl.org/source/"
21+
regex(/href=.*?openssl[._-]v?(\d+(?:\.\d+)+)\.t/i)
22+
end
23+
24+
depends_on arch: :arm64
25+
depends_on "ca-certificates"
26+
27+
link_overwrite "bin/c_rehash", "bin/openssl", "include/openssl/*"
28+
link_overwrite "lib/libcrypto*", "lib/libssl*"
29+
link_overwrite "lib/pkgconfig/libcrypto.pc", "lib/pkgconfig/libssl.pc", "lib/pkgconfig/openssl.pc"
30+
link_overwrite "share/doc/openssl/*", "share/man/man*/*ssl"
31+
32+
# SSLv2 died with 1.1.0, so no-ssl2 no longer required.
33+
# SSLv3 & zlib are off by default with 1.1.0 but this may not
34+
# be obvious to everyone, so explicitly state it for now to
35+
# help debug inevitable breakage.
36+
def configure_args
37+
args = %W[
38+
enable-ec_nistp_64_gcc_128
39+
no-asm
40+
no-ssl3
41+
no-ssl3-method
42+
no-zlib
43+
]
44+
end
45+
46+
def install
47+
# Determine the minimum macOS version.
48+
# Match the required version of the DB Browser for SQLite app.
49+
ENV["MACOSX_DEPLOYMENT_TARGET"] = "10.13"
50+
ENV.append "CPPFLAGS", "-mmacosx-version-min=10.13"
51+
ENV.append "LDFLAGS", "-mmacosx-version-min=10.13"
52+
53+
# This could interfere with how we expect OpenSSL to build.
54+
ENV.delete("OPENSSL_LOCAL_CONFIG_DIR")
55+
56+
# This ensures where Homebrew's Perl is needed the Cellar path isn't
57+
# hardcoded into OpenSSL's scripts, causing them to break every Perl update.
58+
# Whilst our env points to opt_bin, by default OpenSSL resolves the symlink.
59+
ENV["PERL"] = Formula["perl"].opt_bin/"perl" if which("perl") == Formula["perl"].opt_bin/"perl"
60+
61+
arch_args = []
62+
arch_args << "darwin64-x86_64-cc"
63+
arch_args += %W[--prefix=#{prefix}/darwin64-x86_64-cc]
64+
arch_args += %W[--openssldir=#{openssldir}/darwin64-x86_64-cc]
65+
arch_args << "--libdir=#{prefix}/darwin64-x86_64-cc/lib"
66+
ENV.append "CFLAGS", "-arch x86_64"
67+
68+
system "perl", "./Configure", *(configure_args + arch_args)
69+
system "arch -x86_64 make"
70+
system "make", "install", "MANDIR=#{prefix}/darwin64-x86_64-cc/share/man", "MANSUFFIX=ssl"
71+
# AF_ALG support isn't always enabled (e.g. some containers), which breaks the tests.
72+
# AF_ALG is a kernel feature and failures are unlikely to be issues with the formula.
73+
# system "CFLAGS=\"-arch x86_64\" arch -x86_64 make test TESTS=-test_afalg"
74+
75+
arch_args = []
76+
arch_args << "darwin64-arm64-cc"
77+
arch_args += %W[--prefix=#{prefix} --openssldir=#{openssldir} --libdir=lib]
78+
79+
openssldir.mkpath
80+
system "make clean"
81+
system "perl", "./Configure", *(configure_args + arch_args)
82+
system "make"
83+
system "make", "install", "MANDIR=#{man}", "MANSUFFIX=ssl"
84+
# # AF_ALG support isn't always enabled (e.g. some containers), which breaks the tests.
85+
# # AF_ALG is a kernel feature and failures are unlikely to be issues with the formula.
86+
# system "make", "test", "TESTS=-test_afalg"
87+
88+
system "lipo", "-create", "-output", "#{lib}/libcrypto.3.dylib", "#{lib}/libcrypto.3.dylib", "#{prefix}/darwin64-x86_64-cc/lib/libcrypto.3.dylib"
89+
system "lipo", "-create", "-output", "#{lib}/libcrypto.a", "#{lib}/libcrypto.a", "#{prefix}/darwin64-x86_64-cc/lib/libcrypto.a"
90+
rm "#{lib}/libcrypto.dylib"
91+
ln_s "#{lib}/libcrypto.3.dylib", "#{lib}/libcrypto.dylib"
92+
end
93+
94+
def openssldir
95+
etc/"sqlb-openssl@3"
96+
end
97+
98+
def post_install
99+
rm_f openssldir/"cert.pem"
100+
openssldir.install_symlink Formula["ca-certificates"].pkgetc/"cert.pem"
101+
end
102+
103+
def caveats
104+
<<~EOS
105+
A CA file has been bootstrapped using certificates from the system
106+
keychain. To add additional certificates, place .pem files in
107+
#{openssldir}/certs
108+
109+
and run
110+
#{opt_bin}/c_rehash
111+
EOS
112+
end
113+
114+
test do
115+
# Make sure the necessary .cnf file exists, otherwise OpenSSL gets moody.
116+
assert_predicate pkgetc/"openssl.cnf", :exist?,
117+
"OpenSSL requires the .cnf file for some functionality"
118+
119+
# Check OpenSSL itself functions as expected.
120+
(testpath/"testfile.txt").write("This is a test file")
121+
expected_checksum = "e2d0fe1585a63ec6009c8016ff8dda8b17719a637405a4e23c0ff81339148249"
122+
system bin/"openssl", "dgst", "-sha256", "-out", "checksum.txt", "testfile.txt"
123+
open("checksum.txt") do |f|
124+
checksum = f.read(100).split("=").last.strip
125+
assert_equal checksum, expected_checksum
126+
end
127+
end
128+
end

0 commit comments

Comments
 (0)