From 5ce7f7e62ca46be6023f637f04da5760a184ddd1 Mon Sep 17 00:00:00 2001 From: Milan Malfait Date: Mon, 26 Feb 2024 10:30:12 +0100 Subject: [PATCH] Fix the copyright heading linter (#319) * Fix the copyright heading linter Run only on git-staged files * Check the files we're told to check, and move the file filtering to the pre-commit config. This means different options to pre-commit should work properly. * Remove accidental README additions --------- Co-authored-by: Jeremy Stein --- .pre-commit-config.yaml | 1 + README.md | 2 +- bin/linters/check_headers_exist.sh | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bda55d38f..d01c57a3b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,5 +33,6 @@ repos: - id: copyright-headers name: copyright-headers language: script + types_or: [python, shell, yaml, dockerfile] entry: bin/linters/check_headers_exist.sh diff --git a/README.md b/README.md index 2b4573e9d..a9938270c 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ setfacl -R -m d:g::rwX /gae/pixl_dev ### 1. Choose deployment environment -This is one of dev|test|staging|prod and referred to as `` in the docs. +This is one of `dev|test|staging|prod` and referred to as `` in the docs. ### 2. Initialise environment configuration diff --git a/bin/linters/check_headers_exist.sh b/bin/linters/check_headers_exist.sh index 2542f211f..d7c1e6fa8 100755 --- a/bin/linters/check_headers_exist.sh +++ b/bin/linters/check_headers_exist.sh @@ -12,15 +12,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +set -euo pipefail -for ext in ".yml" ".yaml" ".sh" "Dockerfile" ".py" -do - # shellcheck disable=SC2044 - for path in $(find . -name "*$ext") - do - if ! grep -q "Copyright" "$path"; then - echo -e "\n\e[31m»»» ⚠️ No copyright/license header in $path" - exit 1 - fi - done || exit 1 +for f in "$@"; do + if ! grep -q '#.*Copyright.*University College London Hospitals NHS Foundation Trust' "$f"; then + echo "No copyright notice found in $f" + exit 1 + fi + if ! grep -q '#.*Licensed under the Apache License, Version 2.0' "$f"; then + echo "No licence notice found in $f" + exit 1 + fi done