Skip to content

Commit

Permalink
feat: add renovate tests and more rules (#57)
Browse files Browse the repository at this point in the history
* feat: add renovate tests and fwupd rule

* Remove shell=True

* Prefered way to use subprocess

* Add shell=False

* Move test directory

* Maybe check_call will fix Codacy issue?

* Add rule for topgrade

* Add renovate rule for sched-ext/scx
  • Loading branch information
ledif authored Dec 8, 2024
1 parent bdfec2b commit aa88989
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
"extractVersionTemplate": "^(?<version>\\d\\.\\d)",
"versioningTemplate": "loose",
"registryUrlTemplate": "https://yum2npm.io/repos/{{replace '/' '/modules/' registryUrl}}/packages"
},
{
"customType": "regex",
"fileMatch": [".*\\.spec"],
"matchStrings": [
"# renovate: datasource=yum repo=(?<registryUrl>[^\\s]+) pkg=(?<depName>[^\\s]+)\\s*[^\\s]+\\s+(?<currentValue>[^\\s]+)"
],
"datasourceTemplate": "npm",
"extractVersionTemplate": "^(?<version>\\d\\.\\d+\\.\\d+)",
"versioningTemplate": "loose",
"registryUrlTemplate": "https://yum2npm.io/repos/{{replace '/' '/modules/' registryUrl}}/packages"
}

]
Expand Down
17 changes: 17 additions & 0 deletions .github/test/renovate/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test-local:
#!/bin/bash
set -eo pipefail

if [[ -z "$GITHUB_COM_TOKEN" ]]; then
echo '$GITHUB_COM_TOKEN environment variable not set -- some tests may fail'
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_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
100 changes: 100 additions & 0 deletions .github/test/renovate/test_renovate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/python3

import os
import re
import sys
import subprocess
from pathlib import Path
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+",
"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",
},
"sched-ext/scx": {
"path": "staging/scx-scheds/scx-scheds.spec",
"match": r"Version: 1\.\d+\.\d+",
"replace": r"Version: 1.0.4",
}
}


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():
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"] = log_filename

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.check_call(["/usr/local/sbin/renovate"], shell=False)

found_payload = False
validated = False
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"]:
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()
1 change: 1 addition & 0 deletions staging/fwupd/fwupd.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions staging/scx-scheds/scx-scheds.spec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions staging/topgrade/topgrade.spec
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit aa88989

Please sign in to comment.