From 02644cda36a5a96b07ebd50cfaff030089832dae Mon Sep 17 00:00:00 2001 From: Aaron Burchfield Date: Sat, 18 Mar 2023 22:41:21 -0700 Subject: [PATCH 1/4] check that installer items exist and match the file system case --- pre_commit_hooks/check_munki_pkgsinfo.py | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pre_commit_hooks/check_munki_pkgsinfo.py b/pre_commit_hooks/check_munki_pkgsinfo.py index 756bd27..26b7768 100755 --- a/pre_commit_hooks/check_munki_pkgsinfo.py +++ b/pre_commit_hooks/check_munki_pkgsinfo.py @@ -5,6 +5,7 @@ import argparse import os import plistlib +from pathlib import Path from xml.parsers.expat import ExpatError from pre_commit_hooks.util import ( @@ -37,6 +38,22 @@ def build_argument_parser(): return parser +def _check_case_sensitive_path(path): + # Return immediately if the file does not exist + if not os.path.exists(path): + return False + + p = Path(path) + while True: + # At root, p == p.parent --> break loop and return True + if p == p.parent: + return True + # If string representation of path is not in parent directory, return False + if str(p) not in map(str, p.parent.iterdir()): + return False + p = p.parent + + def main(argv=None): """Main process.""" @@ -114,6 +131,22 @@ def main(argv=None): ) retval = 1 + # Check for missing installer items + if all( + ( + "installer_item_location" in pkginfo, + not _check_case_sensitive_path( + os.path.join("pkgs", pkginfo.get("installer_item_location")) + ), + ) + ): + print( + "{}: installer item does not exist or path is not case sensitive".format( + filename + ) + ) + retval = 1 + # Check for pkg filenames showing signs of duplicate imports. if pkginfo.get("installer_item_location", "").endswith(tuple(dupe_suffixes)): print( From 894b5a97d782c3e00946cbb688345d84a61bfd02 Mon Sep 17 00:00:00 2001 From: Ari Leviatan Date: Mon, 14 Aug 2023 11:42:22 +0200 Subject: [PATCH 2/4] Increased result granularity in the URL validation --- pre_commit_hooks/check_preference_manifests.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pre_commit_hooks/check_preference_manifests.py b/pre_commit_hooks/check_preference_manifests.py index 08cb2e6..2538912 100755 --- a/pre_commit_hooks/check_preference_manifests.py +++ b/pre_commit_hooks/check_preference_manifests.py @@ -324,7 +324,15 @@ def validate_urls(subkey, filename): url_keys = ("pfm_app_url", "pfm_documentation_url") for url_key in url_keys: if url_key in subkey: - if not subkey[url_key].startswith("http"): + if len(subkey[url_key]) == 0: + print( + "{}: {} URL value is empty.".format( + filename, + url_key, + ) + ) + passed = False + elif not subkey[url_key].startswith("http"): print( "{}: {} value doesn't look like a URL: {}".format( filename, From 80e2d55c2ca2a9be2fc9ce752efcd442b2073cb4 Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Sat, 18 Nov 2023 03:29:23 -0800 Subject: [PATCH 3/4] Bump version for development --- README.md | 8 ++++---- setup.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 77a18ef..794d2b4 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ For any hook in this repo you wish to use, add the following to your pre-commit ```yaml - repo: https://github.com/homebysix/pre-commit-macadmin - rev: v1.13.0 + rev: v1.14.0 hooks: - id: check-plists # - id: ... @@ -121,7 +121,7 @@ When combining arguments that take lists (for example: `--required-keys`, `--cat ```yaml - repo: https://github.com/homebysix/pre-commit-macadmin - rev: v1.13.0 + rev: v1.14.0 hooks: - id: check-munki-pkgsinfo args: ['--catalogs', 'testing', 'stable', '--'] @@ -131,7 +131,7 @@ But if you also use the `--categories` argument, you would move the trailing `-- ```yaml - repo: https://github.com/homebysix/pre-commit-macadmin - rev: v1.13.0 + rev: v1.14.0 hooks: - id: check-munki-pkgsinfo args: ['--catalogs', 'testing', 'stable', '--categories', 'Design', 'Engineering', 'Web Browsers', '--'] @@ -143,7 +143,7 @@ If it looks better to your eye, feel free to use a multi-line list for long argu ```yaml - repo: https://github.com/homebysix/pre-commit-macadmin - rev: v1.13.0 + rev: v1.14.0 hooks: - id: check-munki-pkgsinfo args: [ diff --git a/setup.py b/setup.py index b9a0768..e46c825 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,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.13.0", + version="1.14.0", author="Elliot Jordan", author_email="elliot@elliotjordan.com", packages=["pre_commit_hooks"], From 6df6b492557558c47f3c9925ae18c8c672f1c941 Mon Sep 17 00:00:00 2001 From: Elliot Jordan Date: Sun, 19 Nov 2023 12:52:18 -0800 Subject: [PATCH 4/4] Update change log for 1.14.0 PRs --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8782d2f..0efbf21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,13 @@ All notable changes to this project will be documented in this file. This projec Nothing yet. +## [1.14.0] - 2023-11-19 + +### Added + +- `check-preference-manifests` hook now outputs more specific error message if `pfm_documentation_url` is empty (#67, thanks to @relgit). +- `check-munki-pkgsinfo` hook now detects path mismatches on case-sensitive filesystems (#66, thanks to @AaronBurchfield). + ## [1.13.0] - 2023-11-18 ### Changed