Skip to content

Commit 3b279ac

Browse files
authored
Merge pull request #45 from homebysix/1.10.0
v1.10.0 merge to main
2 parents 65a8740 + 51b2544 commit 3b279ac

6 files changed

Lines changed: 92 additions & 17 deletions

File tree

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
with:
4848
languages: ${{ matrix.language }}
4949
# If you wish to specify custom queries, you can do so here or in a config file.
50-
# By default, queries listed here will override any specified in a config file.
50+
# By default, queries listed here will override any specified in a config file.
5151
# Prefix the list here with "+" to use these queries and those in the config file.
5252
# queries: ./path/to/local/query, your-org/your-repo/queries@main
5353

.pre-commit-hooks.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
description: This hook checks AutoPkg recipes to ensure they contain required top-level keys.
1212
entry: check-autopkg-recipes
1313
language: python
14-
files: '\.recipe$'
14+
files: '\.recipe(\.plist|\.yaml|\.json)?$'
1515
types: [text]
1616

1717
- id: check-git-config-email
@@ -97,15 +97,15 @@
9797
description: This hook prevents AutoPkg overrides from being added to the repo.
9898
entry: forbid-autopkg-overrides
9999
language: python
100-
files: '\.recipe$'
100+
files: '\.recipe(\.plist|\.yaml|\.json)?$'
101101
types: [text]
102102

103103
- id: forbid-autopkg-trust-info
104104
name: Forbid AutoPkg Trust Info
105105
description: This hook prevents AutoPkg recipes with trust info from being added to the repo.
106106
entry: forbid-autopkg-trust-info
107107
language: python
108-
files: '\.recipe$'
108+
files: '\.recipe(\.plist|\.yaml|\.json)?$'
109109
types: [text]
110110

111111
- id: munki-makecatalogs

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [1.10.0] - 2021-02-21
6+
7+
### Added
8+
- In anticipation of AutoPkg 2.3, now supports checking YAML recipes (must have extension `.recipe.yaml`).
9+
- In anticipation of AutoPkg 2.3, supports additional AutoPkg plist extension `.recipe.plist`.
10+
- Supports JSON AutoPkg recipes (must have extension `.recipe.json`). NOTE: AutoPkg itself does not yet support JSON recipes.
11+
- Built placeholder for checking for unused AutoPkg recipe input variables in the future. Check is disabled for now.
12+
13+
### Fixed
14+
- Fixed a bug preventing display of AutoPkg recipe path and identifier if duplicate identifier is found in the repo.
15+
516
## [1.9.0] - 2021-01-18
617

718
### Added

README.md

Lines changed: 4 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.9.0
18+
rev: v1.10.0
1919
hooks:
2020
- id: check-plists
2121
# - id: ...
@@ -121,7 +121,7 @@ When combining arguments that take lists (for example: `--required-keys`, `--cat
121121

122122
```yaml
123123
- repo: https://github.com/homebysix/pre-commit-macadmin
124-
rev: v1.9.0
124+
rev: v1.10.0
125125
hooks:
126126
- id: check-munki-pkgsinfo
127127
args: ['--catalogs', 'testing', 'stable', '--']
@@ -131,7 +131,7 @@ But if you also use the `--categories` argument, you would move the trailing `--
131131

132132
```yaml
133133
- repo: https://github.com/homebysix/pre-commit-macadmin
134-
rev: v1.9.0
134+
rev: v1.10.0
135135
hooks:
136136
- id: check-munki-pkgsinfo
137137
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
143143

144144
```yaml
145145
- repo: https://github.com/homebysix/pre-commit-macadmin
146-
rev: v1.9.0
146+
rev: v1.10.0
147147
hooks:
148148
- id: check-munki-pkgsinfo
149149
args: [

pre_commit_hooks/check_autopkg_recipes.py

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
requirements."""
55

66
import argparse
7+
import json
78
import os
89
import plistlib
910
import sys
1011
from contextlib import contextmanager
1112
from distutils.version import LooseVersion
1213
from xml.parsers.expat import ExpatError
1314

15+
from ruamel import yaml
16+
1417
from pre_commit_hooks.util import (
1518
validate_pkginfo_key_types,
1619
validate_required_keys,
@@ -280,6 +283,30 @@ def validate_no_superclass_procs(process, filename):
280283
return passed
281284

282285

286+
# def validate_unused_input_vars(recipe, recipe_text, filename):
287+
# """Warn if any input variables are not referenced in the recipe."""
288+
289+
# # List of variables that are commonly allowed to be unreferenced (lowercase).
290+
# ignored_vars = (
291+
# "name",
292+
# "pkginfo",
293+
# )
294+
295+
# passed = True
296+
# for input_var, _ in recipe.get("Input", {}).items():
297+
# if input_var.lower() in ignored_vars:
298+
# continue
299+
# subst = "%" + input_var + "%"
300+
# if subst not in recipe_text:
301+
# print(
302+
# "{}: WARNING: Input variable {} not referenced in recipe.".format(
303+
# filename, input_var
304+
# )
305+
# )
306+
307+
# return passed
308+
309+
283310
def validate_no_var_in_app_path(process, filename):
284311
"""Ensure %NAME% is not used in app paths that should be hard coded."""
285312

@@ -458,14 +485,40 @@ def main(argv=None):
458485

459486
retval = 0
460487
for filename in args.filenames:
461-
try:
462-
with open(filename, "rb") as openfile:
463-
recipe = plistlib.load(openfile)
464488

465-
except (ExpatError, ValueError) as err:
466-
print("{}: plist parsing error: {}".format(filename, err))
467-
retval = 1
468-
break # No need to continue checking this file
489+
if filename.endswith(".yaml"):
490+
try:
491+
# try to read it as yaml
492+
with open(filename, "rb") as f:
493+
recipe = yaml.safe_load(f)
494+
except Exception as err:
495+
print("{}: yaml parsing error: {}".format(filename, err))
496+
retval = 1
497+
break # No need to continue checking this file
498+
499+
elif filename.endswith(".json"):
500+
try:
501+
# try to read it as json
502+
with open(filename, "rb") as f:
503+
recipe = json.load(f)
504+
except Exception as err:
505+
print("{}: json parsing error: {}".format(filename, err))
506+
retval = 1
507+
break # No need to continue checking this file
508+
509+
else:
510+
try:
511+
# try to read it as a plist
512+
with open(filename, "rb") as f:
513+
recipe = plistlib.load(f)
514+
except Exception as err:
515+
print("{}: plist parsing error: {}".format(filename, err))
516+
retval = 1
517+
break # No need to continue checking this file
518+
519+
# For future implementation of validate_unused_input_vars()
520+
# with open(filename, "r") as openfile:
521+
# recipe_text = openfile.read()
469522

470523
# Top level keys that all AutoPkg recipes should contain.
471524
required_keys = ["Identifier"]
@@ -475,7 +528,11 @@ def main(argv=None):
475528

476529
# Ensure the recipe identifier isn't duplicated.
477530
if recipe["Identifier"] in seen_identifiers:
478-
print('{}: Identifier "{}" is shared by another recipe in this repo.')
531+
print(
532+
'{}: Identifier "{}" is shared by another recipe in this repo.'.format(
533+
filename, recipe["Identifier"]
534+
)
535+
)
479536
retval = 1
480537
else:
481538
seen_identifiers.append(recipe["Identifier"])
@@ -494,6 +551,13 @@ def main(argv=None):
494551
)
495552
retval = 1
496553

554+
# Validate that all input variables are used.
555+
# (Disabled for now because it's a little too opinionated, and doesn't take into account
556+
# whether environmental variables are used in custom processors.)
557+
# if args.strict:
558+
# if not validate_unused_input_vars(recipe, recipe_text, filename):
559+
# retval = 1
560+
497561
# If the Input key contains a pkginfo dict, make a best effort to validate its contents.
498562
input_key = recipe.get("Input", recipe.get("input", recipe.get("INPUT")))
499563
if input_key and "pkginfo" in input_key:

setup.py

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

0 commit comments

Comments
 (0)