-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add renovate tests and more rules (#57)
* 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
Showing
6 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters