Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
93 changes: 93 additions & 0 deletions bin/check-package-years.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script ensures that all the headers in any given folder under packages
# all have the same Copyright year in their header.

# Get the directory where the script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Assume packages is a sibling of the bin directory where this script lives
# or in the current directory if run from root.
if [ -d "$SCRIPT_DIR/../packages" ]; then
PACKAGES_DIR="$SCRIPT_DIR/../packages"
elif [ -d "$SCRIPT_DIR/packages" ]; then
PACKAGES_DIR="$SCRIPT_DIR/packages"
else
echo "Error: Could not find 'packages' directory."
exit 1
fi

EXIT_CODE=0

# Iterate through each package folder
# Using find -print0 and read -d '' is the most robust way to handle any filename
while IFS= read -r -d '' pkg_path; do
pkg=$(basename "$pkg_path")
echo "Scanning package $pkg..."

first_year=""
first_file=""

# Find all files that are likely to have copyright headers
# This addresses the request to ensure all files in the folder have a copyright year.
# We focus on source files and configuration files that should have headers.
while IFS= read -r -d '' 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. awk will exit with 0 even if no input is found.
year=$(grep -iohE "Copyright [0-9]{4}" "$file" | head -n 1 | awk '{print $2}')

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 < <(find "$pkg_path" -type f \
\( -name "*.ts" -o -name "*.js" -o -name "*.cjs" -o -name "*.mjs" \) \
-not -path "*/node_modules/*" \
-not -path "*/.git/*" \
-not -path "*/.coverage/*" \
-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" \
-print0)
done < <(find "$PACKAGES_DIR" -maxdepth 1 -mindepth 1 -type d -print0 | sort -z)

if [ $EXIT_CODE -eq 0 ]; then
echo "Success: All package copyright years match."
else
echo "Failure: Some packages have mismatched or missing copyright years."
fi

exit $EXIT_CODE
68 changes: 68 additions & 0 deletions bin/fix-header-years.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script updates all copyright headers in the packages/ directory to 2026.
# It excludes .proto files and common ignored directories.

PACKAGES_DIR="packages"

if [ ! -d "$PACKAGES_DIR" ]; then
echo "Error: Could not find 'packages' directory."
exit 1
fi

echo "Updating copyright headers in $PACKAGES_DIR to 2026..."

# Regex pattern to match "Copyright", optional "(c)", and any year or range of years.
# Examples:
# Copyright 2020
# Copyright (c) 2018
# Copyright 2018-2022
# Copyright 2018, 2019
# We want to capture the space/punctuation after Copyright to preserve it.
# Note: Using [[:space:][:punct:]] might be too broad, let's stick to the plan's recommendation or similar.
# The plan suggested: Copyright([ (cC)]+)[0-9]{4}([- ,]+[0-9]{4})*

FIND_CMD=(
find "$PACKAGES_DIR" -type f
-not -path "*/node_modules/*"
-not -path "*/.git/*"
-not -path "*/.coverage/*"
-not -path "*/dist/*"
-not -path "*/build/*"
-not -name "*.proto"
-not -name "LICENSE"
-not -name "CHANGELOG.md"
-not -name "package.json"
-not -name "package-lock.json"
-not -name "pnpm-lock.yaml"
)

# Use perl for more robust regex across different platforms if needed,
# but sed -E should work for GNU sed.
# The pattern should be applied to any line containing "Copyright".

while IFS= read -r -d '' file; do
# Check if file contains "Copyright" before attempting to edit
if grep -q "Copyright" "$file"; then
# We use perl for more advanced regex support (like non-greedy matching or easier capturing)
# The pattern matches "Copyright", then any sequence of spaces, (c), (C),
# then a 4-digit year, potentially followed by ranges or lists of years.
perl -pi -e 's/(Copyright[ (cC)]+)\d{4}(?:[- ,]+\d{4})*/${1}2026/gi' "$file"
fi
done < <("${FIND_CMD[@]}" -print0)

echo "Header update complete."
64 changes: 64 additions & 0 deletions bin/verify-header-years.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script verifies that all copyright headers in the packages/ directory are set to 2026.
# It excludes .proto files and common ignored directories.

PACKAGES_DIR="packages"

if [ ! -d "$PACKAGES_DIR" ]; then
echo "Error: Could not find 'packages' directory."
exit 1
fi

echo "Verifying copyright headers in $PACKAGES_DIR are 2026..."

EXIT_CODE=0

FIND_CMD=(
find "$PACKAGES_DIR" -type f
-not -path "*/node_modules/*"
-not -path "*/.git/*"
-not -path "*/.coverage/*"
-not -path "*/dist/*"
-not -path "*/build/*"
-not -name "*.proto"
-not -name "LICENSE"
-not -name "CHANGELOG.md"
-not -name "package.json"
-not -name "package-lock.json"
-not -name "pnpm-lock.yaml"
)

while IFS= read -r -d '' file; do
# Find lines with "Copyright [Year]" where [Year] is NOT 2026
# This avoids false positives from the Apache License text which uses "copyright" as a noun.
mismatches=$(grep -iohE "Copyright [0-9]{4}" "$file" | grep -v "2026")

if [ -n "$mismatches" ]; then
echo "Error: Non-2026 copyright year found in $file:"
echo "$mismatches"
EXIT_CODE=1
fi
done < <("${FIND_CMD[@]}" -print0)

if [ $EXIT_CODE -eq 0 ]; then
echo "Success: All copyright headers are 2026."
else
echo "Failure: Some files have incorrect copyright years."
fi

exit $EXIT_CODE
2 changes: 1 addition & 1 deletion packages/gapic-node-processing/.mocharc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/gapic-node-processing/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exports['tests for templates it should create the templates in the directory 1'] = `
# Copyright 2022 Google LLC
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/gapic-node-processing/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/gapic-node-processing/src/combine-libraries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/gapic-node-processing/src/generate-index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/gapic-node-processing/src/generate-readme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/gapic-node-processing/src/library.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/gapic-node-processing/src/templating.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Google LLC
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,7 +40,7 @@ module.exports = {
includePattern: '\\.js$'
},
templates: {
copyright: 'Copyright 2025 Google LLC',
copyright: 'Copyright 2026 Google LLC',
includeDate: false,
sourceFiles: false,
systemName: '@google-cloud/data',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Loading
Loading