From 6105ae52a2b640ceb1a7c7cbc974b87e3959bcfc Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 6 Jan 2022 21:51:52 +0100 Subject: [PATCH 1/4] 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 -- 2.43.5 From 5c35459a1876d4c121cca1609e7f5c39a4abb12c Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 7 Jan 2022 00:03:05 +0100 Subject: [PATCH 2/4] Fix license_check --- php-cs/check-license.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/php-cs/check-license.sh b/php-cs/check-license.sh index 7afe405..e381cb4 100755 --- a/php-cs/check-license.sh +++ b/php-cs/check-license.sh @@ -5,13 +5,17 @@ [[ -z "${CHANGED_FILES}" ]] && exit 0 +IFS=' ' read -ra files <<<"${CHANGED_FILES//$'\n'/ }" + 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 +printf "\n" + +for file in "${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 -- 2.43.5 From 29638f2f4011062a9df1600e35b9496491d65c90 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 16 Jan 2022 20:48:11 +0100 Subject: [PATCH 3/4] Fix license-check --- php-cs/check-license.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/php-cs/check-license.sh b/php-cs/check-license.sh index e381cb4..409ec7b 100755 --- a/php-cs/check-license.sh +++ b/php-cs/check-license.sh @@ -16,6 +16,9 @@ exitVal=0 printf "\n" for file in "${files[@]}"; do + if [ ! -f "$file" ]; then + continue + fi php_license_md5=$(head -n "$php_template_rows" "$file" | md5sum) [[ "$php_template_md5" != "$php_license_md5" ]] && printf " - %s\n" "$file" && exitVal=1 done -- 2.43.5 From 367884e91ed4a4f3117ab7f804b513bc642ac153 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 22 Jan 2022 19:32:54 +0100 Subject: [PATCH 4/4] Exclude "strings.php" from license check --- php-cs/check-license.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php-cs/check-license.sh b/php-cs/check-license.sh index 409ec7b..d425e42 100755 --- a/php-cs/check-license.sh +++ b/php-cs/check-license.sh @@ -16,7 +16,7 @@ exitVal=0 printf "\n" for file in "${files[@]}"; do - if [ ! -f "$file" ]; then + if [ ! -f "$file" ] || [[ "$file" == *strings.php ]]; then continue fi php_license_md5=$(head -n "$php_template_rows" "$file" | md5sum) -- 2.43.5