suyanhanx commented on code in PR #9336:
URL: https://github.com/apache/opendal/pull/9336#discussion_r4726492411


##########
scripts/compose_atr.py:
##########
@@ -0,0 +1,187 @@
+# 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.
+
+"""Stage one complete signed candidate and bind its ATR revision to the Git 
RC."""
+
+import argparse
+import hashlib
+import subprocess
+import tempfile
+import time
+from pathlib import Path
+
+from release_lifecycle import (
+    ATR,
+    REPO,
+    Candidate,
+    api,
+    atr_jwt,
+    atr_manifest,
+    atr_release,
+    candidates,
+    ref_sha,
+    request_json,
+    selected_revision,
+)
+
+
+def signed_manifest(directory, version):
+    files = {}
+    for path in directory.iterdir():
+        if path.is_symlink() or not path.is_file():
+            raise ValueError(f"Unexpected entry in the signed bundle: 
{path.name}")
+        with path.open("rb") as stream:
+            files[path.name] = (
+                "sha3-256:" + hashlib.file_digest(stream, 
"sha3_256").hexdigest()
+            )
+    archives = {name for name in files if name.endswith("-src.tar.gz")}
+    if f"apache-opendal-core-{version}-src.tar.gz" not in archives or 
set(files) != {
+        name + suffix for name in archives for suffix in ("", ".asc", 
".sha512")
+    }:
+        raise ValueError(
+            "Expected signed source archives with both .asc and .sha512 
sidecars"
+        )
+    return files
+
+
+def upload(candidate, directory):
+    with tempfile.TemporaryDirectory(prefix="od-atr-", dir="/tmp") as 
temporary:
+        key = Path(temporary) / "key"
+        subprocess.run(
+            ["ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-f", key], 
check=True
+        )
+        request_json(
+            f"{ATR}/api/publisher/ssh/register",
+            {
+                "publisher": "github",
+                "jwt": atr_jwt(),
+                "ssh_key": key.with_suffix(".pub").read_text().strip(),
+                "source_commit": candidate.sha,
+            },
+        )
+        subprocess.run(
+            [
+                "rsync",
+                "-av",
+                "--delete",
+                "-e",
+                f"ssh -p 2222 -i {key} -o BatchMode=yes -o IdentitiesOnly=yes 
-o StrictHostKeyChecking=accept-new",
+                "--",
+                f"{directory}/",
+                f"[email protected]:/opendal/{candidate.version}/",
+            ],
+            check=True,
+        )
+
+
+def accepted_revision(candidate, files, previous):
+    # ATR may finish archive validation after rsync exits. The old revision 
stays visible meanwhile.
+    deadline = time.monotonic() + 20 * 60
+    while time.monotonic() < deadline:
+        release = atr_release(candidate.version, optional=True)
+        if release is not None:
+            if release["phase"] != "release_candidate_draft":
+                raise ValueError(f"ATR {candidate.version} has left the 
compose phase")
+            number = release.get("latest_revision_number")
+            if (
+                number
+                and number != previous
+                and release.get("commit_hash") == candidate.sha
+            ):
+                revision = selected_revision(release)
+                remote = atr_manifest(candidate.version, revision)
+                if remote == files:
+                    return revision
+                mismatches = sorted(
+                    name
+                    for name in files.keys() | remote
+                    if files.get(name) != remote.get(name)
+                )
+                raise ValueError(
+                    f"ATR revision {revision} differs from the signed bundle: 
{mismatches}"
+                )
+        time.sleep(10)
+    raise TimeoutError(
+        f"ATR has not accepted the signed bundle for {candidate.rc} at 
{candidate.sha}"
+    )
+
+
+def compose(candidate, directory):
+    if ref_sha("tags", f"v{candidate.rc}") != candidate.sha:
+        raise ValueError(f"Git tag v{candidate.rc} does not identify 
{candidate.sha}")
+    files = signed_manifest(directory, candidate.version)
+    if atr_release(candidate.rc, optional=True) is not None:
+        raise ValueError(
+            f"Finish or withdraw the existing ATR candidate {candidate.rc} 
before preparing a new Git RC"
+        )
+    release = atr_release(candidate.version, optional=True)
+    previous = None
+    revision = None
+    if release is None:
+        if ref_sha("tags", f"v{candidate.version}") is not None:
+            raise ValueError(f"Git already has a final tag for 
{candidate.version}")
+        for rc in candidates():
+            if rc != candidate.rc and 
rc.startswith(f"{candidate.version}-rc."):
+                legacy = atr_release(rc, optional=True)
+                if legacy and legacy["phase"] != "release_candidate_draft":
+                    raise ValueError(
+                        f"Resolve the existing ATR release {rc} before 
starting {candidate.version}"
+                    )
+    else:
+        if release["phase"] != "release_candidate_draft":
+            locked = selected_revision(release)
+            status = candidate.revision_status(locked, files)
+            if (
+                candidate.recorded_revision(status) == status
+                and atr_manifest(candidate.version, locked) == files
+            ):
+                return
+            raise ValueError(
+                f"ATR {candidate.version} is in {release['phase']}; only a 
draft can be replaced"
+            )
+        previous = release.get("latest_revision_number")
+        if (
+            previous
+            and release.get("commit_hash") == candidate.sha
+            and atr_manifest(candidate.version, selected_revision(release)) == 
files
+        ):
+            revision = previous
+    if revision is None:
+        upload(candidate, directory)

Review Comment:
   A rerun of RC1 can overwrite RC2 while RC2 is still a draft. RC1's tag still 
matches its SHA, and the draft's different commit sends RC1 straight to this 
upload. Since rsync uses `--delete`, the shared draft then contains RC1's files 
again, and the workflow records the new revision as a successful compose. Could 
we check which Git RC owns the current draft before replacing it and reject a 
stale rerun?



##########
scripts/compose_atr.py:
##########
@@ -0,0 +1,187 @@
+# 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.
+
+"""Stage one complete signed candidate and bind its ATR revision to the Git 
RC."""
+
+import argparse
+import hashlib
+import subprocess
+import tempfile
+import time
+from pathlib import Path
+
+from release_lifecycle import (
+    ATR,
+    REPO,
+    Candidate,
+    api,
+    atr_jwt,
+    atr_manifest,
+    atr_release,
+    candidates,
+    ref_sha,
+    request_json,
+    selected_revision,
+)
+
+
+def signed_manifest(directory, version):
+    files = {}
+    for path in directory.iterdir():
+        if path.is_symlink() or not path.is_file():
+            raise ValueError(f"Unexpected entry in the signed bundle: 
{path.name}")
+        with path.open("rb") as stream:
+            files[path.name] = (
+                "sha3-256:" + hashlib.file_digest(stream, 
"sha3_256").hexdigest()
+            )
+    archives = {name for name in files if name.endswith("-src.tar.gz")}
+    if f"apache-opendal-core-{version}-src.tar.gz" not in archives or 
set(files) != {
+        name + suffix for name in archives for suffix in ("", ".asc", 
".sha512")
+    }:
+        raise ValueError(
+            "Expected signed source archives with both .asc and .sha512 
sidecars"
+        )
+    return files
+
+
+def upload(candidate, directory):
+    with tempfile.TemporaryDirectory(prefix="od-atr-", dir="/tmp") as 
temporary:
+        key = Path(temporary) / "key"
+        subprocess.run(
+            ["ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-f", key], 
check=True
+        )
+        request_json(
+            f"{ATR}/api/publisher/ssh/register",
+            {
+                "publisher": "github",
+                "jwt": atr_jwt(),
+                "ssh_key": key.with_suffix(".pub").read_text().strip(),
+                "source_commit": candidate.sha,
+            },
+        )
+        subprocess.run(
+            [
+                "rsync",
+                "-av",
+                "--delete",
+                "-e",
+                f"ssh -p 2222 -i {key} -o BatchMode=yes -o IdentitiesOnly=yes 
-o StrictHostKeyChecking=accept-new",
+                "--",
+                f"{directory}/",
+                f"[email protected]:/opendal/{candidate.version}/",
+            ],
+            check=True,
+        )
+
+
+def accepted_revision(candidate, files, previous):
+    # ATR may finish archive validation after rsync exits. The old revision 
stays visible meanwhile.
+    deadline = time.monotonic() + 20 * 60
+    while time.monotonic() < deadline:
+        release = atr_release(candidate.version, optional=True)
+        if release is not None:
+            if release["phase"] != "release_candidate_draft":
+                raise ValueError(f"ATR {candidate.version} has left the 
compose phase")
+            number = release.get("latest_revision_number")
+            if (
+                number
+                and number != previous
+                and release.get("commit_hash") == candidate.sha
+            ):
+                revision = selected_revision(release)
+                remote = atr_manifest(candidate.version, revision)
+                if remote == files:
+                    return revision
+                mismatches = sorted(
+                    name
+                    for name in files.keys() | remote
+                    if files.get(name) != remote.get(name)
+                )
+                raise ValueError(
+                    f"ATR revision {revision} differs from the signed bundle: 
{mismatches}"
+                )
+        time.sleep(10)
+    raise TimeoutError(
+        f"ATR has not accepted the signed bundle for {candidate.rc} at 
{candidate.sha}"
+    )
+
+
+def compose(candidate, directory):
+    if ref_sha("tags", f"v{candidate.rc}") != candidate.sha:
+        raise ValueError(f"Git tag v{candidate.rc} does not identify 
{candidate.sha}")
+    files = signed_manifest(directory, candidate.version)
+    if atr_release(candidate.rc, optional=True) is not None:
+        raise ValueError(
+            f"Finish or withdraw the existing ATR candidate {candidate.rc} 
before preparing a new Git RC"
+        )
+    release = atr_release(candidate.version, optional=True)
+    previous = None
+    revision = None
+    if release is None:
+        if ref_sha("tags", f"v{candidate.version}") is not None:
+            raise ValueError(f"Git already has a final tag for 
{candidate.version}")
+        for rc in candidates():
+            if rc != candidate.rc and 
rc.startswith(f"{candidate.version}-rc."):
+                legacy = atr_release(rc, optional=True)
+                if legacy and legacy["phase"] != "release_candidate_draft":
+                    raise ValueError(
+                        f"Resolve the existing ATR release {rc} before 
starting {candidate.version}"
+                    )
+    else:
+        if release["phase"] != "release_candidate_draft":
+            locked = selected_revision(release)
+            status = candidate.revision_status(locked, files)
+            if (
+                candidate.recorded_revision(status) == status

Review Comment:
   If ATR accepts the upload but the GitHub status write fails, an RM can start 
voting before the job is retried. A retry with the original signed artifact 
then fails here because the status it needs to write is missing. Even a passing 
vote gets stuck because publication requires that status too. Could the retry 
verify the locked revision's source SHA and full manifest against the original 
artifact, then write the missing status without uploading again? A conflicting 
status should still fail.



##########
scripts/release_lifecycle.py:
##########
@@ -310,44 +421,19 @@ def notice(candidate, release, status=None):
 Read-only checks:
 
 ```bash
-atr check status opendal {rc} {revision}
-atr vote tabulate opendal {rc}
-```
-
-After verification, start the vote (do not repeat this if voting is already 
open):
-
-```bash
-uv run --python 3.13 --with "apache-trusted-releases @ 
git+https://github.com/apache/tooling-releases-client"; python - <<'PYTHON'
-from atrclient import api
-from atrclient.models.api import VoteStartArgs
-
-task = api.vote_start(VoteStartArgs(
-    project="opendal",
-    version="{rc}",
-    revision="{revision}",
-    email_to="[email protected]",
-    automatic_resolve_when_finished=True,
-    automatic_publish_when_resolved=True,
-    notify_when_finished=True,
-)).task
-print(task.model_dump_json(indent=2))
-assert task.task_args["automatic_resolve_when_finished"] is True
-assert task.task_args["automatic_publish_when_resolved"] is True
-PYTHON
+atr check status opendal {atr_version} {revision}
+atr vote tabulate opendal {atr_version}
 ```
 
-This uses the official ATR client and the same credentials as `atr`. It checks
-that the returned task enables both automatic resolution and publication. If a
-check fails, inspect that task in ATR; do not repeat the start command. The 
CLI's
-`--auto-publish` option alone does not enable automatic resolution.
+{vote_start_instructions(candidate, atr_version, revision)}
 
 ATR attempts automatic resolution at the scheduled vote end and publishes the
 source archives if the vote passes. Insufficient votes leave the vote open for
 manual follow-up; do not assume later ballots automatically trigger another
 attempt. If manual resolution is needed, review the tally first:
 
 ```bash
-atr vote resolve opendal {rc} passed
+atr vote resolve opendal {atr_version} passed

Review Comment:
   After an RC1 vote is withdrawn and RC2 starts voting, the command in RC1's 
discussion still addresses the shared final version. Running it from that old 
discussion can resolve RC2's ballot. The [ATR 
CLI](https://github.com/apache/tooling-releases-client/blob/a392d6f4f7ea717323035091291b9460c81f0827/src/atrclient/client.py#L1070-L1080)
 passes only project, version and resolution. Could we remove the ready-to-run 
command from these persistent discussions and direct the RM to verify the 
active round and voted revision in ATR before resolving it?



-- 
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]

Reply via email to