jason810496 commented on code in PR #71869:
URL: https://github.com/apache/airflow/pull/71869#discussion_r3868370857
##########
.pre-commit-config.yaml:
##########
@@ -280,6 +280,25 @@ repos:
(?x)
^java-sdk/gradle\.properties$|
^java-sdk/sdk/schema/schema\.json$
+ - id: regenerate-java-sdk-verification-metadata
+ name: Regenerate the Java SDK dependency verification metadata
+ description: "Drop trusted checksums that no Java SDK build task
resolves any more"
+ entry: ./java-sdk/scripts/ci/regenerate-verification-metadata.sh
+ language: system
+ pass_filenames: false
+ # example/ and scala_spark_example/ are separate builds this metadata
does
+ # not cover, so their build files are excluded.
+ files: >
+ (?x)
+ ^java-sdk/build\.gradle\.kts$|
+ ^java-sdk/buildSrc/.*$|
+ ^java-sdk/gradle\.properties$|
+ ^java-sdk/gradle/libs\.versions\.toml$|
+ ^java-sdk/gradle/verification-metadata\.xml$|
+ ^java-sdk/gradle/wrapper/gradle-wrapper\.properties$|
+ ^java-sdk/scripts/ci/regenerate-verification-metadata\.sh$|
+ ^java-sdk/settings\.gradle\.kts$|
+ ^java-sdk/(?!example/|scala_spark_example/)[^/]+/build\.gradle\.kts$
Review Comment:
We need to trigger regeneration for dependencymodule properties too.
```suggestion
^java-sdk/(?!example/|scala_spark_example/)[^/]+/(?:build\.gradle\.kts|gradle\.properties)$
```
##########
java-sdk/scripts/ci/regenerate-verification-metadata.sh:
##########
@@ -0,0 +1,110 @@
+#!/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.
+
+# Rewrite java-sdk/gradle/verification-metadata.xml from an empty component
+# list. Gradle only ever appends to that file, so a version bump leaves the
+# superseded entries behind and they stay trusted forever; starting from an
+# empty list drops them.
+
+set -euo pipefail
+
+JAVA_SDK_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
+METADATA_FILE="$JAVA_SDK_ROOT/gradle/verification-metadata.xml"
+
+# Only what these tasks resolve gets recorded, so the list has to cover
+# everything CI builds — anything missing here fails strict verification later.
+GRADLE_TASKS=(
+ build
+ :sdk:dokkaGeneratePublicationHtml
+ :sdk:dokkaGeneratePublicationJavadoc
+ sourceTarball
+ checksumSourceTarball
+ publishToMavenLocal
+)
+
+# One shot at Maven Central and the Gradle Plugin Portal makes this a flaky
+# check rather than a useful one.
+MAX_ATTEMPTS=3
+RETRY_DELAY_SECONDS=30
+
+committed="$(mktemp)"
+cp "$METADATA_FILE" "$committed"
+
+# Gradle rewrites the whole file and drops the ASF header the insert-license
+# hook requires, so carry the committed one over.
+license_header="$(awk 'NR > 1 { if ($0 ~ /^<verification-metadata/) exit;
print }' "$committed")"
+
+cleanup() {
+ local status=$?
+ if [ "$status" -ne 0 ]; then
+ cp "$committed" "$METADATA_FILE"
+ fi
+ rm -f "$committed"
+}
+trap cleanup EXIT
+
+write_empty_metadata() {
+ awk '
+ /<components>/ { print " <components/>"; print
"</verification-metadata>"; exit }
+ { print }
+ ' "$committed" > "$METADATA_FILE"
+}
+
+restore_license_header() {
+ grep -q "Licensed to the Apache Software Foundation" "$METADATA_FILE" &&
return 0
+ awk -v header="$license_header" '
+ NR == 1 { print; if (header != "") print header; next }
+ { print }
+ ' "$METADATA_FILE" > "$METADATA_FILE.tmp"
+ mv "$METADATA_FILE.tmp" "$METADATA_FILE"
Review Comment:
Would it be more robust to define the header within the script and add it
back? IIRC, most of this static check script follows this common pattern.
```suggestion
# Gradle rewrites the whole file and drops the ASF header the insert-license
# hook requires, so define the canonical XML header here.
readonly LICENSE_HEADER='<!--
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.
-->'
cleanup() {
local status=$?
if [ "$status" -ne 0 ]; then
cp "$committed" "$METADATA_FILE"
fi
rm -f "$committed"
}
trap cleanup EXIT
write_empty_metadata() {
awk '
/<components>/ { print " <components/>"; print
"</verification-metadata>"; exit }
{ print }
' "$committed" > "$METADATA_FILE"
}
restore_license_header() {
grep -q "Licensed to the Apache Software Foundation" "$METADATA_FILE" &&
return 0
{
head -n 1 "$METADATA_FILE"
printf '%s\n' "$LICENSE_HEADER"
tail -n +2 "$METADATA_FILE"
} > "$METADATA_FILE.tmp"
mv "$METADATA_FILE.tmp" "$METADATA_FILE"
}
```
##########
java-sdk/scripts/ci/regenerate-verification-metadata.sh:
##########
@@ -0,0 +1,110 @@
+#!/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.
+
+# Rewrite java-sdk/gradle/verification-metadata.xml from an empty component
+# list. Gradle only ever appends to that file, so a version bump leaves the
+# superseded entries behind and they stay trusted forever; starting from an
+# empty list drops them.
+
+set -euo pipefail
+
+JAVA_SDK_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
+METADATA_FILE="$JAVA_SDK_ROOT/gradle/verification-metadata.xml"
+
+# Only what these tasks resolve gets recorded, so the list has to cover
+# everything CI builds — anything missing here fails strict verification later.
+GRADLE_TASKS=(
+ build
+ :sdk:dokkaGeneratePublicationHtml
+ :sdk:dokkaGeneratePublicationJavadoc
+ sourceTarball
+ checksumSourceTarball
+ publishToMavenLocal
+)
+
+# One shot at Maven Central and the Gradle Plugin Portal makes this a flaky
+# check rather than a useful one.
+MAX_ATTEMPTS=3
+RETRY_DELAY_SECONDS=30
+
+committed="$(mktemp)"
+cp "$METADATA_FILE" "$committed"
+
+# Gradle rewrites the whole file and drops the ASF header the insert-license
+# hook requires, so carry the committed one over.
+license_header="$(awk 'NR > 1 { if ($0 ~ /^<verification-metadata/) exit;
print }' "$committed")"
+
+cleanup() {
+ local status=$?
+ if [ "$status" -ne 0 ]; then
+ cp "$committed" "$METADATA_FILE"
+ fi
+ rm -f "$committed"
+}
+trap cleanup EXIT
+
+write_empty_metadata() {
Review Comment:
Would it better to add the tests covering successful rewrite/license
preservation, retries, and final-failure restoration.
--
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]