Skip to content

Commit

Permalink
Add min vers argument, comment warning
Browse files Browse the repository at this point in the history
  • Loading branch information
homebysix committed Jun 24, 2019
1 parent 86177f9 commit 18cfdc6
Showing 1 changed file with 49 additions and 8 deletions.
57 changes: 49 additions & 8 deletions pre_commit_hooks/check_autopkg_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ def build_argument_parser():
parser.add_argument(
"--override-prefix",
default="local.",
help='Expected prefix for recipe override identifiers. (defaults to "local")',
help='Expected prefix for recipe override identifiers (defaults to "local").',
)
parser.add_argument(
"--recipe-prefix",
default="com.github.",
help='Expected prefix for recipe identifiers. (defaults to "com.github")',
help='Expected prefix for recipe identifiers (defaults to "com.github").',
)
parser.add_argument(
"--ignore-min-vers-before",
default="1.0.0",
help="Ignore MinimumVersion/processor mismatches below this version of AutoPkg "
'(defaults to "1.0.0").\nSet to 0.1.0 to warn about all '
"MinimumVersion/processor mismatches.",
)
parser.add_argument("filenames", nargs="*", help="Filenames to check.")
return parser
Expand Down Expand Up @@ -83,7 +90,7 @@ def main(argv=None):
retval = 1

# Ensure MinimumVersion is set appropriately for the processors used.
processor_min_versions = {
proc_min_versions = {
"AppPkgCreator": "1.0.0",
"BrewCaskInfoProvider": "0.2.5",
"CodeSignatureVerifier": "0.3.1",
Expand Down Expand Up @@ -118,18 +125,52 @@ def main(argv=None):
"Versioner": "0.1.0",
}
if "Process" in recipe and "MinimumVersion" in recipe:
for proc in processor_min_versions:
for proc in [
x
for x in proc_min_versions
if LooseVersion(proc_min_versions[x])
>= LooseVersion(args.ignore_min_vers_before)
]:
if proc in [x["Processor"] for x in recipe["Process"]]:
if LooseVersion(recipe["MinimumVersion"]) < LooseVersion(
processor_min_versions[proc]
proc_min_versions[proc]
):
print(
"{}: {} processor requires minimum AutoPkg version {}".format(
filename, proc, processor_min_versions[proc]
)
"{}: {} processor requires minimum AutoPkg "
"version {}".format(filename, proc, proc_min_versions[proc])
)
retval = 1

# Ensure %NAME% is not used in app paths that should be hard coded.
no_name_var_in_proc_args = (
"CodeSignatureVerifier",
"Versioner",
"PkgPayloadUnpacker",
"FlatPkgUnpacker",
"FileFinder",
"Copier",
"AppDmgVersioner",
"InstallFromDMG",
)
for process in recipe.get("Process"):
if process["Processor"] in no_name_var_in_proc_args:
for _, argvalue in process["Arguments"].items():
if isinstance(argvalue, str) and "%NAME%.app" in argvalue:
print(
"{}: Use actual app name instead of %NAME%.app in {} "
"processor argument.".format(filename, process["Processor"])
)
retval = 1

# Warn about comments that would be lost during `plutil -convert xml1`
with open(filename, "r") as openfile:
recipe_text = openfile.read()
if "<!--" in recipe_text and "-->" in recipe_text:
print(
"{}: WARNING: <!-- --> style comments will be lost during plutil "
"conversion.".format(filename)
)

return retval


Expand Down

0 comments on commit 18cfdc6

Please sign in to comment.