This is an automated email from the ASF dual-hosted git repository.

hello-stephen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git


The following commit(s) were added to refs/heads/master by this push:
     new 2e5b5f8f08b [infra] Protect the asf-site deployment branch from 
deletion (#4713)
2e5b5f8f08b is described below

commit 2e5b5f8f08bf67c63e678452554555d51c4bb2ff
Author: Mingyu Chen (Rayner) <[email protected]>
AuthorDate: Wed Nov 25 22:55:07 2026 +0800

    [infra] Protect the asf-site deployment branch from deletion (#4713)
    
    ## Summary
    
    Adds a repository ruleset that blocks **deletion** of the `asf-site`
    branch.
    
    `asf-site` currently has no protection (`protected: false`), so any user
    with write access can delete it, taking the published site down until
    the next deploy recreates the branch.
    
    ## Why only the deletion rule
    
    The deploy pushes `asf-site` with `peaceiris/actions-gh-pages` and
    `force_orphan: true`, i.e. a force-push. A `non_fast_forward` rule would
    therefore break publishing, so this ruleset enables `restrict_deletion`
    and explicitly disables `restrict_force_push`.
    
    This is deliberate: the rule prevents branch deletion and does **not**
    block the deploy's force-update.
    
    ## What this protects and what it does not
    
    - **Protects**: `asf-site` cannot be deleted by anyone, including a
    compromised writer token.
    - **Does not protect**: a writer can still push or force-push content to
    `asf-site` and change the published site until the next deploy. Blocking
    that requires excluding the deploy identity from a `non_fast_forward`
    rule.
    
    ## Why not add the force-push rule here
    
    The deploy authenticates with the built-in `GITHUB_TOKEN`, which is the
    platform-native `github-actions` app (ID 15368). GitHub does not allow
    that app as a ruleset bypass actor: the Rulesets API rejects
    `actor_type: Integration` with `actor_id: 15368`, and the app does not
    appear in the UI bypass picker. A `non_fast_forward` rule would
    therefore block the deploy itself.
    
    ## Follow-up for full protection
    
    1. Create a custom GitHub App with `Contents: write`, installed on
    `apache/doris-website` (org owner / Infra).
    2. Store its app ID and private key as secrets.
    3. Change the deploy jobs in `cron-deploy-website.yml` and
    `manual-deploy-website.yml` to mint a token with
    `actions/create-github-app-token` and pass it to
    `peaceiris/actions-gh-pages` instead of `github.token`.
    4. Extend this ruleset with `non_fast_forward` (and optionally `update`)
    and add the app as a bypass actor, using the raw ruleset payload syntax:
    
       ```yaml
       bypass_actors:
         - actor_id: <app-id>
           actor_type: Integration
           bypass_mode: always
       ```
    
    5. A deploy key is an alternative (`actor_type: DeployKey`), simpler but
    adds another long-lived credential.
    
    Until that follow-up, this PR is a safe, non-breaking first step.
    
    ## Validation
    
    - `.asf.yaml` parses as valid YAML; the ruleset uses the asfyaml
    convenience syntax (`type: branch`, `branches.includes`,
    `restrict_deletion`, `restrict_force_push`).
    - `restrict_force_push: false` is explicitly set because the convenience
    syntax defaults it to `true`.
    - After merge, ASF Infra's asfyaml run creates the ruleset; verify with
    `GET /repos/apache/doris-website/rulesets` and run a deploy to confirm
    publishing still works.
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    ---------
    
    Co-authored-by: morningman <[email protected]>
    Co-authored-by: Claude Code <[email protected]>
---
 .asf.yaml                                   | 13 +++++
 .github/actions/publish-asf-site/action.yml | 56 ++++++++++++++++++
 .github/scripts/check_asf_site.py           | 88 +++++++++++++++++++++++++++++
 .github/scripts/test_check_asf_site.py      | 58 +++++++++++++++++++
 .github/scripts/test_review.py              | 13 ++++-
 .github/workflows/cron-deploy-website.yml   | 27 ++++++---
 .github/workflows/manual-deploy-website.yml | 12 +---
 7 files changed, 248 insertions(+), 19 deletions(-)

diff --git a/.asf.yaml b/.asf.yaml
index c4ff473edad..a4e9511f873 100644
--- a/.asf.yaml
+++ b/.asf.yaml
@@ -37,6 +37,19 @@ github:
     - tpch
     - ssb
     - vectorized
+  rulesets:
+    - name: "Protect asf-site"
+      type: branch
+      branches:
+        includes:
+          - "asf-site"
+        excludes: []
+      # The deploy force-pushes this branch with force_orphan, so the
+      # non-fast-forward rule would break publishing. Only block deletion;
+      # full force-push protection needs a bypass identity (custom App or
+      # deploy key) because the built-in Actions app cannot be a bypass actor.
+      restrict_deletion: true
+      restrict_force_push: false
   enabled_merge_buttons:
     squash:  true
     merge:   false
diff --git a/.github/actions/publish-asf-site/action.yml 
b/.github/actions/publish-asf-site/action.yml
new file mode 100644
index 00000000000..852855677b5
--- /dev/null
+++ b/.github/actions/publish-asf-site/action.yml
@@ -0,0 +1,56 @@
+name: Publish the ASF website
+description: Push an orphan commit and record the exact commit sent to asf-site
+inputs:
+  source-sha:
+    description: The master commit used to build the website
+    required: true
+  commit-message:
+    description: The subject of the generated deployment commit
+    required: true
+runs:
+  using: composite
+  steps:
+    - name: Push website and record its commit
+      shell: bash
+      env:
+        GH_TOKEN: ${{ github.token }}
+        SOURCE_SHA: ${{ inputs.source-sha }}
+        COMMIT_MESSAGE: ${{ inputs.commit-message }}
+      run: |
+        set -euo pipefail
+        test -s build/.asf.yaml
+        [[ "$SOURCE_SHA" =~ ^[0-9a-f]{40}$ ]]
+
+        publish_dir=$(mktemp -d "$RUNNER_TEMP/asf-site.XXXXXX")
+        trap 'rm -rf -- "$publish_dir"' EXIT
+        cp -a build/. "$publish_dir/"
+        cd "$publish_dir"
+        rm -rf -- .git .github
+        touch .nojekyll
+
+        git init --quiet --initial-branch=asf-site
+        git config user.name 'github-actions[bot]'
+        git config user.email 'github-actions[bot]@users.noreply.github.com'
+        git add --all
+        git commit --quiet -m "$COMMIT_MESSAGE $GITHUB_SHA"
+        site_sha=$(git rev-parse HEAD)
+
+        auth=$(printf 'x-access-token:%s' "$GH_TOKEN" | base64 | tr -d '\n')
+        echo "::add-mask::$auth"
+        GIT_TERMINAL_PROMPT=0 GIT_CONFIG_COUNT=1 \
+          GIT_CONFIG_KEY_0="http.$GITHUB_SERVER_URL/.extraheader" \
+          GIT_CONFIG_VALUE_0="Authorization: Basic $auth" \
+          git push --force "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" 
"$site_sha:refs/heads/asf-site"
+
+        # Record the local commit after a successful push. Reading the remote
+        # ref here could bless a separate push made immediately after ours.
+        printf '{"site_sha":"%s","source_sha":"%s"}\n' "$site_sha" 
"$SOURCE_SHA" \
+          > "$RUNNER_TEMP/asf-site-publish.json"
+
+    - name: Save the publication record
+      uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 
v4
+      with:
+        name: asf-site-publish
+        path: ${{ runner.temp }}/asf-site-publish.json
+        if-no-files-found: error
+        overwrite: true
diff --git a/.github/scripts/check_asf_site.py 
b/.github/scripts/check_asf_site.py
new file mode 100644
index 00000000000..79cc2437edf
--- /dev/null
+++ b/.github/scripts/check_asf_site.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python3
+"""Compare the production branch with the last recorded website publication."""
+
+import argparse
+import io
+import json
+import os
+import subprocess
+from pathlib import Path
+from zipfile import ZipFile
+
+from review import ReviewError, api, repository, revision
+
+
+PUBLISH_EVENTS = {
+    ".github/workflows/cron-deploy-website.yml": {"push", "schedule"},
+    ".github/workflows/manual-deploy-website.yml": {"workflow_dispatch"},
+}
+SITE_REF = "refs/heads/asf-site"
+
+
+def gh_api(endpoint, *options):
+    return subprocess.check_output(["gh", "api", endpoint, *options], 
timeout=60)
+
+
+def is_master_commit(repo, run_sha, master_sha, request):
+    if run_sha == master_sha:
+        return True
+    # A workflow_dispatch run can name a tag "master". Verify the run's
+    # actual code was on the protected master branch before trusting its 
record.
+    try:
+        comparison = 
request(f"{repo}/compare/{run_sha}...{master_sha}?per_page=1")
+    except ReviewError as error:
+        if str(error) == "GitHub API request failed (HTTP 404)":
+            return False
+        raise
+    return comparison["merge_base_commit"]["sha"] == run_sha
+
+
+def published_site(repo, repo_id, master_sha, request=api, cli=gh_api):
+    pages = 
json.loads(cli(f"{repo}/actions/artifacts?name=asf-site-publish&per_page=100",
+                           "--paginate", "--slurp"))
+    records = [record for page in pages for record in page["artifacts"] if not 
record["expired"]]
+    for record in sorted(records, key=lambda item: (item["created_at"], 
item["id"]), reverse=True):
+        owner = record.get("workflow_run") or {}
+        if (owner.get("head_branch") != "master" or owner.get("repository_id") 
!= repo_id
+                or owner.get("head_repository_id") != repo_id):
+            continue
+        run = request(f"{repo}/actions/runs/{owner['id']}")
+        if run["event"] not in PUBLISH_EVENTS.get(run["path"], set()):
+            continue
+        if not is_master_commit(repo, revision(run["head_sha"]), master_sha, 
request):
+            continue
+        with 
ZipFile(io.BytesIO(cli(f"{repo}/actions/artifacts/{record['id']}/zip"))) as 
archive:
+            with archive.open("asf-site-publish.json") as data:
+                result = json.loads(data.read(1024))
+        return revision(result["site_sha"]), revision(result["source_sha"])
+    return None
+
+
+def rebuild_reason(record, current_site, current_source):
+    if record is None:
+        return "No trusted publication record. Build from master to record the 
expected asf-site commit."
+    site_sha, source_sha = record
+    if current_site != site_sha:
+        return f"Unexpected asf-site commit. Expected {site_sha}, found 
{current_site or 'no branch'}."
+    if current_source != source_sha:
+        # A scheduled run can supersede a queued push in the shared 
concurrency group.
+        return "The latest master commit has not been published."
+    return None
+
+
+def main():
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument("source_sha", type=revision)
+    args = parser.parse_args()
+    repo = f"repos/{repository()}"
+    record = published_site(repo, int(os.environ["GITHUB_REPOSITORY_ID"]), 
args.source_sha)
+    refs = api(f"{repo}/git/matching-refs/heads/asf-site")
+    current_site = next((revision(ref["object"]["sha"]) for ref in refs if 
ref["ref"] == SITE_REF), None)
+    reason = rebuild_reason(record, current_site, args.source_sha)
+    print(f"::warning::{reason}" if reason else "asf-site matches the last 
trusted publication.")
+    with Path(os.environ["GITHUB_OUTPUT"]).open("a") as output:
+        print(f"rebuild={'true' if reason else 'false'}", file=output)
+
+
+if __name__ == "__main__":
+    main()
diff --git a/.github/scripts/test_check_asf_site.py 
b/.github/scripts/test_check_asf_site.py
new file mode 100644
index 00000000000..2c9e4b2d4ce
--- /dev/null
+++ b/.github/scripts/test_check_asf_site.py
@@ -0,0 +1,58 @@
+import io
+import json
+import unittest
+from zipfile import ZipFile
+
+from check_asf_site import published_site, rebuild_reason
+
+
+MASTER = "a" * 40
+OLD_MASTER = "b" * 40
+SITE = "c" * 40
+UNRELATED = "d" * 40
+REPO = "repos/apache/doris-website"
+
+
+class SiteIntegrityTests(unittest.TestCase):
+    def 
test_rebuilds_a_missing_or_changed_site_and_publishes_pending_master(self):
+        self.assertIsNone(rebuild_reason((SITE, MASTER), SITE, MASTER))
+        self.assertIn("Unexpected asf-site commit", rebuild_reason((SITE, 
MASTER), UNRELATED, MASTER))
+        self.assertIn("no branch", rebuild_reason((SITE, MASTER), None, 
MASTER))
+        self.assertIn("No trusted publication", rebuild_reason(None, SITE, 
MASTER))
+        self.assertIn("has not been published", rebuild_reason((SITE, 
OLD_MASTER), SITE, MASTER))
+
+    def test_only_downloads_records_from_trusted_publishing_runs(self):
+        def artifact(artifact_id, **changes):
+            owner = {"repository_id": 42, "head_repository_id": 42, 
"head_branch": "master", "id": artifact_id}
+            owner.update(changes)
+            return {"id": artifact_id, "created_at": "2026-11-25T08:00:00Z",
+                    "expired": False, "workflow_run": owner}
+
+        records = [
+            artifact(1),
+            artifact(5, head_branch="asf-site"),
+            artifact(4, head_repository_id=99),
+            artifact(3),  # Same repository, but an unrelated workflow.
+            artifact(2),  # A manual run on a tag named master.
+        ]
+        manual = ".github/workflows/manual-deploy-website.yml"
+        automatic = ".github/workflows/cron-deploy-website.yml"
+        responses = {
+            f"{REPO}/actions/runs/1": {"path": automatic, "event": "schedule", 
"head_sha": OLD_MASTER},
+            f"{REPO}/actions/runs/2": {"path": manual, "event": 
"workflow_dispatch", "head_sha": UNRELATED},
+            f"{REPO}/actions/runs/3": {"path": ".github/workflows/other.yml", 
"event": "push", "head_sha": MASTER},
+            f"{REPO}/compare/{UNRELATED}...{MASTER}?per_page=1": 
{"merge_base_commit": {"sha": OLD_MASTER}},
+            f"{REPO}/compare/{OLD_MASTER}...{MASTER}?per_page=1": 
{"merge_base_commit": {"sha": OLD_MASTER}},
+        }
+
+        def cli(endpoint, *options):
+            if endpoint.endswith("&per_page=100"):
+                self.assertEqual(options, ("--paginate", "--slurp"))
+                return json.dumps([{"artifacts": records[:3]}, {"artifacts": 
records[3:]}])
+            self.assertEqual(endpoint, f"{REPO}/actions/artifacts/1/zip")
+            data = io.BytesIO()
+            with ZipFile(data, "w") as archive:
+                archive.writestr("asf-site-publish.json", 
json.dumps({"site_sha": SITE, "source_sha": MASTER}))
+            return data.getvalue()
+
+        self.assertEqual(published_site(REPO, 42, MASTER, 
responses.__getitem__, cli), (SITE, MASTER))
diff --git a/.github/scripts/test_review.py b/.github/scripts/test_review.py
index 61bf5e4765c..8105d48d16f 100644
--- a/.github/scripts/test_review.py
+++ b/.github/scripts/test_review.py
@@ -326,9 +326,20 @@ class WorkflowTests(unittest.TestCase):
                 self.assertTrue(any(step.get("uses") == 
"./.github/actions/upload-website-assets" for step in deploy["steps"]))
                 publisher = next(step for step in deploy["steps"] if 
step.get("name") == "Deploy Website")
                 self.assertEqual(publisher["if"], 
"vars.WEBSITE_PUBLISH_ENABLED == 'true'")
+                self.assertEqual(publisher["uses"], 
"./.github/actions/publish-asf-site")
+                self.assertEqual(publisher["with"]["source-sha"], "${{ 
needs.source.outputs.source_sha }}")
             self.assertEqual(deploy["steps"][0]["with"]["ref"], "${{ 
github.sha }}")
-            
self.assertEqual(workflow["jobs"]["source"]["steps"][-1]["env"]["DEPLOY_BRANCH"],
+            source = workflow["jobs"]["source"]
+            resolver = next(step for step in source["steps"] if step.get("id") 
== "source")
+            self.assertEqual(resolver["env"]["DEPLOY_BRANCH"],
                              "${{ inputs.branch }}" if 
name.startswith("manual") else "master")
+            if name == "cron-deploy-website.yml":
+                self.assertIn("schedule", workflow["on"])
+                self.assertEqual(source["permissions"], {"contents": "read", 
"actions": "read"})
+                self.assertIn("github.ref == 'refs/heads/master'", 
source["if"])
+                self.assertNotIn("secrets.", json.dumps(source))
+                self.assertEqual(source["outputs"]["rebuild"], "${{ 
steps.integrity.outputs.rebuild }}")
+                self.assertEqual(build["if"], "github.event_name == 'push' || 
needs.source.outputs.rebuild == 'true'")
 
     def 
test_repository_secrets_work_without_new_environment_configuration(self):
         raw = subprocess.check_output(["node", "-e", """
diff --git a/.github/workflows/cron-deploy-website.yml 
b/.github/workflows/cron-deploy-website.yml
index 15951a80713..f1c0248bce5 100644
--- a/.github/workflows/cron-deploy-website.yml
+++ b/.github/workflows/cron-deploy-website.yml
@@ -4,6 +4,8 @@ on:
     push:
         branches:
             - master
+    schedule:
+        - cron: '17 * * * *'
 permissions:
   contents: read
 # Serialize website uploads and ASF publication with manual deployment.
@@ -15,23 +17,36 @@ jobs:
     if: github.repository == 'apache/doris-website' && github.ref == 
'refs/heads/master'
     runs-on: ubuntu-latest
     timeout-minutes: 5
+    permissions:
+      contents: read
+      actions: read
     outputs:
       source_sha: ${{ steps.source.outputs.source_sha }}
       branch: ${{ steps.source.outputs.branch }}
+      rebuild: ${{ steps.integrity.outputs.rebuild }}
     steps:
       - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
         with:
           ref: ${{ github.sha }}
           persist-credentials: false
+          sparse-checkout: .github/scripts
       - name: Resolve a protected branch to an immutable commit
         id: source
         env:
           GH_TOKEN: ${{ github.token }}
           DEPLOY_BRANCH: master
         run: python3 .github/scripts/review.py deploy-ref
+      - name: Check the published commit
+        id: integrity
+        if: github.event_name == 'schedule' && vars.WEBSITE_PUBLISH_ENABLED == 
'true'
+        env:
+          GH_TOKEN: ${{ github.token }}
+          SOURCE_SHA: ${{ steps.source.outputs.source_sha }}
+        run: python3 .github/scripts/check_asf_site.py "$SOURCE_SHA"
 
   build:
     needs: source
+    if: github.event_name == 'push' || needs.source.outputs.rebuild == 'true'
     outputs:
       locales: ${{ steps.publication-locales.outputs.locales }}
       artifact_id: ${{ steps.site-artifact.outputs.artifact-id }}
@@ -265,16 +280,10 @@ jobs:
 
       - name: Deploy Website
         if: vars.WEBSITE_PUBLISH_ENABLED == 'true'
-        uses: 
peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847 # v3
+        uses: ./.github/actions/publish-asf-site
         with:
-            github_token: ${{ github.token }}
-            publish_branch: asf-site
-            publish_dir: ./build
-            force_orphan: true
-            destination_dir: ./
-            user_name: 'github-actions[bot]'
-            user_email: 'github-actions[bot]@users.noreply.github.com'
-            commit_message: 'Automated deployment with doris master@${{ 
env.DORIS_COMMIT }}'
+          source-sha: ${{ needs.source.outputs.source_sha }}
+          commit-message: 'Automated deployment with doris master@${{ 
env.DORIS_COMMIT }}'
 
       - name: Report publishing measurements
         if: always() && steps.metrics-start.outcome == 'success'
diff --git a/.github/workflows/manual-deploy-website.yml 
b/.github/workflows/manual-deploy-website.yml
index 2aa15e74c2f..56c05e06d5d 100644
--- a/.github/workflows/manual-deploy-website.yml
+++ b/.github/workflows/manual-deploy-website.yml
@@ -250,16 +250,10 @@ jobs:
 
       - name: Deploy Website
         if: vars.WEBSITE_PUBLISH_ENABLED == 'true'
-        uses: 
peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847 # v3
+        uses: ./.github/actions/publish-asf-site
         with:
-            github_token: ${{ github.token }}
-            publish_branch: asf-site
-            force_orphan: true
-            publish_dir: ./build
-            destination_dir: ./
-            user_name: 'github-actions[bot]'
-            user_email: 'github-actions[bot]@users.noreply.github.com'
-            commit_message: 'Automated deployment with doris branch ${{ 
needs.source.outputs.branch }}@${{ env.DORIS_COMMIT }}'
+          source-sha: ${{ needs.source.outputs.source_sha }}
+          commit-message: 'Automated deployment with doris branch ${{ 
needs.source.outputs.branch }}@${{ env.DORIS_COMMIT }}'
 
       - name: Report publishing measurements
         if: always() && steps.metrics-start.outcome == 'success'


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

Reply via email to