From d78d36e5016efa46e21302d4c5670488204ca457 Mon Sep 17 00:00:00 2001 From: Adam Fidel Date: Fri, 6 Dec 2024 18:58:22 -0600 Subject: [PATCH 1/8] feat: add renovate tests and fwupd rule --- .github/renovate.json5 | 11 +++++ staging/fwupd/fwupd.spec | 1 + test/renovate/justfile | 18 ++++++++ test/renovate/test_renovate.py | 84 ++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 test/renovate/justfile create mode 100755 test/renovate/test_renovate.py diff --git a/.github/renovate.json5 b/.github/renovate.json5 index aebc0cd..8aa3f41 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -19,6 +19,17 @@ "extractVersionTemplate": "^(?\\d\\.\\d)", "versioningTemplate": "loose", "registryUrlTemplate": "https://yum2npm.io/repos/{{replace '/' '/modules/' registryUrl}}/packages" + }, + { + "customType": "regex", + "fileMatch": [".*\\.spec"], + "matchStrings": [ + "# renovate: datasource=yum repo=(?[^\\s]+) pkg=(?[^\\s]+)\\s*[^\\s]+\\s+(?[^\\s]+)" + ], + "datasourceTemplate": "npm", + "extractVersionTemplate": "^(?\\d\\.\\d+\\.\\d+)", + "versioningTemplate": "loose", + "registryUrlTemplate": "https://yum2npm.io/repos/{{replace '/' '/modules/' registryUrl}}/packages" } ] diff --git a/staging/fwupd/fwupd.spec b/staging/fwupd/fwupd.spec index c4f65cc..c4ef849 100644 --- a/staging/fwupd/fwupd.spec +++ b/staging/fwupd/fwupd.spec @@ -52,6 +52,7 @@ Summary: Firmware update daemon Name: fwupd +# renovate: datasource=yum repo=fedora-41-x86_64 pkg=fwupd Version: 1.9.26 Release: 100.ublue License: LGPL-2.1-or-later diff --git a/test/renovate/justfile b/test/renovate/justfile new file mode 100644 index 0000000..01d2096 --- /dev/null +++ b/test/renovate/justfile @@ -0,0 +1,18 @@ +test-local: + #!/bin/bash + set -eo pipefail + + if [[ -z "$GITHUB_TOKEN" ]]; then + echo 'Must set $GITHUB_TOKEN environment variable' + exit 1 + fi + + tmpdir=$(mktemp -d) + chmod og+rx $tmpdir + echo "Working in $tmpdir" + cp -r ../../* ../../.* $tmpdir + podman run -it --rm -v ${tmpdir}:/usr/src/app --security-opt label=disable -u root \ + -e RENOVATE_TOKEN=$GITHUB_TOKEN \ + -e GITHUB_TOKEN=$GITHUB_TOKEN \ + renovate/renovate:39 /usr/bin/python3 /usr/src/app/test/renovate/test_renovate.py + rm -rf $tmpdir diff --git a/test/renovate/test_renovate.py b/test/renovate/test_renovate.py new file mode 100755 index 0000000..475fb72 --- /dev/null +++ b/test/renovate/test_renovate.py @@ -0,0 +1,84 @@ +#!/usr/bin/python3 + +import os +import re +import sys +import subprocess +from pathlib import Path +import json + +TEST_CASES = { + "kf6-kio": { + "path": "staging/kf6-kio/kf6-kio.spec", + "match": r"%global majmin_ver_kf6 6\.\d+", + "replace": "%global majmin_ver_kf6 6.7" + }, + "fwupd": { + "path": "staging/fwupd/fwupd.spec", + "match": r"Version: 1.\d+\.\d+", + "replace": r"Version: 1.8.0", + } +} + +OUTPUT_LOG = "renovate-log.ndjson" + +def validate_output(payload): + packages_with_updates = set() + for deps in payload: + for dep in deps["deps"]: + dep_name = dep["depName"] + if len(dep["updates"]) > 0: + packages_with_updates.add(dep_name) + + print("Packages with updates:") + print(packages_with_updates) + + all_packages_found = True + for package in TEST_CASES.keys(): + if not package in packages_with_updates: + print(f"ERROR: did not find update for package {package}") + all_packages_found = False + + return all_packages_found + + +def main(): + os.environ["LOG_LEVEL"] = "debug" + os.environ["RENOVATE_PLATFORM"] = "local" + os.environ["RENOVATE_CONFIG_FILE"] = str(Path(".github/renovate.json5").resolve()) + os.environ["RENOVATE_LOG_FILE"] = OUTPUT_LOG + + for test_name, test_case in TEST_CASES.items(): + with open(test_case["path"], 'r+') as file: + content = file.read() + new_content = re.sub(test_case["match"], test_case["replace"], content) + + if content == new_content: + print(f"WARNING: did not replace version in {test_name}") + file.seek(0) + file.write(new_content) + file.truncate() + + subprocess.run("renovate", shell=True) + + found_payload = False + validated = False + with open(OUTPUT_LOG, 'r') as file: + for line in file.readlines(): + parsed_line = json.loads(line) + if "config" in parsed_line and "regex" in parsed_line["config"]: + found_payload = True + validated = validate_output(parsed_line["config"]["regex"]) + + if not found_payload: + print(f"WARNING: did not find output from renovate") + + if validated: + print("passed") + sys.exit(0) + else: + print("failed") + sys.exit(1) + +if __name__ == "__main__": + main() From 734a26e48532604ace5efb5a0c0ff929d857dc88 Mon Sep 17 00:00:00 2001 From: Adam Fidel Date: Fri, 6 Dec 2024 20:08:26 -0600 Subject: [PATCH 2/8] Remove shell=True --- test/renovate/test_renovate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/renovate/test_renovate.py b/test/renovate/test_renovate.py index 475fb72..979bd5d 100755 --- a/test/renovate/test_renovate.py +++ b/test/renovate/test_renovate.py @@ -59,7 +59,7 @@ def main(): file.write(new_content) file.truncate() - subprocess.run("renovate", shell=True) + subprocess.run("renovate") found_payload = False validated = False From 481cf2b03deab9411430bf8be5d4d6390cb0b11a Mon Sep 17 00:00:00 2001 From: Adam Fidel Date: Fri, 6 Dec 2024 20:18:39 -0600 Subject: [PATCH 3/8] Prefered way to use subprocess --- test/renovate/test_renovate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/renovate/test_renovate.py b/test/renovate/test_renovate.py index 979bd5d..8b39f6b 100755 --- a/test/renovate/test_renovate.py +++ b/test/renovate/test_renovate.py @@ -59,7 +59,7 @@ def main(): file.write(new_content) file.truncate() - subprocess.run("renovate") + subprocess.call(["/usr/local/sbin/renovate"]) found_payload = False validated = False From 503843057e9e47a9a81de40dec5267b4b0b52603 Mon Sep 17 00:00:00 2001 From: Adam Fidel Date: Fri, 6 Dec 2024 22:57:11 -0600 Subject: [PATCH 4/8] Add shell=False --- test/renovate/test_renovate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/renovate/test_renovate.py b/test/renovate/test_renovate.py index 8b39f6b..92a6763 100755 --- a/test/renovate/test_renovate.py +++ b/test/renovate/test_renovate.py @@ -59,7 +59,7 @@ def main(): file.write(new_content) file.truncate() - subprocess.call(["/usr/local/sbin/renovate"]) + subprocess.call(["/usr/local/sbin/renovate"], shell=False) found_payload = False validated = False From 55b5a9abd07b4ff1faab2acf29a2fd085d27137b Mon Sep 17 00:00:00 2001 From: Adam Fidel Date: Sat, 7 Dec 2024 10:29:38 -0600 Subject: [PATCH 5/8] Move test directory --- {test => .github/test}/renovate/justfile | 3 +-- {test => .github/test}/renovate/test_renovate.py | 0 2 files changed, 1 insertion(+), 2 deletions(-) rename {test => .github/test}/renovate/justfile (85%) rename {test => .github/test}/renovate/test_renovate.py (100%) diff --git a/test/renovate/justfile b/.github/test/renovate/justfile similarity index 85% rename from test/renovate/justfile rename to .github/test/renovate/justfile index 01d2096..c178d25 100644 --- a/test/renovate/justfile +++ b/.github/test/renovate/justfile @@ -3,8 +3,7 @@ test-local: set -eo pipefail if [[ -z "$GITHUB_TOKEN" ]]; then - echo 'Must set $GITHUB_TOKEN environment variable' - exit 1 + echo '$GITHUB_TOKEN environment variable not set -- some tests may fail' fi tmpdir=$(mktemp -d) diff --git a/test/renovate/test_renovate.py b/.github/test/renovate/test_renovate.py similarity index 100% rename from test/renovate/test_renovate.py rename to .github/test/renovate/test_renovate.py From e0cbd6bfd3301b163b20b9261fc8d9661a031771 Mon Sep 17 00:00:00 2001 From: Adam Fidel Date: Sat, 7 Dec 2024 12:41:12 -0600 Subject: [PATCH 6/8] Maybe check_call will fix Codacy issue? --- .github/test/renovate/justfile | 4 ++-- .github/test/renovate/test_renovate.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/test/renovate/justfile b/.github/test/renovate/justfile index c178d25..299ae67 100644 --- a/.github/test/renovate/justfile +++ b/.github/test/renovate/justfile @@ -9,9 +9,9 @@ test-local: tmpdir=$(mktemp -d) chmod og+rx $tmpdir echo "Working in $tmpdir" - cp -r ../../* ../../.* $tmpdir + cp -r ../../../* ../../../.* $tmpdir podman run -it --rm -v ${tmpdir}:/usr/src/app --security-opt label=disable -u root \ -e RENOVATE_TOKEN=$GITHUB_TOKEN \ -e GITHUB_TOKEN=$GITHUB_TOKEN \ - renovate/renovate:39 /usr/bin/python3 /usr/src/app/test/renovate/test_renovate.py + renovate/renovate:39 /usr/bin/python3 /usr/src/app/.github/test/renovate/test_renovate.py rm -rf $tmpdir diff --git a/.github/test/renovate/test_renovate.py b/.github/test/renovate/test_renovate.py index 92a6763..f2e76a1 100755 --- a/.github/test/renovate/test_renovate.py +++ b/.github/test/renovate/test_renovate.py @@ -59,7 +59,7 @@ def main(): file.write(new_content) file.truncate() - subprocess.call(["/usr/local/sbin/renovate"], shell=False) + subprocess.check_call(["/usr/local/sbin/renovate"], shell=False) found_payload = False validated = False From 6e7df67f9d39dd18add24347d47617ab73dede50 Mon Sep 17 00:00:00 2001 From: Adam Fidel Date: Sat, 7 Dec 2024 13:15:19 -0600 Subject: [PATCH 7/8] Add rule for topgrade --- .github/test/renovate/justfile | 8 ++++---- .github/test/renovate/test_renovate.py | 17 ++++++++++++++--- staging/topgrade/topgrade.spec | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/test/renovate/justfile b/.github/test/renovate/justfile index 299ae67..0c4f2dd 100644 --- a/.github/test/renovate/justfile +++ b/.github/test/renovate/justfile @@ -2,8 +2,8 @@ test-local: #!/bin/bash set -eo pipefail - if [[ -z "$GITHUB_TOKEN" ]]; then - echo '$GITHUB_TOKEN environment variable not set -- some tests may fail' + if [[ -z "$GITHUB_COM_TOKEN" ]]; then + echo '$GITHUB_COM_TOKEN environment variable not set -- some tests may fail' fi tmpdir=$(mktemp -d) @@ -11,7 +11,7 @@ test-local: echo "Working in $tmpdir" cp -r ../../../* ../../../.* $tmpdir podman run -it --rm -v ${tmpdir}:/usr/src/app --security-opt label=disable -u root \ - -e RENOVATE_TOKEN=$GITHUB_TOKEN \ - -e GITHUB_TOKEN=$GITHUB_TOKEN \ + -e RENOVATE_TOKEN=$GITHUB_COM_TOKEN \ + -e GITHUB_COM_TOKEN=$GITHUB_COM_TOKEN \ renovate/renovate:39 /usr/bin/python3 /usr/src/app/.github/test/renovate/test_renovate.py rm -rf $tmpdir diff --git a/.github/test/renovate/test_renovate.py b/.github/test/renovate/test_renovate.py index f2e76a1..f4ec5ad 100755 --- a/.github/test/renovate/test_renovate.py +++ b/.github/test/renovate/test_renovate.py @@ -8,6 +8,16 @@ import json TEST_CASES = { + "loft-sh/devpod": { + "path": "staging/devpod/devpod.spec", + "match": r"Version: v0.\d+\.\d+", + "replace": r"Version: v0.6.0", + }, + "topgrade-rs/topgrade": { + "path": "staging/topgrade/topgrade.spec", + "match": r"Version: \d+\.\d+\.\d+", + "replace": "Version: 14.0.0", + }, "kf6-kio": { "path": "staging/kf6-kio/kf6-kio.spec", "match": r"%global majmin_ver_kf6 6\.\d+", @@ -20,7 +30,6 @@ } } -OUTPUT_LOG = "renovate-log.ndjson" def validate_output(payload): packages_with_updates = set() @@ -43,10 +52,12 @@ def validate_output(payload): def main(): + log_filename = "renovate-log.ndjson" + os.environ["LOG_LEVEL"] = "debug" os.environ["RENOVATE_PLATFORM"] = "local" os.environ["RENOVATE_CONFIG_FILE"] = str(Path(".github/renovate.json5").resolve()) - os.environ["RENOVATE_LOG_FILE"] = OUTPUT_LOG + os.environ["RENOVATE_LOG_FILE"] = log_filename for test_name, test_case in TEST_CASES.items(): with open(test_case["path"], 'r+') as file: @@ -63,7 +74,7 @@ def main(): found_payload = False validated = False - with open(OUTPUT_LOG, 'r') as file: + with open(log_filename, 'r') as file: for line in file.readlines(): parsed_line = json.loads(line) if "config" in parsed_line and "regex" in parsed_line["config"]: diff --git a/staging/topgrade/topgrade.spec b/staging/topgrade/topgrade.spec index a1832ad..a15b73f 100644 --- a/staging/topgrade/topgrade.spec +++ b/staging/topgrade/topgrade.spec @@ -1,6 +1,7 @@ %global debug_package %{nil} Name: topgrade +# renovate: datasource=github-releases depName=topgrade-rs/topgrade Version: 15.0.0 Release: 1%{?dist} Summary: Upgrade all the things From 2440b8069d6f5c3975503449aef366b5893d0d91 Mon Sep 17 00:00:00 2001 From: Adam Fidel Date: Sat, 7 Dec 2024 20:27:39 -0600 Subject: [PATCH 8/8] Add renovate rule for sched-ext/scx --- .github/test/renovate/test_renovate.py | 5 +++++ staging/scx-scheds/scx-scheds.spec | 1 + 2 files changed, 6 insertions(+) diff --git a/.github/test/renovate/test_renovate.py b/.github/test/renovate/test_renovate.py index f4ec5ad..efe2990 100755 --- a/.github/test/renovate/test_renovate.py +++ b/.github/test/renovate/test_renovate.py @@ -27,6 +27,11 @@ "path": "staging/fwupd/fwupd.spec", "match": r"Version: 1.\d+\.\d+", "replace": r"Version: 1.8.0", + }, + "sched-ext/scx": { + "path": "staging/scx-scheds/scx-scheds.spec", + "match": r"Version: 1\.\d+\.\d+", + "replace": r"Version: 1.0.4", } } diff --git a/staging/scx-scheds/scx-scheds.spec b/staging/scx-scheds/scx-scheds.spec index 3b39b6b..a22e88d 100644 --- a/staging/scx-scheds/scx-scheds.spec +++ b/staging/scx-scheds/scx-scheds.spec @@ -1,4 +1,5 @@ Name: scx-scheds +# renovate: datasource=github-releases depName=sched-ext/scx Version: 1.0.5 Release: 1%{?dist} Summary: Sched_ext Schedulers and Tools