Merge pull request #9 from nupplaphil/feat/license_check

Add license check
This commit is contained in:
Hypolite Petovan 2022-07-03 19:22:53 -04:00 committed by GitHub
commit 08ae380ed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -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

28
php-cs/check-license.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/bash
#
# Checks if the license header is correct
#
[[ -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
printf "\n"
for file in "${files[@]}"; do
if [ ! -f "$file" ] || [[ "$file" == *strings.php ]]; 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
[[ $exitVal != 0 ]] && echo "License headers are missing or wrong"
exit $exitVal