Skip to content

test: Copyright year changes#8095

Open
danieljbruce wants to merge 7 commits intogoogleapis:mainfrom
danieljbruce:copyright-year-changes
Open

test: Copyright year changes#8095
danieljbruce wants to merge 7 commits intogoogleapis:mainfrom
danieljbruce:copyright-year-changes

Conversation

@danieljbruce
Copy link
Copy Markdown
Contributor

experiment

@danieljbruce danieljbruce requested a review from a team as a code owner April 22, 2026 18:03
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a script, bin/check-package-years.sh, to validate and ensure consistency of copyright years across package files, along with updates to various files to reflect the 2026 copyright year. The review identified that the find command in the script was overly restrictive, excluding files that it was intended to check, and suggested using process substitution to improve the robustness of the file processing loop.

Comment on lines +52 to +66
\( -name "*.ts" -o -name "*.js" \) \
-not -path "*/node_modules/*" \
-not -path "*/.git/*" \
-not -path "*/dist/*" \
-not -path "*/build/*" \
-not -name "LICENSE" \
-not -name "CHANGELOG.md" \
-not -name "package.json" \
-not -name "package-lock.json" \
-not -name "pnpm-lock.yaml" \
-not -name "prettier.config.js" \
-not -name ".prettierrc.js" \
-not -name ".eslintrc.js" \
-not -name "webpack.config.js" \
-not -name "rollup.config.js" \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The find command has two issues that cause it to not check all relevant files:

  1. Incomplete file types: It only checks *.ts and *.js files, but this PR also updates copyright headers in .cjs and .yaml files. These should be included for comprehensive checking.
  2. Incorrect exclusions: It excludes several configuration files (e.g., .prettierrc.js, webpack.config.js). However, this PR updates copyrights in those very files, which implies they should be checked. These exclusions should be removed.

To ensure the script correctly validates all intended files, please update the find command.

Suggested change
\( -name "*.ts" -o -name "*.js" \) \
-not -path "*/node_modules/*" \
-not -path "*/.git/*" \
-not -path "*/dist/*" \
-not -path "*/build/*" \
-not -name "LICENSE" \
-not -name "CHANGELOG.md" \
-not -name "package.json" \
-not -name "package-lock.json" \
-not -name "pnpm-lock.yaml" \
-not -name "prettier.config.js" \
-not -name ".prettierrc.js" \
-not -name ".eslintrc.js" \
-not -name "webpack.config.js" \
-not -name "rollup.config.js" \
\( -name "*.ts" -o -name "*.js" -o -name "*.cjs" -o -name "*.yaml" \) \
-not -path "*/node_modules/*" \
-not -path "*/.git/*" \
-not -path "*/dist/*" \
-not -path "*/build/*" \
-not -name "LICENSE" \
-not -name "CHANGELOG.md" \
-not -name "package.json" \
-not -name "package-lock.json" \
-not -name "pnpm-lock.yaml"

Comment on lines +50 to +95
tmp_file=$(mktemp)
find "$pkg_path" -type f \
\( -name "*.ts" -o -name "*.js" \) \
-not -path "*/node_modules/*" \
-not -path "*/.git/*" \
-not -path "*/dist/*" \
-not -path "*/build/*" \
-not -name "LICENSE" \
-not -name "CHANGELOG.md" \
-not -name "package.json" \
-not -name "package-lock.json" \
-not -name "pnpm-lock.yaml" \
-not -name "prettier.config.js" \
-not -name ".prettierrc.js" \
-not -name ".eslintrc.js" \
-not -name "webpack.config.js" \
-not -name "rollup.config.js" \
> "$tmp_file"

while IFS= read -r file; do
if [ -z "$file" ]; then continue; fi

# Extract the year from the first copyright line found in the file
# We use grep -i to be case-insensitive and || true to be robust
year=$(grep -iohE "Copyright [0-9]{4}" "$file" | head -n 1 | awk '{print $2}' || true)

if [ -z "$year" ]; then
# If the file is missing a copyright year, report it
# Note: We only report this if it's a file type we expect to have it
echo "Error: Missing copyright year in file: $file"
EXIT_CODE=1
continue
fi

if [ -z "$first_year" ]; then
first_year="$year"
first_file="$file"
elif [ "$year" != "$first_year" ]; then
echo "Error: Copyright year mismatch in package: $pkg"
echo " $first_file: $first_year"
echo " $file: $year"
EXIT_CODE=1
# We don't break here to allow finding all issues in this package
fi
done < "$tmp_file"
rm "$tmp_file"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The use of a temporary file can be avoided here. Using process substitution (< <(...)) is a cleaner and more robust way to pipe the output of find into the while loop. This avoids creating a file on disk and eliminates the need for manual cleanup with rm (line 95), which might not run if the script is interrupted.

This refactoring would look like:

  # ...
  first_year=""
  first_file=""

  # Find all files and pipe them to the inner loop
  while IFS= read -r file; do
    # ... (inner loop logic)
  done < <(find "$pkg_path" -type f ...)

  # No rm needed
# ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant