From 18cfdc65f771829d6c87704e8de45525093e1caa Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Mon, 24 Jun 2019 12:12:11 -0700 Subject: [PATCH 1/3] Add min vers argument, comment warning --- pre_commit_hooks/check_autopkg_recipes.py | 57 +++++++++++++++++++---- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/pre_commit_hooks/check_autopkg_recipes.py b/pre_commit_hooks/check_autopkg_recipes.py index 8f7a7c6..44f0825 100755 --- a/pre_commit_hooks/check_autopkg_recipes.py +++ b/pre_commit_hooks/check_autopkg_recipes.py @@ -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 @@ -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", @@ -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: + print( + "{}: WARNING: style comments will be lost during plutil " + "conversion.".format(filename) + ) + return retval From 5e7340c7eb35e176643245bb9851dbe3e70f9bc1 Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Mon, 24 Jun 2019 12:12:25 -0700 Subject: [PATCH 2/3] Bump version to 1.1.3 --- README.md | 8 ++++---- setup.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e4399ad..bac1e6e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ For any hook in this repo you wish to use, add the following to your pre-commit ``` - repo: https://github.com/homebysix/pre-commit-macadmin - rev: v1.1.2 + rev: v1.1.3 hooks: - id: check-plists # - id: ... @@ -105,7 +105,7 @@ When combining arguments that take lists (for example: `--required-keys`, `--cat ``` - repo: https://github.com/homebysix/pre-commit-macadmin - rev: v1.1.2 + rev: v1.1.3 hooks: - id: check-munki-pkgsinfo args: ['--catalogs', 'testing', 'stable', '--'] @@ -115,7 +115,7 @@ But if you also use the `--categories` argument, you would move the trailing `-- ``` - repo: https://github.com/homebysix/pre-commit-macadmin - rev: v1.1.2 + rev: v1.1.3 hooks: - id: check-munki-pkgsinfo args: ['--catalogs', 'testing', 'stable', '--categories', 'Design', 'Engineering', 'Web Browsers', '--'] @@ -127,7 +127,7 @@ If it looks better to your eye, feel free to use a multi-line list for long argu ``` - repo: https://github.com/homebysix/pre-commit-macadmin - rev: v1.1.2 + rev: v1.1.3 hooks: - id: check-munki-pkgsinfo args: [ diff --git a/setup.py b/setup.py index 28f208d..6700b59 100755 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ name="pre-commit-macadmin", description="Pre-commit hooks for Mac admins, client engineers, and IT consultants.", url="https://github.com/homebysix/pre-commit-macadmin", - version="1.1.2", + version="1.1.3", author="Elliot Jordan", author_email="elliot@elliotjordan.com", packages=["pre_commit_hooks"], From 6d81854ee262de029b00ca2853eb357c17f150a4 Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Mon, 24 Jun 2019 12:15:07 -0700 Subject: [PATCH 3/3] Adjust warning message for comments --- pre_commit_hooks/check_autopkg_recipes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pre_commit_hooks/check_autopkg_recipes.py b/pre_commit_hooks/check_autopkg_recipes.py index 44f0825..16fefcc 100755 --- a/pre_commit_hooks/check_autopkg_recipes.py +++ b/pre_commit_hooks/check_autopkg_recipes.py @@ -167,8 +167,8 @@ def main(argv=None): recipe_text = openfile.read() if "" in recipe_text: print( - "{}: WARNING: style comments will be lost during plutil " - "conversion.".format(filename) + "{}: WARNING: Recommend converting from style comments to a " + "Comment key where needed.".format(filename) ) return retval