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 6 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
10 changes: 5 additions & 5 deletions test/test_mvnw.js
Copy link
Member

Choose a reason for hiding this comment

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

@slry why do we need these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess, my IDE accidentally formatted this file, will revert this one

Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
* SOFTWARE.
*/

const {mvnw} = require('../src/mvnw');
const { mvnw } = require("../src/mvnw");

Check failure on line 25 in test/test_mvnw.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

There should be no space after '{'

Check failure on line 25 in test/test_mvnw.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

There should be no space before '}'

Check failure on line 25 in test/test_mvnw.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

Strings must use singlequote

describe('mvnw', function() {
it('prints Maven own version', function(done) {
const opts = {batch: true};
mvnw(['--version', '--quiet'], null, opts.batch);
describe("mvnw", function() {

Check failure on line 27 in test/test_mvnw.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

Strings must use singlequote
it("prints Maven own version", function(done) {

Check failure on line 28 in test/test_mvnw.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

Strings must use singlequote
const opts = { batch: true };

Check failure on line 29 in test/test_mvnw.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

There should be no space after '{'

Check failure on line 29 in test/test_mvnw.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

There should be no space before '}'
mvnw(["--version", "--quiet"], null, opts.batch);

Check failure on line 30 in test/test_mvnw.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

Strings must use singlequote

Check failure on line 30 in test/test_mvnw.js

View workflow job for this annotation

GitHub Actions / build (macos-latest, 17, 16)

Strings must use singlequote
done();
});
});
Loading