Copilot commented on code in PR #3084:
URL: https://github.com/apache/iceberg-rust/pull/3084#discussion_r3872755830


##########
dev/check_license_notice.sh:
##########
@@ -0,0 +1,159 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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
+#
+#   http://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.
+
+# Every distributed artifact must ship its own LICENSE and NOTICE.
+# Checking the packaged file list, rather than the crate directory,
+# also catches files that exist on disk but are excluded from the published
+# crate.
+
+set -Eeuo pipefail
+
+REQUIRED_FILES=(LICENSE NOTICE)
+
+usage() {
+  cat <<USAGE
+Usage:
+  $0 [-h|--help]
+
+Checks that every publishable crate in the workspace packages a top-level
+LICENSE and NOTICE file, as required for Apache source and binary releases.
+USAGE
+}
+
+require_command() {
+  local command_name="$1"
+  if ! command -v "${command_name}" >/dev/null 2>&1; then
+    echo "This script requires '${command_name}', but it is not installed." >&2
+    return 1
+  fi
+}
+
+report_error() {
+  # GitHub Actions turns `::error::` lines into annotations on the job summary.
+  if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
+    echo "::error::$1"
+  else
+    echo "ERROR: $1" >&2
+  fi
+}
+
+# Return name and manifest path for every crate that would be published in a 
release.
+publishable_crates() {
+  # `publish` is an empty list for `publish = false` crates and null when the
+  # crate may be published to any registry.
+  cargo metadata --no-deps --format-version 1 |
+    jq -r '.packages[] | select(.publish != []) | 
"\(.name)\t\(.manifest_path)"'
+}
+
+# Check file exists, following any symlinks.
+check_file_exists() {
+  local path="$1"
+
+  # `-s` follows symlinks
+  if [ ! -s "${path}" ]; then
+    return 1
+  fi
+}
+
+# Return true if the given path (second arg) is present in the list of paths 
(first arg).
+packages_file_at_root() {
+  local packaged_paths="$1"
+  local file_name="$2"
+
+  local packaged_path
+
+  while IFS= read -r packaged_path; do
+    if [ "${packaged_path}" = "${file_name}" ]; then
+      return 0
+    fi
+  done <<<"${packaged_paths}"
+
+  return 1
+}
+
+# Verify that the necessary files are bundled in the crate.
+# Accepts both crate name and its directory, so that artifacts can be fully 
verified including symlink resolution.
+check_crate() {
+  local crate="$1"
+  local crate_dir="$2"
+
+  local packaged_paths status repo_path
+  status=0
+
+  echo "Checking ${crate}..."
+  packaged_paths="$(cargo package --package "${crate}" --list --locked)"
+
+  for required_file in "${REQUIRED_FILES[@]}"; do
+    # `cargo package --list` reports the entry even when a symlinked target is
+    # missing, so the packaged list and the contents are checked separately.
+    repo_path="${crate_dir}/${required_file}"
+    if ! packages_file_at_root "${packaged_paths}" "${required_file}"; then
+      report_error "${crate} package is missing top-level ${required_file}"
+      status=1
+    elif ! check_file_exists "${repo_path}"; then
+      report_error "${crate} ${required_file} is empty or does not resolve to 
a file: ${repo_path}"
+      status=1
+    fi
+  done
+
+  return "${status}"
+}
+
+# Route CLI args
+while [ "$#" -gt 0 ]; do
+  case "$1" in
+    -h | --help)
+      usage
+      exit 0
+      ;;
+    *)
+      echo "Unknown argument: $1" >&2
+      usage >&2
+      exit 1
+      ;;
+  esac
+done
+
+require_command cargo
+require_command jq
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
+cd "${REPO_ROOT}"
+
+FAILED=0
+
+echo "Checking repository root..."
+for required_file in "${REQUIRED_FILES[@]}"; do
+  if ! check_file_exists "${REPO_ROOT}/${required_file}"; then
+    report_error "Repository root ${required_file} is empty or does not 
resolve to a file: ${REPO_ROOT}/${required_file}"
+    FAILED=1
+  fi
+done
+
+while IFS=$'\t' read -r crate manifest_path; do
+  check_crate "${crate}" "$(dirname "${manifest_path}")" || FAILED=1
+done < <(publishable_crates)
+
+if [ "${FAILED}" -ne 0 ]; then
+  echo "Every publishable crate directory needs a LICENSE and NOTICE resolving 
to the repository root copies." >&2

Review Comment:
   The PR description says LICENSE/NOTICE are verified to be resolvable 
symlinks, and the final error message says they should resolve to the 
repository root copies, but the current implementation only checks that the 
path exists and is non-empty (it doesn’t require a symlink, nor validate that 
it resolves specifically to `${REPO_ROOT}/LICENSE` / `${REPO_ROOT}/NOTICE`). If 
symlinks-to-root is a hard requirement, update the check to (1) require `-L` 
for crate-level LICENSE/NOTICE, and (2) compare the resolved target path 
against the repo-root file (e.g., via `realpath`), failing if it points 
elsewhere.



##########
dev/check_license_notice.sh:
##########
@@ -0,0 +1,159 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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
+#
+#   http://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.
+
+# Every distributed artifact must ship its own LICENSE and NOTICE.
+# Checking the packaged file list, rather than the crate directory,
+# also catches files that exist on disk but are excluded from the published
+# crate.
+
+set -Eeuo pipefail
+
+REQUIRED_FILES=(LICENSE NOTICE)
+
+usage() {
+  cat <<USAGE
+Usage:
+  $0 [-h|--help]
+
+Checks that every publishable crate in the workspace packages a top-level
+LICENSE and NOTICE file, as required for Apache source and binary releases.
+USAGE
+}
+
+require_command() {
+  local command_name="$1"
+  if ! command -v "${command_name}" >/dev/null 2>&1; then
+    echo "This script requires '${command_name}', but it is not installed." >&2
+    return 1
+  fi
+}
+
+report_error() {
+  # GitHub Actions turns `::error::` lines into annotations on the job summary.
+  if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
+    echo "::error::$1"
+  else
+    echo "ERROR: $1" >&2
+  fi
+}
+
+# Return name and manifest path for every crate that would be published in a 
release.
+publishable_crates() {
+  # `publish` is an empty list for `publish = false` crates and null when the
+  # crate may be published to any registry.
+  cargo metadata --no-deps --format-version 1 |
+    jq -r '.packages[] | select(.publish != []) | 
"\(.name)\t\(.manifest_path)"'
+}
+
+# Check file exists, following any symlinks.
+check_file_exists() {
+  local path="$1"
+
+  # `-s` follows symlinks
+  if [ ! -s "${path}" ]; then

Review Comment:
   `test -s` checks that the target’s size is > 0, but it does not ensure the 
path resolves to a regular file; directories can satisfy `-s` on many systems. 
Since the error message indicates this must 'resolve to a file', consider 
checking for a regular file (`-f`) and (if non-empty is intended) additionally 
checking `-s`. If emptiness should not be part of the requirement, use 
`-e`/`-f` instead of `-s` to avoid false negatives.



##########
dev/check_license_notice.sh:
##########
@@ -0,0 +1,159 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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
+#
+#   http://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.
+
+# Every distributed artifact must ship its own LICENSE and NOTICE.
+# Checking the packaged file list, rather than the crate directory,
+# also catches files that exist on disk but are excluded from the published
+# crate.
+
+set -Eeuo pipefail
+
+REQUIRED_FILES=(LICENSE NOTICE)
+
+usage() {
+  cat <<USAGE
+Usage:
+  $0 [-h|--help]
+
+Checks that every publishable crate in the workspace packages a top-level
+LICENSE and NOTICE file, as required for Apache source and binary releases.
+USAGE
+}
+
+require_command() {
+  local command_name="$1"
+  if ! command -v "${command_name}" >/dev/null 2>&1; then
+    echo "This script requires '${command_name}', but it is not installed." >&2
+    return 1
+  fi
+}
+
+report_error() {
+  # GitHub Actions turns `::error::` lines into annotations on the job summary.
+  if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
+    echo "::error::$1"
+  else
+    echo "ERROR: $1" >&2
+  fi
+}
+
+# Return name and manifest path for every crate that would be published in a 
release.
+publishable_crates() {
+  # `publish` is an empty list for `publish = false` crates and null when the
+  # crate may be published to any registry.
+  cargo metadata --no-deps --format-version 1 |
+    jq -r '.packages[] | select(.publish != []) | 
"\(.name)\t\(.manifest_path)"'
+}
+
+# Check file exists, following any symlinks.
+check_file_exists() {
+  local path="$1"
+
+  # `-s` follows symlinks
+  if [ ! -s "${path}" ]; then
+    return 1
+  fi
+}
+
+# Return true if the given path (second arg) is present in the list of paths 
(first arg).
+packages_file_at_root() {
+  local packaged_paths="$1"
+  local file_name="$2"
+
+  local packaged_path
+
+  while IFS= read -r packaged_path; do
+    if [ "${packaged_path}" = "${file_name}" ]; then
+      return 0
+    fi
+  done <<<"${packaged_paths}"
+
+  return 1
+}
+
+# Verify that the necessary files are bundled in the crate.
+# Accepts both crate name and its directory, so that artifacts can be fully 
verified including symlink resolution.
+check_crate() {
+  local crate="$1"
+  local crate_dir="$2"
+
+  local packaged_paths status repo_path
+  status=0
+
+  echo "Checking ${crate}..."
+  packaged_paths="$(cargo package --package "${crate}" --list --locked)"

Review Comment:
   Running `cargo package` for each publishable crate can be relatively 
expensive in CI because it performs packaging work repeatedly. If you only need 
the file list, consider adding `--no-verify` to reduce overhead (verification 
isn’t needed to compute `--list`). Optionally, if this script is expected to be 
run by developers locally, consider whether `--allow-dirty` is appropriate to 
avoid failing on a dirty working tree (keeping CI strict by running in a clean 
checkout).



##########
dev/check_license_notice.sh:
##########
@@ -0,0 +1,159 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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
+#
+#   http://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.
+
+# Every distributed artifact must ship its own LICENSE and NOTICE.
+# Checking the packaged file list, rather than the crate directory,
+# also catches files that exist on disk but are excluded from the published
+# crate.
+
+set -Eeuo pipefail
+
+REQUIRED_FILES=(LICENSE NOTICE)
+
+usage() {
+  cat <<USAGE
+Usage:
+  $0 [-h|--help]
+
+Checks that every publishable crate in the workspace packages a top-level
+LICENSE and NOTICE file, as required for Apache source and binary releases.
+USAGE
+}
+
+require_command() {
+  local command_name="$1"
+  if ! command -v "${command_name}" >/dev/null 2>&1; then
+    echo "This script requires '${command_name}', but it is not installed." >&2
+    return 1
+  fi
+}
+
+report_error() {
+  # GitHub Actions turns `::error::` lines into annotations on the job summary.
+  if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
+    echo "::error::$1"
+  else
+    echo "ERROR: $1" >&2
+  fi
+}
+
+# Return name and manifest path for every crate that would be published in a 
release.
+publishable_crates() {
+  # `publish` is an empty list for `publish = false` crates and null when the
+  # crate may be published to any registry.
+  cargo metadata --no-deps --format-version 1 |
+    jq -r '.packages[] | select(.publish != []) | 
"\(.name)\t\(.manifest_path)"'
+}
+
+# Check file exists, following any symlinks.
+check_file_exists() {
+  local path="$1"
+
+  # `-s` follows symlinks
+  if [ ! -s "${path}" ]; then
+    return 1
+  fi
+}

Review Comment:
   The PR description says LICENSE/NOTICE are verified to be resolvable 
symlinks, and the final error message says they should resolve to the 
repository root copies, but the current implementation only checks that the 
path exists and is non-empty (it doesn’t require a symlink, nor validate that 
it resolves specifically to `${REPO_ROOT}/LICENSE` / `${REPO_ROOT}/NOTICE`). If 
symlinks-to-root is a hard requirement, update the check to (1) require `-L` 
for crate-level LICENSE/NOTICE, and (2) compare the resolved target path 
against the repo-root file (e.g., via `realpath`), failing if it points 
elsewhere.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to