Repository navigation
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
139 lines (137 loc) · 7.77 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
139 lines (137 loc) · 7.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# DO NOT EDIT. Generated with:
#
# devctl
#
# https://github.com/giantswarm/devctl/blob/84caccc8334479d1752d924494e76942d6ec1188/pkg/gen/input/precommit/internal/file/pre-commit-config.yaml.template
#
minimum_pre_commit_version: '2.17'
default_install_hook_types: [pre-commit, commit-msg]
# Protobuf-generated code (protoc, buf: *_pb.ts, *_pb.js, *_pb2.py,
# *_pb2_grpc.py, *.pb.go, *_grpc.pb.go) belongs to its generator: a hook that
# rewrote it (end-of-file-fixer, go-imports, ruff --fix) would be undone by
# the next generation, so no hook reads it.
exclude: "(_pb2?|\\.pb)(_grpc)?\\.[^/]+$"
repos:
# base hooks
#
# helm/<chart>/charts/ holds vendored upstream subcharts (vendir-synced).
# Those files are not repo-authored: the auto-fixing hooks would rewrite
# them on every vendir bump and the next vendir sync would revert the fix,
# so the whitespace/shebang/private-key hooks skip the vendored subtree.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
exclude: "^helm/[^/]+/charts/.*"
- id: detect-private-key
# Upstream charts document key formats with placeholder PEM headers
# (redis-ha's restore.ssh.key example) that the hook cannot tell from
# a key; gitleaks stays the scanner of record for the vendored subtree.
exclude: "^helm/[^/]+/charts/.*"
- id: end-of-file-fixer
exclude: "(.*testdata/.*|^\\.yarn/.*|^helm/[^/]+/charts/.*|.*.patch)"
- id: mixed-line-ending
exclude: "(^helm/[^/]+/charts/.*|.*.patch)"
- id: trailing-whitespace
exclude: "(.*testdata/.*|^\\.yarn/.*|^helm/[^/]+/charts/.*|.*.patch)"
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.5.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
args: [--strict]
# Helm chart schema for agent: verify helm/agent/values.schema.json is up to date.
#
# `devctl gen precommit` now generates and writes helm/agent/values.schema.json itself
# (running the same generate -> fix $ref -> normalize pipeline in-process, see
# giantswarm/devctl#2195), so this hook is READ-ONLY: it reproduces that pipeline to a
# scratch file and diffs it against the committed one, but never writes the committed
# file. A hook that regenerated files in place used to fight `schemalint-verify` and
# itself over key ordering, because pre-commit runs each hook independently against the
# file on disk and fails the run if any hook modifies it (giantswarm/giantswarm#37267);
# a read-only check has no resting format to fight over.
#
# The `$ref` step repairs a JSON Schema 2020-12 defect: `additionalProperties: false` as
# a sibling of a `$ref`. `additionalProperties` only sees sibling
# `properties`/`patternProperties` -- NOT properties pulled in through `$ref` -- so such
# a node rejects every field the referenced schema defines (e.g. `helm template` fails
# with "additional properties 'podAntiAffinity' not allowed" for a k8s Affinity). The
# correct keyword is `unevaluatedProperties`, which DOES consider $ref-evaluated
# properties. So for every object that has both `$ref` and `additionalProperties: false`
# we drop `additionalProperties` and set `unevaluatedProperties: false`.
#
# The generator itself no longer produces this. It did until v2.6.0, which shipped
# https://github.com/losisin/helm-values-schema-json/pull/378 (fixing #317): at draft
# 2019 or later, with `noAdditionalProperties: true`, it now closes applicator-bearing
# nodes with `unevaluatedProperties` instead. devctl sets `draft: 2020`, so that holds
# here. Under v2.6.0 the step is a no-op on generated output -- measured over every
# repository that DECLARES the `helmchart` pre-commit flavour. The hook reaches more
# repositories than that: `helmchart` is also the default flavour for any repository
# with a `helm/` directory, so re-measure over those too before you act on the number.
#
# It stays for schemas the generator BUNDLES rather than generates. `bundle: true`
# inlines a `# @schema $ref: <file>` target verbatim, defect included, and the tool
# cannot be expected to rewrite third-party content. One repo depends on this today:
# security-profiles-operator-app vendors the upstream chart's own `values.schema.json`,
# whose `daemon.tolerations` items close a `$ref`ed k8s Toleration with
# `additionalProperties: false` and so reject `value` and `tolerationSeconds`.
# Before removing this step, re-run that measurement -- do not assume it is dead.
#
# BOTH binaries are installed and pinned by the hook itself (`additional_dependencies`,
# hence `language: golang`), at the exact versions devctl's own go.mod requires (stamped
# in by the generator, not hardcoded here), so this reproduction runs the same versions
# devctl used to write the committed file.
#
# `helm-values-schema-json` is the module behind the `helm schema` plugin -- the very
# same binary, called directly, so nothing here depends on a helm plugin. It used to:
# the hook called a bare `helm schema`, resolved from whatever the developer had in
# their global helm plugin dir, while CI pinned a version in a different file. The old
# guard only checked that *a* plugin existed, never which version, so a wrong version
# printed "Passed" locally while rewriting the committed schema (v2.6.0 alone strips 41
# lines from hello-world-app's) and CI then rejected it.
- repo: local
hooks:
- id: helm-schema-agent
name: "verify helm/agent/values.schema.json is up to date"
language: golang
additional_dependencies: ['github.com/giantswarm/schemalint/v2@v2.6.3', 'github.com/losisin/helm-values-schema-json/v2@v2.6.1']
files: ^helm/agent/(values\.yaml|\.schema\.yaml|values\.schema\.json|zz_generated\.app-platform\.values\.yaml)$
pass_filenames: false
require_serial: true
entry: sh -c
args:
- |
set -e
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
helm-values-schema-json --config helm/agent/.schema.yaml -o "$tmp"
python3 -c 'import json,sys; h=lambda o: {**{k:v for k,v in o.items() if k!="additionalProperties"},"unevaluatedProperties":False} if ("$ref" in o and o.get("additionalProperties") is False) else o; p=sys.argv[1]; f=open(p,encoding="utf-8"); d=json.load(f,object_hook=h); f.close(); f=open(p,"w",encoding="utf-8"); json.dump(d,f); f.close()' "$tmp"
schemalint normalize "$tmp" -o "$tmp" --force
if ! diff -u helm/agent/values.schema.json "$tmp"; then
printf '%s\n' "helm/agent/values.schema.json is out of date; run from the repository root and commit the result:" 'devctl gen precommit --language='"'"'generic'"'"' --repo-name='"'"'agent'"'"' --flavors='"'"'helmchart'"'"' --k8s-schema-version='"'"'v1.33.1'"'"'' >&2
exit 1
fi
- repo: https://github.com/giantswarm/schemalint
rev: v2.6.3
hooks:
- id: schemalint-verify
pass_filenames: false
args:
- helm/agent/values.schema.json
# helm-docs finds every chart below helm/, the vendored subcharts under
# helm/<chart>/charts/ included; --chart-to-generate limits the README it
# writes to the repo's own charts, so the vendored subtree stays untouched
# like it does for the base hooks above.
- repo: https://github.com/norwoodj/helm-docs
rev: "v1.14.2"
hooks:
- id: helm-docs
# The upstream script hook uses helm-docs from PATH. Build this rev
# in pre-commit's isolated Go environment so local and CI runs agree.
language: golang
entry: helm-docs
args:
- --chart-search-root=helm
- --chart-to-generate=helm/agent
- --sort-values-order=file