Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/verify_header.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

#
# Copyright(c) 2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#

# COPYRIGHT_REGEX is lowercase, because the whole line is
# converted to lowercase before test against this regex.
COPYRIGHT_REGEX="(copyright|\(c\))\s*([0-9]{4}(\s*-\s*([0-9]{4}))?)"
LICENSE_REGEX="SPDX-License-Identifier: BSD-3-Clause$"
YEAR=$(date +"%Y")

unset copyright_header license_header

# Read lines until proper copyright and license headers are found.
while read -r line && [[ ! "$copyright_header" || ! "$license_header" ]]; do
if [[ "${line,,}" =~ $COPYRIGHT_REGEX ]]; then
# If the fourth regex group (from year range) doesn't exist,
# use the second regex group instead (from a single year).
copyright_year=${BASH_REMATCH[4]:-${BASH_REMATCH[2]}}

if [[ $copyright_year == $YEAR ]]; then
copyright_header="correct_copyright_header_found"
fi
elif [[ "$line" =~ $LICENSE_REGEX ]]; then
license_header="correct_license_header_found"
fi
done < "$1"

# Proper copyright and license info were found - all good.
[[ "$copyright_header" && "$license_header" ]] && exit 0

[[ ! "$copyright_header" ]] && echo >&2 "error: file '$1' does not contain any appropriate copyright info"
[[ ! "$license_header" ]] && echo >&2 "error: file '$1' does not contain appropriate license identifier"
exit 1
43 changes: 43 additions & 0 deletions .github/workflows/license-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Licence-date-verification
permissions:
contents: read
pull-requests: read
on:
pull_request:
branches:
- master
- v*

env:
EXTENSIONS: "c h cpp py go sh mk spec service"
FILES: "configure configure.d/* *Makefile utils/casctl tools/pckgen.d/deb/debian/rules"
jobs:
verify-date:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/[email protected]
with:
files_ignore: '.github/**'
- name: List all changed files
run: |
files_to_check=(${{ steps.changed-files.outputs.added_files }})
files_to_check+=(${{ steps.changed-files.outputs.modified_files }})

for file in ${files_to_check[@]}; do
for file_in_list in $FILES; do
if [[ "$file" == $file_in_list ]]; then
.github/verify_header.sh "$file"
continue 2
fi
done

extension=${file##*.}
if [[ "$EXTENSIONS" =~ $extension ]]; then
.github/verify_header.sh "$file"
fi
done
Loading