From 6105ae52a2b640ceb1a7c7cbc974b87e3959bcfc Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 6 Jan 2022 21:51:52 +0100 Subject: [PATCH] Add license check --- php-cs/Dockerfile | 3 ++- php-cs/check-license.sh | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 php-cs/check-license.sh diff --git a/php-cs/Dockerfile b/php-cs/Dockerfile index ef9bdcd..5732020 100644 --- a/php-cs/Dockerfile +++ b/php-cs/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.2 +FROM php:7.4 RUN apt-get update -q && \ DEBIAN_FRONTEND=noninteractive apt-get install -q -y \ @@ -7,3 +7,4 @@ RUN apt-get update -q && \ && rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* COPY check-php-cs.sh /check-php-cs.sh +COPY check-license.sh /check-license.sh diff --git a/php-cs/check-license.sh b/php-cs/check-license.sh new file mode 100755 index 0000000..7afe405 --- /dev/null +++ b/php-cs/check-license.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Checks if the license header is correct +# + +[[ -z "${CHANGED_FILES}" ]] && exit 0 + +current_year=$(date +"%Y") +php_template_md5=$(sed "s/%%YEAR%%/$current_year/g" "mods/license/license_php.template" | md5sum) +php_template_rows=$(wc -l "mods/license/license_php.template" | cut -d" " -f1) + +exitVal=0 + +for file in "${CHANGED_FILES[@]}"; do + php_license_md5=$(head -n "$php_template_rows" "$file" | md5sum) + [[ "$php_template_md5" != "$php_license_md5" ]] && printf " - %s\n" "$file" && exitVal=1 +done + +[[ $exitVal != 0 ]] && echo "License headers are missing or wrong" + +exit $exitVal