Skip to content

Commit

Permalink
Add new --warn-on-duplicate-imports flag for Munki pkginfo checks
Browse files Browse the repository at this point in the history
  • Loading branch information
homebysix committed Jun 10, 2024
1 parent 3034dcb commit b2799bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ All notable changes to this project will be documented in this file. This projec

## [Unreleased]

Nothing yet.
### Added

- New `--warn-on-duplicate-imports` flag for use with Munki pkginfo checks, for Munki administrators who don't care about multiple potential versions of the same pkginfo/pkg in the repository (perhaps because of differing `supported_architectures` or other keys).

When this is specified, the pre-commit hook will warn when files with `__1` (and similar) suffixes are seen in the pkgsinfo/pkgs folders. This will enbale pre-commit hooks to pass, as long as there are no other errors. Omitting the `--warn-on-duplicate-imports` flag will continue generating an error and failing the hooks, as was the previous behavior.

## [1.16.2] - 2024-06-10

Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ After adding a hook to your pre-commit config, it's not a bad idea to run `pre-c
This hook checks AutoPkg recipes to ensure they meet various requirements and conventions.

- Optionally specify your preferred AutoPkg recipe and/or override prefix, if you wish to enforce them:
`args: ['--override-prefix=com.yourcompany.autopkg.']`
(default: `local.`)
`args: ['--recipe-prefix=com.github.yourusername.']`
`args: ['--override-prefix=com.yourcompany.autopkg.']`
(default: `local.`)
`args: ['--recipe-prefix=com.github.yourusername.']`
(default: `com.github.`)

- Optionally specify the version of AutoPkg for which you want to ignore MinimumVersion mismatches with processors.
`args: ['--ignore-min-vers-before=0.5.0']`
(default: `1.0.0`)
`args: ['--ignore-min-vers-before=0.5.0']`
(default: `1.0.0`)
Specifying `0.1.0` will not ignore any MinimumVersion mismatches.

- If you're a purist, you can also enable strict mode. This enforces recipe type conventions, all processor/MinimumVersion mismatches, forbids `<!-- -->` style comments, and ensures all processor input variables (arguments) are valid.
`args: ['--strict']`
- If you're a purist, you can also enable strict mode. This enforces recipe type conventions, all processor/MinimumVersion mismatches, forbids `<!-- -->` style comments, and ensures all processor input variables (arguments) are valid.
`args: ['--strict']`
(default: False)

- __forbid-autopkg-overrides__
Expand Down Expand Up @@ -117,9 +117,12 @@ After adding a hook to your pre-commit config, it's not a bad idea to run `pre-c
`args: ['--munki-repo', './my_repo_location']`
(default: ".")

- Choose to just warn on missing icons with a flag, note if no other issues exist this will allow pre-commit to pass without seeing the warnings:
- Choose to just warn if icons referenced in pkginfo files are missing (this will allow pre-commit checks to pass if no other issues exist):
`args: ['--warn-on-missing-icons]`

- Choose to just warn if pkg/pkginfo files with __1 (or similar) suffixes are detected (this will allow pre-commit checks to pass if no other issues exist):
`args: ['--warn-on-duplicate-imports]`

- Add additional shebangs that are valid for your environment:
`args: ['--valid-shebangs', '#!/bin/macadmin/python37', '#!/bin/macadmin/python42', '--']`

Expand Down
22 changes: 17 additions & 5 deletions pre_commit_hooks/check_munki_pkgsinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def build_argument_parser():
action="store_true",
default=False,
)
parser.add_argument(
"--warn-on-duplicate-imports",
help="If added, this will only warn if pkginfo/pkg files end with a __1 suffix.",
action="store_true",
default=False,
)
parser.add_argument(
"--valid-shebangs",
nargs="+",
Expand Down Expand Up @@ -154,10 +160,15 @@ def main(argv=None):

# Check for pkg filenames showing signs of duplicate imports.
if pkginfo.get("installer_item_location", "").endswith(tuple(dupe_suffixes)):
print(
f'{filename}: installer item "{pkginfo.get("installer_item_location")}" may be a duplicate import'
installer_item_location = pkginfo["installer_item_location"]
msg = (
f"installer item '{installer_item_location}' may be a duplicate import"
)
retval = 1
if args.warn_on_missing_icons:
print(f"{filename}: WARNING: {msg}")
else:
print(f"{filename}: {msg}")
retval = 1

# Checking for the absence of blocking_applications for pkg installers.
# If a pkg doesn't require blocking_applications, use empty "<array/>" in pkginfo.
Expand All @@ -184,10 +195,11 @@ def main(argv=None):
pkginfo.get("installer_type") == "apple_update_metadata",
)
):
msg = f"missing icon"
if args.warn_on_missing_icons:
print(f"WARNING: {filename}: missing icon")
print(f"{filename}: WARNING: {msg}")
else:
print(f"{filename}: missing icon")
print(f"{filename}: {msg}")
retval = 1

# Ensure uninstall method is set correctly if uninstall_script exists.
Expand Down

0 comments on commit b2799bb

Please sign in to comment.