Skip to content

Commit

Permalink
Update renovate settings (#117)
Browse files Browse the repository at this point in the history
1 -  Update renovate settings
2 - Integrate new linter for renovate configuration files + tests
  • Loading branch information
EliSchleifer committed Feb 4, 2023
1 parent 4015948 commit e4d5480
Show file tree
Hide file tree
Showing 11 changed files with 16,999 additions and 4,769 deletions.
101 changes: 101 additions & 0 deletions linters/renovate/parse.py
@@ -0,0 +1,101 @@
#!/usr/bin/env python3

"""
renovate-config-validae output looks like this:
```
INFO: Validating renovate.json
ERROR: renovate.json contains errors
"errors": [
{
"topic": "Configuration Error",
"message": "Invalid configuration option: packageRules[0].matchUpdateTypesd"
}
]
```
Bad JSON parses like this
```
WARN: linters/renovate/test_data/bad_renovate.json could not be parsed
"err": {
"lineNumber": 12,
"columnNumber": 1,
"message": "JSON5: invalid end of input at 12:1",
"stack": "SyntaxError: JSON5: invalid end of input at 12:1\n at syntaxError (/home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/json5/lib/parse.js:1110:17)\n at invalidEOF (/home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/json5/lib/parse.js:1059:12)\n at Object.afterPropertyValue (/home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/json5/lib/parse.js:915:19)\n at Object.parse (/home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/json5/lib/parse.js:32:32)\n at getParsedContent (/home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/renovate/lib/workers/global/config/parse/file.ts:20:20)\n at /home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/renovate/lib/config-validator.ts:62:31"
}
```
"""

import json
import re
import sys


def to_result_sarif(
path: str, line_number: int, column_number: int, rule_id: str, message: str
):
return {
"level": "error",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": path,
},
"region": {
"startColumn": column_number,
"startLine": line_number,
},
}
}
],
"message": {
"text": message,
},
"ruleId": rule_id,
}


def main(argv):
results = []
content = sys.stdin.read()

parse_reg = "(.*WARN:.*could not be parsed)(.*)"
error_section = content.find('"errors": [')

parse_result = re.fullmatch(parse_reg, content, flags=re.DOTALL)
if parse_result:
warn_section = parse_result.group(2)
json_content = "{" + warn_section + "}"
error_output = json.loads(json_content)
err = error_output.get("err")
results.append(
to_result_sarif(
".", err["lineNumber"], err["columnNumber"], "JSON", err["message"]
)
)
pass
# TODO - fix this up to read the exit code once that is available in the parser
elif content.find("Config validated successfully") != -1:
pass
elif error_section == -1:
# could not parse - dumping all content as the error
results.append(to_result_sarif(".", 0, 0, "error", content))
else:
# Parse the output as json
json_content = "{" + content[error_section:] + "}"
error_output = json.loads(json_content)
for entry in error_output.get("errors", []):
results.append(to_result_sarif(".", 0, 0, entry["topic"], entry["message"]))

sarif = {
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [{"results": results}],
}

print(json.dumps(sarif, indent=2))


if __name__ == "__main__":
main(sys.argv)
32 changes: 32 additions & 0 deletions linters/renovate/plugin.yaml
@@ -0,0 +1,32 @@
version: 0.1
lint:
files:
- name: renovate-config
filenames:
- renovate.json
- renovate.json5
- .renovaterc.json
- .renovaterc.json5
definitions:
- name: renovate
files: [renovate-config]
runtime: node
package: renovate
commands:
- name: validate
run: renovate-config-validator ${target}
success_codes: [0, 1]
output: sarif
read_output_from: stdout
parser:
runtime: python
run: ${cwd}/parse.py
affects_cache:
- renovate.json
- renovate.json5
- .renovaterc.json
- .renovaterc.json5
known_good_version: 34.122.0
version_command:
parse_regex: ${semver}
run: renovate --version
9 changes: 9 additions & 0 deletions linters/renovate/renovate.test.ts
@@ -0,0 +1,9 @@
import { customLinterCheckTest } from "tests";
import { skipOS } from "tests/utils";

// python missing on mac
customLinterCheckTest({
linterName: "renovate",
args: "-a",
skipTestIf: skipOS(["darwin"]),
});
13 changes: 13 additions & 0 deletions linters/renovate/test_data/.renovaterc.json
@@ -0,0 +1,13 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
"prConcurrentLimit": 3,
"packageRules": [
{
"groupName": "all non-major dependencies",
"groupSlug": "all-minor-patch",
"matchPackagePatterns": ["*"],
"matchUpdateTypes": ["minor", "patch"]
}
]
}
12 changes: 12 additions & 0 deletions linters/renovate/test_data/renovate.json
@@ -0,0 +1,12 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
"packageRules": [
{
"groupName": "all non-major dependencies",
"groupSlug": "all-minor-patch",
"matchPackagePatterns": ["*"],
"matchUpdateTyped_badInfo": ["minor", "patch"]
}
]
}
11 changes: 11 additions & 0 deletions linters/renovate/test_data/renovate.json5
@@ -0,0 +1,11 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
"packageRules": [
{
"groupName": "all non-major dependencies",
"groupSlug": "all-minor-patch",
"matchPackagePatterns": ["*"],
"matchUpdateTyped_badInfo": ["minor", "patch"]
}
]
59 changes: 59 additions & 0 deletions linters/renovate/test_data/renovate_v34.122.0_CUSTOM.check.shot
@@ -0,0 +1,59 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter renovate test CUSTOM 1`] = `
Object {
"issues": Array [
Object {
"bucket": "renovate",
"code": "Configuration-Error",
"file": "test_data/renovate.json",
"level": "LEVEL_HIGH",
"linter": "renovate",
"message": "Invalid configuration option: packageRules[0].matchUpdateTyped_badInfo",
"targetType": "renovate-config",
},
Object {
"bucket": "renovate",
"code": "JSON",
"column": "1",
"file": "test_data/renovate.json5",
"level": "LEVEL_HIGH",
"line": "12",
"linter": "renovate",
"message": "JSON5: invalid end of input at 12:1",
"targetType": "renovate-config",
},
],
"lintActions": Array [
Object {
"command": "validate",
"fileGroupName": "renovate-config",
"linter": "renovate",
"paths": Array [
"test_data/.renovaterc.json",
],
"verb": "TRUNK_VERB_CHECK",
},
Object {
"command": "validate",
"fileGroupName": "renovate-config",
"linter": "renovate",
"paths": Array [
"test_data/renovate.json",
],
"verb": "TRUNK_VERB_CHECK",
},
Object {
"command": "validate",
"fileGroupName": "renovate-config",
"linter": "renovate",
"paths": Array [
"test_data/renovate.json5",
],
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": Array [],
"unformattedFiles": Array [],
}
`;

0 comments on commit e4d5480

Please sign in to comment.