Skip to content

Commit

Permalink
Merge pull request #22 from homebysix/1.1.4
Browse files Browse the repository at this point in the history
1.1.4
  • Loading branch information
homebysix authored Jun 24, 2019
2 parents 901c086 + 3b921f2 commit e0be1aa
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 81 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.3
rev: v1.1.4
hooks:
- id: check-plists
# - id: ...
Expand Down Expand Up @@ -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.3
rev: v1.1.4
hooks:
- id: check-munki-pkgsinfo
args: ['--catalogs', 'testing', 'stable', '--']
Expand All @@ -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.3
rev: v1.1.4
hooks:
- id: check-munki-pkgsinfo
args: ['--catalogs', 'testing', 'stable', '--categories', 'Design', 'Engineering', 'Web Browsers', '--']
Expand All @@ -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.3
rev: v1.1.4
hooks:
- id: check-munki-pkgsinfo
args: [
Expand Down
162 changes: 86 additions & 76 deletions pre_commit_hooks/check_autopkg_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,54 @@

from pre_commit_hooks.util import validate_pkginfo_key_types

# Processors for which a minimum version of AutoPkg is required.
PROC_MIN_VERSIONS = {
"AppPkgCreator": "1.0.0",
"BrewCaskInfoProvider": "0.2.5",
"CodeSignatureVerifier": "0.3.1",
"CURLDownloader": "0.5.1",
"CURLTextSearcher": "0.5.1",
"DeprecationWarning": "1.1.0",
"EndOfCheckPhase": "0.1.0",
"FileFinder": "0.2.3",
"FileMover": "0.2.9",
"FlatPkgPacker": "0.2.4",
"FlatPkgUnpacker": "0.1.0",
"GitHubReleasesInfoProvider": "0.5.0",
"Installer": "0.4.0",
"InstallFromDMG": "0.4.0",
"MunkiCatalogBuilder": "0.1.0",
"MunkiImporter": "0.1.0",
"MunkiInstallsItemsCreator": "0.1.0",
"MunkiPkginfoMerger": "0.1.0",
"MunkiSetDefaultCatalog": "0.4.2",
"PackageRequired": "0.5.1",
"PathDeleter": "0.1.0",
"PkgCopier": "0.1.0",
"PkgExtractor": "0.1.0",
"PkgPayloadUnpacker": "0.1.0",
"PlistEditor": "0.1.0",
"PlistReader": "0.2.5",
"SparkleUpdateInfoProvider": "0.1.0",
"StopProcessingIf": "0.1.0",
"Symlinker": "0.1.0",
"Unarchiver": "0.1.0",
"URLTextSearcher": "0.2.9",
"Versioner": "0.1.0",
}

# Processors for which %NAME%.app should not be present in the arguments.
NO_NAME_VAR_IN_PROC_ARGS = (
"CodeSignatureVerifier",
"Versioner",
"PkgPayloadUnpacker",
"FlatPkgUnpacker",
"FileFinder",
"Copier",
"AppDmgVersioner",
"InstallFromDMG",
)


def build_argument_parser():
"""Build and return the argument parser."""
Expand Down Expand Up @@ -84,84 +132,11 @@ def main(argv=None):
)
retval = 1

input = recipe.get("Input", recipe.get("input", recipe.get("INPUT")))
if input and "pkginfo" in input:
if not validate_pkginfo_key_types(input["pkginfo"], filename):
input_key = recipe.get("Input", recipe.get("input", recipe.get("INPUT")))
if input_key and "pkginfo" in input_key:
if not validate_pkginfo_key_types(input_key["pkginfo"], filename):
retval = 1

# Ensure MinimumVersion is set appropriately for the processors used.
proc_min_versions = {
"AppPkgCreator": "1.0.0",
"BrewCaskInfoProvider": "0.2.5",
"CodeSignatureVerifier": "0.3.1",
"CURLDownloader": "0.5.1",
"CURLTextSearcher": "0.5.1",
"DeprecationWarning": "1.1.0",
"EndOfCheckPhase": "0.1.0",
"FileFinder": "0.2.3",
"FileMover": "0.2.9",
"FlatPkgPacker": "0.2.4",
"FlatPkgUnpacker": "0.1.0",
"GitHubReleasesInfoProvider": "0.5.0",
"Installer": "0.4.0",
"InstallFromDMG": "0.4.0",
"MunkiCatalogBuilder": "0.1.0",
"MunkiImporter": "0.1.0",
"MunkiInstallsItemsCreator": "0.1.0",
"MunkiPkginfoMerger": "0.1.0",
"MunkiSetDefaultCatalog": "0.4.2",
"PackageRequired": "0.5.1",
"PathDeleter": "0.1.0",
"PkgCopier": "0.1.0",
"PkgExtractor": "0.1.0",
"PkgPayloadUnpacker": "0.1.0",
"PlistEditor": "0.1.0",
"PlistReader": "0.2.5",
"SparkleUpdateInfoProvider": "0.1.0",
"StopProcessingIf": "0.1.0",
"Symlinker": "0.1.0",
"Unarchiver": "0.1.0",
"URLTextSearcher": "0.2.9",
"Versioner": "0.1.0",
}
if "Process" in recipe and "MinimumVersion" in recipe:
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(
proc_min_versions[proc]
):
print(
"{}: {} 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()
Expand All @@ -171,6 +146,41 @@ def main(argv=None):
"Comment key where needed.".format(filename)
)

# Processor checks.
if "Process" in recipe:
# Ensure MinimumVersion is set appropriately for the processors used.
if "MinimumVersion" in recipe:
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(
PROC_MIN_VERSIONS[proc]
):
print(
"{}: {} 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.
for process in recipe["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

return retval


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.3",
version="1.1.4",
author="Elliot Jordan",
author_email="[email protected]",
packages=["pre_commit_hooks"],
Expand Down

0 comments on commit e0be1aa

Please sign in to comment.