Skip to content

Commit

Permalink
Fix the copyright heading linter (#319)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
milanmlft and jeremyestein authored Feb 26, 2024
1 parent 027f794 commit 5ce7f7e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<environment>` in the docs.
This is one of `dev|test|staging|prod` and referred to as `<environment>` in the docs.

### 2. Initialise environment configuration

Expand Down
20 changes: 10 additions & 10 deletions bin/linters/check_headers_exist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5ce7f7e

Please sign in to comment.