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
Show file tree
Hide file tree
Changes from 14 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
66 changes: 66 additions & 0 deletions .github/workflows/copyright_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---

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
run: |
bash - << 'SCRIPT'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slry I can't understand, why do you need to run Bash script through this SCRIPT file? can't you just directly use the text?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yegor256 this script just do not work in yaml for some reason, so this is a workaround I found

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slry it's a weird workaround. I suggest you try to make it work as all other scripts.


# Get the current year
current_year=$(date +"%Y")

# Ignore files and directories
ignore_files="(.git|node_modules|build|dist|temp|check_copyright.sh)"

# 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
if [[ "$file" =~ $ignore_files ]]; then
continue
fi

# Use grep to find the line and awk to extract the year
year_line=$(grep "$pattern" "$file")

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 the 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
done < tmp.$$
rm tmp.$$ # Clean up temporary file

echo "Check complete."
exit $exit_code
SCRIPT
17 changes: 16 additions & 1 deletion .github/workflows/itest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
java: [11, 18]
node: [12, 16]
node: [14, 16]
exclude:
- os: macos-latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slry even Node 14 is not supported on MacOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon I have tested it, unfortunately its not...

node: 14
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -56,3 +59,15 @@ jobs:
node ../src/eoc.js clean
node ../src/eoc.js "--parser=$p" "--home-tag=$t" --batch \
test
if: ${{ matrix.os != 'windows-latest' }}
- run: |
cd itest
node ../src/eoc.js "--parser=0.36.0" "--home-tag=0.36.0" --batch `
dataize program
node ../src/eoc.js "--parser=0.36.0" "--home-tag=0.36.0" --alone `
--batch dataize program
node ../src/eoc.js clean
node ../src/eoc.js "--parser=0.36.0" "--home-tag=0.36.0" --batch `
test
shell: pwsh
if: ${{ matrix.os == 'windows-latest' }}