Skip to content

Commit 06fd21c

Browse files
committed
Merge branch 'main' into dev
# Conflicts: # .pre-commit-config.yaml
2 parents 0088ee1 + be65b30 commit 06fd21c

9 files changed

Lines changed: 80 additions & 49 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repos:
2828
rev: 6.0.1
2929
hooks:
3030
- id: isort
31-
- repo: https://github.com/python/black
31+
- repo: https://github.com/psf/black
3232
rev: 25.1.0
3333
hooks:
3434
- id: black

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ All notable changes to this project will be documented in this file. This projec
1212

1313
## [Unreleased]
1414

15+
Nothing yet.
16+
17+
## [1.19.0] - 2025-01-16
18+
1519
### Added
1620

21+
- Added `--warn-on-missing-installer-items` flag that makes missing Munki install/uninstall items a warning instead of a failure. (#86, thanks to @haircut)
22+
- Apply the same checks to `uninstaller_item_location` that were previously applied to `installer_item_location`.
1723
- `check-autopkg-recipes` requires Munki recipe `pkginfo` dicts to contain at least `name` and `description`.
1824
- `check-autopkg-recipes` now validates that `uninstall_method` and `uninstall_script` are set appropriately in Munki recipes.
1925
- `check-autopkg-recipes` and `check-munki-pkgsinfo` now validates that `supported_architectures` values are set appropriately.
@@ -23,6 +29,11 @@ All notable changes to this project will be documented in this file. This projec
2329
- `check-autopkg-recipes` includes jamf-upload as an AutoPkg recipe type, and updated processors included in jamf/jamf-upload recipe convention.
2430
- `check-munki-pkgsinfo` requires a `version` key in addition to `name` and `description`.
2531

32+
### Fixed
33+
34+
- Bug fix in `check-munkiadmin-scripts` that prevented script names from processing correctly.
35+
- Bug fix in `check-munki-pkgsinfo` that prevented `--warn-on-duplicate-imports` flag from working correctly.
36+
2637
## [1.18.0] - 2025-01-04
2738

2839
### Added

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ For any hook in this repo you wish to use, add the following to your pre-commit
1515

1616
```yaml
1717
- repo: https://github.com/homebysix/pre-commit-macadmin
18-
rev: v1.18.0
18+
rev: v1.19.0
1919
hooks:
2020
- id: check-plists
2121
# - id: ...
@@ -120,6 +120,9 @@ After adding a hook to your pre-commit config, it's not a bad idea to run `pre-c
120120
- 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 installer/uninstaller items (`installer_item_location` or `uninstaller_item_location`) referenced in pkginfo files are missing (this will allow pre-commit checks to pass if no other issues exist):
124+
`args: ['--warn-on-missing-installer-items]`
125+
123126
- 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):
124127
`args: ['--warn-on-duplicate-imports]`
125128

@@ -144,7 +147,7 @@ When combining arguments that take lists (for example: `--required-keys`, `--cat
144147

145148
```yaml
146149
- repo: https://github.com/homebysix/pre-commit-macadmin
147-
rev: v1.18.0
150+
rev: v1.19.0
148151
hooks:
149152
- id: check-munki-pkgsinfo
150153
args: ['--catalogs', 'testing', 'stable', '--']
@@ -154,7 +157,7 @@ But if you also use the `--categories` argument, you would move the trailing `--
154157

155158
```yaml
156159
- repo: https://github.com/homebysix/pre-commit-macadmin
157-
rev: v1.18.0
160+
rev: v1.19.0
158161
hooks:
159162
- id: check-munki-pkgsinfo
160163
args: ['--catalogs', 'testing', 'stable', '--categories', 'Design', 'Engineering', 'Web Browsers', '--']
@@ -166,7 +169,7 @@ If it looks better to your eye, feel free to use a multi-line list for long argu
166169

167170
```yaml
168171
- repo: https://github.com/homebysix/pre-commit-macadmin
169-
rev: v1.18.0
172+
rev: v1.19.0
170173
hooks:
171174
- id: check-munki-pkgsinfo
172175
args: [

pre_commit_hooks/check_jamf_json_manifests.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
import json
1010
from datetime import datetime
1111

12-
from pre_commit_hooks.util import PLIST_TYPES, validate_required_keys
12+
from pre_commit_hooks.util import validate_required_keys
1313

1414
# Types found in the Jamf JSON manifests
15-
MANIFEST_TYPES = (
16-
"array",
17-
"boolean",
18-
"data",
19-
"date",
20-
"float",
21-
"integer",
22-
"number",
23-
"object",
24-
"real",
25-
"string",
26-
)
15+
MANIFEST_TYPES = {
16+
"array": list,
17+
"boolean": bool,
18+
"data": str,
19+
"date": datetime,
20+
"float": float,
21+
"integer": int,
22+
"number": int,
23+
"object": dict,
24+
"real": float,
25+
"string": str,
26+
}
2727

2828
# List keys and their expected item types
2929
MANIFEST_LIST_TYPES = {
@@ -132,9 +132,9 @@ def validate_default(name, prop, type_found, filename):
132132
actual_type = str
133133
else:
134134
actual_type = type(prop[test_key])
135-
if actual_type != PLIST_TYPES.get(type_found):
135+
if actual_type != MANIFEST_TYPES.get(type_found):
136136
print(
137-
f"{filename}: {test_key} value for {name} should be {PLIST_TYPES.get(type_found)}, not {type(prop[test_key])}"
137+
f"{filename}: {test_key} value for {name} should be {MANIFEST_TYPES.get(type_found)}, not {type(prop[test_key])}"
138138
)
139139
passed = False
140140

pre_commit_hooks/check_munki_pkgsinfo.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ def build_argument_parser():
4949
action="store_true",
5050
default=False,
5151
)
52+
parser.add_argument(
53+
"--warn-on-missing-installer-items",
54+
help="If added, this will only warn on missing installer items.",
55+
action="store_true",
56+
default=False,
57+
)
5258
parser.add_argument(
5359
"--warn-on-duplicate-imports",
5460
help="If added, this will only warn if pkginfo/pkg files end with a __1 suffix.",
@@ -149,29 +155,6 @@ def main(argv=None):
149155
print(f'{filename}: catalog "{catalog}" is not in approved list')
150156
retval = 1
151157

152-
# Check for missing or case-conflicted installer items
153-
if not _check_case_sensitive_path(
154-
os.path.join(
155-
args.munki_repo, "pkgs", pkginfo.get("installer_item_location", "")
156-
)
157-
):
158-
print(
159-
f"{filename}: installer item does not exist or path is not case sensitive"
160-
)
161-
retval = 1
162-
163-
# Check for pkg filenames showing signs of duplicate imports.
164-
if pkginfo.get("installer_item_location", "").endswith(tuple(dupe_suffixes)):
165-
installer_item_location = pkginfo["installer_item_location"]
166-
msg = (
167-
f"installer item '{installer_item_location}' may be a duplicate import"
168-
)
169-
if args.warn_on_missing_icons:
170-
print(f"{filename}: WARNING: {msg}")
171-
else:
172-
print(f"{filename}: {msg}")
173-
retval = 1
174-
175158
# Checking for the absence of blocking_applications for pkg installers.
176159
# If a pkg doesn't require blocking_applications, use empty "<array/>" in pkginfo.
177160
if args.require_pkg_blocking_apps and all(
@@ -187,6 +170,34 @@ def main(argv=None):
187170
)
188171
retval = 1
189172

173+
# Begin checks that apply to both installers and uninstallers
174+
for i_type in ("installer", "uninstaller"):
175+
176+
# Check for missing or case-conflicted installer or uninstaller items
177+
if not _check_case_sensitive_path(
178+
os.path.join(
179+
args.munki_repo, "pkgs", pkginfo.get(f"{i_type}_item_location", "")
180+
)
181+
):
182+
msg = f"{i_type} item does not exist or path is not case sensitive"
183+
if args.warn_on_missing_installer_items:
184+
print(f"{filename}: WARNING: {msg}")
185+
else:
186+
print(f"{filename}: {msg}")
187+
retval = 1
188+
189+
# Check for pkg filenames showing signs of duplicate imports.
190+
if pkginfo.get(f"{i_type}_item_location", "").endswith(
191+
tuple(dupe_suffixes)
192+
):
193+
item_loc = pkginfo[f"{i_type}_item_location"]
194+
msg = f"{i_type} item '{item_loc}' may be a duplicate import"
195+
if args.warn_on_duplicate_imports:
196+
print(f"{filename}: WARNING: {msg}")
197+
else:
198+
print(f"{filename}: {msg}")
199+
retval = 1
200+
190201
# Ensure an icon exists for the item.
191202
if not any(
192203
(

pre_commit_hooks/check_munkiadmin_scripts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def main(argv=None):
3232
prefixes = ["manifest", "pkginfo", "repository"]
3333
actions = ["custom", "postopen", "postsave", "presave"]
3434
ma_script_prefixes = [f"{p}-{a}" for p in prefixes for a in actions]
35-
if not any(filename.startswith(prefix) for prefix in ma_script_prefixes):
35+
if not any(
36+
os.path.basename(filename).startswith(prefix)
37+
for prefix in ma_script_prefixes
38+
):
3639
print(f"{filename}: does not start with a valid MunkiAdmin script prefix")
3740
retval = 1
3841

pre_commit_hooks/check_preference_manifests.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ def validate_pfm_type_strings(subkey, filename):
184184
print(f'{filename}: WARNING: Subkey type "{subkey["pfm_type"]}" is deprecated')
185185
# passed = False
186186
elif subkey["pfm_type"] not in PLIST_TYPES:
187-
print(f'{filename}: Unexpected subkey type "{subkey["pfm_type"]}"')
187+
print(
188+
f'{filename}: Unexpected subkey type {subkey["pfm_type"]} for {subkey.get("pfm_name")}'
189+
)
188190
passed = False
189191

190192
return passed
@@ -282,7 +284,7 @@ def validate_pfm_default(subkey, filename):
282284
# continue
283285
# else:
284286
desired_type = PLIST_TYPES[subkey["pfm_type"]]
285-
if isinstance(subkey[test_key], desired_type):
287+
if not isinstance(subkey[test_key], desired_type):
286288
print(
287289
f"{filename}: {test_key} value for {subkey.get('pfm_name')} should be type "
288290
f"{PLIST_TYPES[subkey['pfm_type']]}, not type {type(subkey[test_key])}"
@@ -333,6 +335,7 @@ def validate_platforms(subkey, filename):
333335
def validate_subkeys(subkeys, filename):
334336
"""Given a list of subkeys, run validation on their contents."""
335337
passed = True
338+
type_passed = True
336339

337340
for subkey in subkeys:
338341

@@ -355,6 +358,7 @@ def validate_subkeys(subkeys, filename):
355358
# Check for rogue pfm_type strings and deprecated keys.
356359
if not validate_pfm_type_strings(subkey, filename):
357360
passed = False
361+
type_passed = False
358362

359363
# TODO: Suggest adding a title if one is missing
360364
# if "pfm_title" not in subkey:
@@ -378,7 +382,7 @@ def validate_subkeys(subkeys, filename):
378382
passed = False
379383

380384
# Check default values to ensure consistent type
381-
if not validate_pfm_default(subkey, filename):
385+
if type_passed and not validate_pfm_default(subkey, filename):
382386
passed = False
383387

384388
# Validate URLs

pre_commit_hooks/util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"integer": int,
1818
"array": list,
1919
"data": None, # TODO: How to represent this?
20-
"float": float,
2120
"real": float,
2221
"date": datetime,
2322
}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
name="pre-commit-macadmin",
77
description="Pre-commit hooks for Mac admins, client engineers, and IT consultants.",
88
url="https://github.com/homebysix/pre-commit-macadmin",
9-
version="1.18.0",
9+
version="1.19.0",
1010
author="Elliot Jordan",
1111
author_email="elliot@elliotjordan.com",
1212
packages=["pre_commit_hooks"],

0 commit comments

Comments
 (0)