Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#275: Update copyright year and GHA to check year #282

Merged
merged 18 commits into from
Jun 13, 2024
Merged
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
94 changes: 94 additions & 0 deletions .github/workflows/copyright_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# The MIT License (MIT)
#
# Copyright (c) 2022-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---

name: copyright
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
copyright:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Run check
shell: bash
run: |
# Get the current year
current_year=$(date +"%Y")

# Ignore files and directories
ignore_files=("*/.git/*" "*/.github/workflows/copyright_check.yml"
"*/node_modules/*" "*/build/*" "*/dist/*" "*/temp/*")

# Directory to search
search_dir="."

# Pattern to look for: 'Copyright (c)'
pattern="Copyright (c)"

exit_code=0

# Find files containing the copyright notice
echo "Checking files in $search_dir for outdated copyright years..."
echo "Current year is $current_year."

# Iterate over files, redirecting into while loop to avoid subshell
find $search_dir -type f -print0 > tmp.$$ || exit 1
while IFS= read -r -d $'\0' file; do
# Skip files in the ignore list
skip_file=false
for ignore_pattern in "${ignore_files[@]}"; do
if echo "$file" | grep -qE "$ignore_pattern"; then
skip_file=true
break
fi
done
if $skip_file; then
continue
fi

# Use grep to find the line and awk to extract the year
# If grep fails
if year_line=$(grep "$pattern" "$file"); then
if [[ -n "$year_line" ]]; then
# Extract year assuming the year is after 'Copyright (c)'
year=$(echo "$year_line" | grep -E -oh "[0-9]{4}-[0-9]{4}")
year=$(echo "$year" | awk -F'-' '{print $2}')

# Check if extracted year is not equal to the current year
if [[ "$year" -ne "$current_year" ]]; then
echo "Outdated copyright year ($year) in file: $file"
exit_code=1
fi
fi
fi
done < tmp.$$
rm tmp.$$ # Clean up temporary file

echo "Check complete."
exit $exit_code
Loading