Skip to content

Commit 61b18d1

Browse files
Merge pull request #43 from NHSDigital/miho6/CCM-5831-template-hooks-update
CCM-5831: Git pre-commit hooks tweaks
2 parents fac6cf9 + 64fc66f commit 61b18d1

File tree

6 files changed

+78
-16
lines changed

6 files changed

+78
-16
lines changed

.tool-versions

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ terraform 1.9.1
44
pre-commit 3.6.0
55
nodejs 18.18.2
66
gitleaks 8.18.4
7+
vale 3.6.0
78
tfsec 1.28.10
89

910
# ==============================================================================
@@ -18,7 +19,7 @@ tfsec 1.28.10
1819
# docker/ghcr.io/nhs-england-tools/github-runner-image 20230909-321fd1e-rt@sha256:ce4fd6035dc450a50d3cbafb4986d60e77cb49a71ab60a053bb1b9518139a646 # SEE: https://github.com/nhs-england-tools/github-runner-image/pkgs/container/github-runner-image
1920
# docker/hadolint/hadolint 2.12.0-alpine@sha256:7dba9a9f1a0350f6d021fb2f6f88900998a4fb0aaf8e4330aa8c38544f04db42 # SEE: https://hub.docker.com/r/hadolint/hadolint/tags
2021
# docker/hashicorp/terraform 1.5.6@sha256:180a7efa983386a27b43657ed610e9deed9e6c3848d54f9ea9b6cb8a5c8c25f5 # SEE: https://hub.docker.com/r/hashicorp/terraform/tags
21-
# docker/jdkato/vale v2.29.7@sha256:5ccfac574231b006284513ac3e4e9f38833989d83f2a68db149932c09de85149 # SEE: https://hub.docker.com/r/jdkato/vale/tags
22+
# docker/jdkato/vale v3.6.0@sha256:0ef22c8d537f079633cfff69fc46f69a2196072f69cab1ab232e8a79a388e425 # SEE: https://hub.docker.com/r/jdkato/vale/tags
2223
# docker/koalaman/shellcheck latest@sha256:e40388688bae0fcffdddb7e4dea49b900c18933b452add0930654b2dea3e7d5c # SEE: https://hub.docker.com/r/koalaman/shellcheck/tags
2324
# docker/mstruebing/editorconfig-checker 2.7.1@sha256:dd3ca9ea50ef4518efe9be018d669ef9cf937f6bb5cfe2ef84ff2a620b5ddc24 # SEE: https://hub.docker.com/r/mstruebing/editorconfig-checker/tags
2425
# docker/sonarsource/sonar-scanner-cli 5.0.1@sha256:494ecc3b5b1ee1625bd377b3905c4284e4f0cc155cff397805a244dee1c7d575 # SEE: https://hub.docker.com/r/sonarsource/sonar-scanner-cli/tags

scripts/config/gitleaks.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ paths = [
2222
'''yarn.lock''',
2323
'''Gemfile.lock''',
2424
]
25+
26+
# Exclude Chrome version in user agent
27+
regexTarget = "line"
28+
regexes = [
29+
'''Chrome/[\d.]+'''
30+
]

scripts/config/pre-commit.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ repos:
1515
- id: pretty-format-json
1616
args: ['--autofix']
1717
# - id: ...
18+
- repo: local
19+
hooks:
20+
- id: sort-dictionary
21+
name: Sort dictionary
22+
entry: ./scripts/githooks/sort-dictionary.sh
23+
language: script
24+
pass_filenames: false
1825
- repo: local
1926
hooks:
2027
- id: scan-secrets

scripts/config/vale/styles/Vocab/words/accept.txt renamed to scripts/config/vale/styles/config/vocabularies/words/accept.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1+
[A-Z]+s
12
Bitwarden
3+
bot
4+
Cognito
25
Cyber
36
Dependabot
7+
draw.io
8+
drawio
9+
endcapture
10+
endfor
11+
endraw
12+
GitHub
413
Gitleaks
514
Grype
15+
idempotence
16+
Jira
617
OAuth
718
Octokit
19+
onboarding
820
Podman
921
Python
22+
rawContent
23+
sed
1024
Syft
1125
Terraform
12-
Trufflehog
13-
bot
14-
idempotence
15-
onboarding
16-
sed
1726
toolchain
18-
[A-Z]+s
19-
GitHub
20-
endraw
21-
draw.io
22-
endfor
23-
drawio
24-
rawContent
25-
endcapture
26-
Cognito
27-
Jira
27+
Trufflehog

scripts/config/vale/styles/Vocab/words/reject.txt renamed to scripts/config/vale/styles/config/vocabularies/words/reject.txt

File renamed without changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Pre-commit git hook to sort the Vale dictionary in a consistent manner to avoid future merge conflicts and aid insertion of new terms
6+
#
7+
# Usage:
8+
# $ [options] ./sort-dictionary.sh
9+
#
10+
# Options:
11+
#
12+
#
13+
# Exit codes:
14+
# 0 - Successfully sorted the dictionary
15+
# non-zero - failed to sort dictionary
16+
17+
# ==============================================================================
18+
19+
function main() {
20+
root=scripts/config/vale/styles/config/vocabularies/words
21+
opts="--dictionary-order --ignore-case -s"
22+
sort $opts $root/accept.txt > $root/accept.sorted.txt
23+
sort $opts $root/reject.txt > $root/reject.sorted.txt
24+
25+
mv $root/accept.sorted.txt $root/accept.txt
26+
mv $root/reject.sorted.txt $root/reject.txt
27+
28+
git add -uv $root/*
29+
}
30+
31+
# ==============================================================================
32+
33+
function is-arg-true() {
34+
35+
if [[ "$1" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
36+
return 0
37+
else
38+
return 1
39+
fi
40+
}
41+
42+
# ==============================================================================
43+
44+
is-arg-true "${VERBOSE:-false}" && set -x
45+
46+
main "$@"
47+
48+
exit 0

0 commit comments

Comments
 (0)