Added header verification script

Signed-off-by: Kamil Lepek <kamil.lepek@intel.com>
This commit is contained in:
Kamil Lepek 2022-05-04 13:09:49 +02:00
parent 6274edb5f4
commit 3f532c5cee
2 changed files with 58 additions and 0 deletions

24
.github/verify_header.sh vendored Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
#
# Copyright(c) 2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#
YEAR=$(date +"%Y")
REGEX="Copyright\(c\) [0-9]{4}-([0-9]{4}) |Copyright\(c\) ([0-9]{4}) "
while read -r line; do
if [[ "$line" =~ $REGEX ]]; then
echo ${BASH_REMATCH[0]}
if [[ $YEAR == ${BASH_REMATCH[1]} || $YEAR == ${BASH_REMATCH[2]} ]]; then
echo $1 have appropriate license header
exit 0
fi
echo $1 have wrong license header year
exit 1
fi
done < "$1"
echo $1 does not contain appropriate license header
exit 1

34
.github/workflows/pullrequest.yml vendored Normal file
View File

@ -0,0 +1,34 @@
name: Licence-date-verification
on:
pull_request:
branches:
- master
env:
EXTENSIONS: "c h cpp py go sh"
jobs:
verify-date:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.1.0
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v18.2
with:
files_ignore: '.github/**'
- name: List all changed files
run: |
for FILE in ${{ steps.changed-files.outputs.all_changed_files }}; do
REGEX=".*\.(.*)"
if [[ "$FILE" =~ $REGEX ]]
then
EXTENSION=${BASH_REMATCH[1]}
EXTENSIONS_LIST=($EXTENSIONS)
if [[ " ${EXTENSIONS_LIST[*]} " =~ " ${EXTENSION} " ]]
then
.github/verify_header.sh $FILE
fi
fi
done