Skip to content

Commit b2799bb

Browse files
committed
Add new --warn-on-duplicate-imports flag for Munki pkginfo checks
1 parent 3034dcb commit b2799bb

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ All notable changes to this project will be documented in this file. This projec
1212

1313
## [Unreleased]
1414

15-
Nothing yet.
15+
### Added
16+
17+
- 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).
18+
19+
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.
1620

1721
## [1.16.2] - 2024-06-10
1822

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ After adding a hook to your pre-commit config, it's not a bad idea to run `pre-c
6161
This hook checks AutoPkg recipes to ensure they meet various requirements and conventions.
6262

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

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

74-
- 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.
75-
`args: ['--strict']`
74+
- 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.
75+
`args: ['--strict']`
7676
(default: False)
7777

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

120-
- 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:
120+
- 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):
121121
`args: ['--warn-on-missing-icons]`
122122

123+
- 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):
124+
`args: ['--warn-on-duplicate-imports]`
125+
123126
- Add additional shebangs that are valid for your environment:
124127
`args: ['--valid-shebangs', '#!/bin/macadmin/python37', '#!/bin/macadmin/python42', '--']`
125128

pre_commit_hooks/check_munki_pkgsinfo.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ def build_argument_parser():
4545
action="store_true",
4646
default=False,
4747
)
48+
parser.add_argument(
49+
"--warn-on-duplicate-imports",
50+
help="If added, this will only warn if pkginfo/pkg files end with a __1 suffix.",
51+
action="store_true",
52+
default=False,
53+
)
4854
parser.add_argument(
4955
"--valid-shebangs",
5056
nargs="+",
@@ -154,10 +160,15 @@ def main(argv=None):
154160

155161
# Check for pkg filenames showing signs of duplicate imports.
156162
if pkginfo.get("installer_item_location", "").endswith(tuple(dupe_suffixes)):
157-
print(
158-
f'{filename}: installer item "{pkginfo.get("installer_item_location")}" may be a duplicate import'
163+
installer_item_location = pkginfo["installer_item_location"]
164+
msg = (
165+
f"installer item '{installer_item_location}' may be a duplicate import"
159166
)
160-
retval = 1
167+
if args.warn_on_missing_icons:
168+
print(f"{filename}: WARNING: {msg}")
169+
else:
170+
print(f"{filename}: {msg}")
171+
retval = 1
161172

162173
# Checking for the absence of blocking_applications for pkg installers.
163174
# If a pkg doesn't require blocking_applications, use empty "<array/>" in pkginfo.
@@ -184,10 +195,11 @@ def main(argv=None):
184195
pkginfo.get("installer_type") == "apple_update_metadata",
185196
)
186197
):
198+
msg = f"missing icon"
187199
if args.warn_on_missing_icons:
188-
print(f"WARNING: {filename}: missing icon")
200+
print(f"{filename}: WARNING: {msg}")
189201
else:
190-
print(f"{filename}: missing icon")
202+
print(f"{filename}: {msg}")
191203
retval = 1
192204

193205
# Ensure uninstall method is set correctly if uninstall_script exists.

0 commit comments

Comments
 (0)