Skip to content

Commit 5553615

Browse files
authored
fix(ci): own docs publish Git lifecycle (#133093)
1 parent d567246 commit 5553615

11 files changed

Lines changed: 628 additions & 85 deletions

‎.github/workflows/docs-sync-publish.yml‎

Lines changed: 107 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ jobs:
5454
persist-credentials: false
5555
token: ${{ env.OPENCLAW_DOCS_SYNC_TOKEN || github.token }}
5656

57+
- name: Prepare Git owner
58+
if: env.OPENCLAW_DOCS_SYNC_TOKEN != ''
59+
uses: openclaw/openclaw/.github/actions/git-owner@dd4528b6393e7d00063067a080ca7241b48ce475
60+
5761
- name: Setup Node
5862
if: env.OPENCLAW_DOCS_SYNC_TOKEN != ''
5963
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
@@ -64,24 +68,36 @@ jobs:
6468
if: env.OPENCLAW_DOCS_SYNC_TOKEN != ''
6569
run: |
6670
set -euo pipefail
67-
for attempt in 1 2 3 4 5; do
68-
rm -rf publish
69-
if timeout --signal=TERM --kill-after=10s 120s git clone \
70-
"https://x-access-token:${OPENCLAW_DOCS_SYNC_TOKEN}@github.com/openclaw/docs.git" \
71-
publish; then
72-
exit 0
73-
fi
74-
echo "Clone attempt ${attempt} failed; retrying."
75-
sleep $((attempt * 2))
76-
done
77-
78-
echo "Failed to clone publish repo after retries." >&2
79-
exit 1
71+
exec python3 -I -S "$CI_GIT_OWNER" --policy - <<'PYTHON'
72+
import os
73+
import subprocess
74+
import sys
75+
from ci_git_owner import run_git, GitFailure, FetchTimeout, backoff, check_cancelled
76+
77+
workspace = os.environ["GITHUB_WORKSPACE"]
78+
publish = os.path.join(workspace, "publish")
79+
for attempt in range(1, 6):
80+
check_cancelled()
81+
# Delete only this fixed entry, including a file or symlink, after
82+
# the previous Git tree has been verified extinct.
83+
subprocess.run(["rm", "-rf", publish], check=True)
84+
try:
85+
run_git(workspace, "clone",
86+
f"https://x-access-token:{os.environ['OPENCLAW_DOCS_SYNC_TOKEN']}@github.com/openclaw/docs.git",
87+
publish, timeout=120)
88+
raise SystemExit(0)
89+
except (GitFailure, FetchTimeout):
90+
print(f"Clone attempt {attempt} failed; retrying.", flush=True)
91+
backoff(attempt * 2)
92+
print("Failed to clone publish repo after retries.", file=sys.stderr)
93+
raise SystemExit(1)
94+
PYTHON
8095
8196
- name: Sync docs into publish repo
8297
if: env.OPENCLAW_DOCS_SYNC_TOKEN != ''
8398
run: |
84-
clawhub_sha="$(git -C "$GITHUB_WORKSPACE/clawhub-source" rev-parse HEAD)"
99+
set -euo pipefail
100+
clawhub_sha="$(cd "$GITHUB_WORKSPACE/clawhub-source" && python3 -I -S "$CI_GIT_OWNER" --checkout-git 0 rev-parse HEAD)"
85101
node scripts/docs-sync-publish.mjs \
86102
--target "$GITHUB_WORKSPACE/publish" \
87103
--source-repo "$GITHUB_REPOSITORY" \
@@ -104,48 +120,80 @@ jobs:
104120
working-directory: publish
105121
run: |
106122
set -euo pipefail
107-
remote_source_sha() {
108-
git show refs/remotes/origin/main:.openclaw-sync/source.json 2>/dev/null \
109-
| node -e 'const fs = require("node:fs"); try { const data = JSON.parse(fs.readFileSync(0, "utf8")); if (data.sha) process.stdout.write(data.sha); } catch {}' \
110-
|| true
111-
}
112-
113-
skip_stale_source() {
114-
current_source_sha="$(remote_source_sha)"
115-
if [ -z "$current_source_sha" ] || [ "$current_source_sha" = "$GITHUB_SHA" ]; then
116-
return
117-
fi
118-
119-
if git -C "$GITHUB_WORKSPACE" merge-base --is-ancestor "$GITHUB_SHA" "$current_source_sha"; then
120-
echo "Skipping stale publish sync for $GITHUB_SHA; origin/main already mirrors $current_source_sha."
121-
exit 0
122-
fi
123-
}
124-
125-
if git diff --quiet -- docs .openclaw-sync; then
126-
echo "No publish-repo changes."
127-
exit 0
128-
fi
129-
130-
if timeout --signal=TERM --kill-after=10s 120s git fetch origin main:refs/remotes/origin/main; then
131-
skip_stale_source
132-
fi
133-
134-
git config user.name "openclaw-docs-sync[bot]"
135-
git config user.email "openclaw-docs-sync[bot]@users.noreply.github.com"
136-
git add docs .openclaw-sync
137-
git commit -m "chore(sync): mirror docs from $GITHUB_REPOSITORY@$GITHUB_SHA"
138-
for attempt in 1 2 3 4 5; do
139-
if timeout --signal=TERM --kill-after=10s 120s git fetch origin main:refs/remotes/origin/main; then
140-
skip_stale_source
141-
if git rebase -X theirs origin/main && git push origin HEAD:main; then
142-
exit 0
143-
fi
144-
fi
145-
git rebase --abort >/dev/null 2>&1 || true
146-
echo "Publish sync attempt ${attempt} failed; retrying."
147-
sleep $((attempt * 2))
148-
done
149-
150-
echo "Failed to push publish-repo sync after retries."
151-
exit 1
123+
exec python3 -I -S "$CI_GIT_OWNER" --policy - <<'PYTHON'
124+
import json
125+
import os
126+
import subprocess
127+
import tempfile
128+
from ci_git_owner import run_git, GitFailure, FetchTimeout, backoff
129+
130+
publish = os.getcwd()
131+
workspace = os.environ["GITHUB_WORKSPACE"]
132+
source_sha = os.environ["GITHUB_SHA"]
133+
134+
def invalid_json_constant(value):
135+
raise json.JSONDecodeError("Invalid JSON constant", value, 0)
136+
137+
def remote_source_sha():
138+
try:
139+
with tempfile.TemporaryFile() as output:
140+
run_git(publish, "show", "refs/remotes/origin/main:.openclaw-sync/source.json",
141+
stdout=output, stderr=subprocess.DEVNULL)
142+
output.seek(0)
143+
data = json.loads(output.read().decode("utf-8", errors="replace"),
144+
parse_constant=invalid_json_constant)
145+
sha = data.get("sha") if isinstance(data, dict) else None
146+
return sha.rstrip("\n") if isinstance(sha, str) else ""
147+
except (GitFailure, json.JSONDecodeError):
148+
return ""
149+
150+
def skip_stale_source():
151+
current_source_sha = remote_source_sha()
152+
if not current_source_sha or current_source_sha == source_sha:
153+
return
154+
try:
155+
run_git(workspace, "merge-base", "--is-ancestor", source_sha, current_source_sha)
156+
except GitFailure:
157+
return
158+
print(f"Skipping stale publish sync for {source_sha}; origin/main already mirrors {current_source_sha}.")
159+
raise SystemExit(0)
160+
161+
try:
162+
run_git(publish, "diff", "--quiet", "--", "docs", ".openclaw-sync")
163+
except GitFailure:
164+
pass
165+
else:
166+
print("No publish-repo changes.")
167+
raise SystemExit(0)
168+
169+
try:
170+
run_git(publish, "fetch", "origin", "main:refs/remotes/origin/main", timeout=120, reclaim_locks=True)
171+
except (GitFailure, FetchTimeout):
172+
pass
173+
else:
174+
skip_stale_source()
175+
176+
run_git(publish, "config", "user.name", "openclaw-docs-sync[bot]", reclaim_locks=True)
177+
run_git(publish, "config", "user.email", "openclaw-docs-sync[bot]@users.noreply.github.com", reclaim_locks=True)
178+
run_git(publish, "add", "docs", ".openclaw-sync", reclaim_locks=True)
179+
run_git(publish, "commit", "-m", f"chore(sync): mirror docs from {os.environ['GITHUB_REPOSITORY']}@{source_sha}", reclaim_locks=True)
180+
for attempt in range(1, 6):
181+
try:
182+
run_git(publish, "fetch", "origin", "main:refs/remotes/origin/main", timeout=120, reclaim_locks=True)
183+
skip_stale_source()
184+
run_git(publish, "rebase", "-X", "theirs", "origin/main", reclaim_locks=True)
185+
run_git(publish, "push", "origin", "HEAD:main", reclaim_locks=True)
186+
raise SystemExit(0)
187+
except (GitFailure, FetchTimeout):
188+
# Only verified Git failure may reach abort/retry; ownership
189+
# uncertainty and cancellation escape the connected policy.
190+
try:
191+
run_git(publish, "rebase", "--abort", stdout=subprocess.DEVNULL,
192+
stderr=subprocess.DEVNULL, reclaim_locks=True)
193+
except GitFailure:
194+
pass
195+
print(f"Publish sync attempt {attempt} failed; retrying.", flush=True)
196+
backoff(attempt * 2)
197+
print("Failed to push publish-repo sync after retries.")
198+
raise SystemExit(1)
199+
PYTHON

‎docs/ci.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ Mantis ref validation uses the same pinned owner. The shared `mantis-validate-tr
198198

199199
Mantis installers and worktree preparation also use that pinned owner, prepared immediately after the harness checkout in each run job. Discord status reactions and thread attachment retain their two depth-one Crabbox clones with 120-second deadlines through `--git 120`. Slack desktop retains init, remote-add, one depth-one fetch of `main`, and detached `FETCH_HEAD` checkout; only its fetch has a 120-second deadline. All six worktree additions across status reactions, thread attachment, Slack desktop, and Web UI chat proof use `--checkout-git 0` from the harness checkout. Local init, remote-add, checkout, and worktree operations have no operation deadline. Ownership failure or cancellation is terminal before subsequent Git operations, Go/pnpm builds, probes, or outputs. No current Mantis Git invocation uses GNU `timeout`.
200200

201+
Docs Sync Publish Repo prepares the same pinned owner after the source and ClawHub checkouts, using system Python before Node setup. Its inline typed policies own clone and the connected publication chain. Clone and both fetch sites retain 120-second operation deadlines; clone and publication retain five attempts with 2/4/6/8/10-second backoffs, including the final failed attempt. Only ordinary Git failure or `FetchTimeout` permits retry after verified cleanup. The advisory pre-commit fetch may fail and safely continue to commit; publication failure first attempts an owned rebase abort. Rebase, push, local reads, and config/add/commit remain unbounded. ClawHub HEAD must complete through the owner before the sync script consumes it. Cleanup uncertainty, setup failure, or cancellation is terminal before retry, abort, another deletion, or consumption. Only the fixed publish path is replaced, without following its symlink; exclusive publish operations reclaim newly created locks while preserving existing locks. Queue concurrency, stale-source checks, and no-change success remain unchanged.
202+
201203
To use the standalone action from another workflow, pin `openclaw/openclaw/.github/actions/git-owner@<full-40-character-commit-SHA>` to a reviewed revision containing the action. Supply policy from the trusted workflow inline or from the same trusted action package, never from the selected candidate. Within `ci.yml`, the existing bundled-protocol and CI-routing matrix tasks smoke-test the action from the separately pinned `.ci-harness` checkout before Node setup, compare its output and copied bytes, and run owned `git --version` without network access. Other workflows' direct Git commands remain outside this ownership coverage until they adopt it.
202204

203205
## Scope and routing
@@ -209,7 +211,7 @@ Release screenshot routing is deliberately conservative because an app change ca
209211
Separate iOS and macOS Periphery workflows enforce a zero-findings dead-code policy. Each runs only when a non-draft pull request touches its native scan scope, or when manually dispatched.
210212

211213
- **CI workflow edits** validate the Node CI graph, workflow linting, and the Windows lane (`ci.yml` executes it), but do not force iOS, Android, or macOS native builds by themselves; those platform lanes stay scoped to platform source changes.
212-
- **Git-owner changes** to its action, base-commit policy, projection generator, lifecycle tests and support, or named owner-adopting workflows such as Workflow Sanity, QA Profile Evidence, and Mantis ref validation, installer, and worktree workflows select the existing `macos-node` and Windows lanes. These run native checkout ownership proof without selecting Swift, iOS, or Android jobs; Mac app and shared-native changes retain their existing Mac lanes.
214+
- **Git-owner changes** to its action, base-commit policy, projection generator, lifecycle tests and support, or named owner-adopting workflows such as Workflow Sanity, QA Profile Evidence, Mantis ref validation/installers/worktrees, and Docs Sync Publish Repo select the existing `macos-node` and Windows lanes. These run native checkout ownership proof without selecting Swift, iOS, or Android jobs; Mac app and shared-native changes retain their existing Mac lanes.
213215
- **macOS Swift runner budgets** are 20 minutes on Blacksmith and 30 minutes on every GitHub-hosted route, including first-attempt pull requests from untrusted contributors.
214216
- **Workflow Sanity** runs `actionlint`, `zizmor` over all workflow YAML files, the composite-action interpolation guard, and the conflict-marker guard. The PR-scoped `security-fast` job also runs `zizmor` over changed workflow files so workflow security findings fail early in the main CI graph.
215217
- **Docs on `main` pushes** are checked by the standalone `Docs` workflow with the same ClawHub docs mirror used by CI, so mixed code+docs pushes do not also queue the CI `check-docs` shard. Pull requests and manual CI still run `check-docs` from CI when docs changed.

‎scripts/ci-changed-scope.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const APPLE_SHARED_CONTRACT_FIXTURE_RE =
4848
const MACOS_NATIVE_RE =
4949
/^(apps\/macos\/|apps\/macos-mlx-tts\/|apps\/shared\/|apps\/swabble\/|Swabble\/)/;
5050
const GIT_OWNER_SCOPE_RE =
51-
/^(?:\.github\/(?:actions\/(?:git-owner|ensure-base-commit|mantis-validate-trusted-ref)\/|workflows\/(?:workflow-sanity|qa-profile-evidence|mantis-(?:discord-(?:smoke|status-reactions|thread-attachment)|slack-desktop-smoke|web-ui-chat-proof))\.yml$)|scripts\/generate-ci-git-owner\.mts$|test\/scripts\/(?:ci-(?:checkout|git-owner|linux-git|platform-checkout)\.test(?:-support)?\.ts|fixtures\/ci-platform-checkout\.mjs)$)/;
51+
/^(?:\.github\/(?:actions\/(?:git-owner|ensure-base-commit|mantis-validate-trusted-ref)\/|workflows\/(?:workflow-sanity|qa-profile-evidence|docs-sync-publish|mantis-(?:discord-(?:smoke|status-reactions|thread-attachment)|slack-desktop-smoke|web-ui-chat-proof))\.yml$)|scripts\/generate-ci-git-owner\.mts$|test\/scripts\/(?:ci-(?:checkout|git-owner|linux-git|platform-checkout)\.test(?:-support)?\.ts|fixtures\/ci-platform-checkout\.mjs)$)/;
5252
const MACOS_SCRIPT_SCOPE_RE =
5353
/^(?:scripts\/(?:check-swift-tools|codesign-mac-app|create-dmg|format-swift|install-swift-tools|install-xcodegen|lint-swift|mac-elevation-host|notarize-mac-artifact|package-mac-app|package-mac-dist|restart-mac|stage-cua-driver-macos|stage-mac-node-worker)\.sh|scripts\/test-macos-native\.mts|scripts\/(?:verify-mac-node-worker(?:-fs)?|lib\/(?:mac-node-worker-proof-state|mac-worker-portability))\.mjs|scripts\/(?:materialize-mac-node-worker|lib\/(?:mac-native-inventory|mac-bundle-mutation))\.py|scripts\/lib\/(?:mac-app-bundle|plistbuddy|swift-toolchain)\.sh|test\/helpers\/mac-(?:native|signing)\.ts|test\/scripts\/(?:codesign-mac-app|create-dmg|mac-elevation-host|mac-node-worker|macos-native-test-launch|notarize-mac-artifact|package-mac-app|package-mac-dist|restart-mac|verify-mac-node-worker-fs)\.test\.ts|test\/scripts\/(?:mac-elevation-artifact|mac-native-fixtures|mac-node-worker-materialization)\.test-support\.ts)$/;
5454
const WORKSPACE_RSYNC_RECEIVER_SCOPE_RE =

‎scripts/test-projects.test-support.mts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,7 @@ const pluginSdkEntryOwners = [
21212121
// unambiguous scripts and direct imports without a second inventory.
21222122
const EXACT_TOOLING_TARGETS = new Map<string, string[]>([
21232123
[".github/workflows/ci.yml", ["ci-platform-checkout", "ci-linux-git", "ci-git-owner"]],
2124+
[".github/workflows/docs-sync-publish.yml", ["docs-sync-publish"]],
21242125
[
21252126
"test/scripts/fixtures/ci-platform-checkout.mjs",
21262127
["ci-platform-checkout", "ci-linux-git", "ci-git-owner"],
@@ -2395,7 +2396,7 @@ const SEMANTIC_TOOLING_TARGET_PATTERNS: Array<[RegExp, string[]]> = [
23952396
],
23962397
[/^\.github\/workflows\/android-release\.yml$/u, [packageAcceptance, workflowGuards]],
23972398
[
2398-
/^\.github\/(?:actions\/(?:ensure-base-commit|git-owner|mantis-validate-trusted-ref)\/|workflows\/(?:workflow-sanity|qa-profile-evidence|mantis-(?:discord-(?:smoke|status-reactions|thread-attachment)|slack-desktop-smoke|web-ui-chat-proof))\.yml$)/u,
2399+
/^\.github\/(?:actions\/(?:ensure-base-commit|git-owner|mantis-validate-trusted-ref)\/|workflows\/(?:workflow-sanity|qa-profile-evidence|docs-sync-publish|mantis-(?:discord-(?:smoke|status-reactions|thread-attachment)|slack-desktop-smoke|web-ui-chat-proof))\.yml$)/u,
23992400
["ci-git-owner", "ci-linux-git", "ci-platform-checkout"],
24002401
],
24012402
[/^tsconfig\.scripts\.json$/u, ["changed-lanes", "test-projects"]],

‎src/scripts/ci-changed-scope.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ describe("detectChangedScope", () => {
402402
".github/actions/git-owner/action.yml",
403403
".github/workflows/workflow-sanity.yml",
404404
".github/workflows/qa-profile-evidence.yml",
405+
".github/workflows/docs-sync-publish.yml",
405406
".github/actions/mantis-validate-trusted-ref/action.yml",
406407
".github/workflows/mantis-discord-smoke.yml",
407408
".github/workflows/mantis-discord-status-reactions.yml",

‎test/scripts/ci-checkout.test-support.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ def run_git(`,
8282
"deadline is not None and time.monotonic() >= deadline",
8383
"deadline is not None and fetch_clock() >= deadline",
8484
)
85-
.replace(/\btimeout=30(?=[,)])/gu, "timeout=2")
86-
.replace(/retry_at = time\.monotonic\(\) \+ [^\n]+/u, "retry_at = time.monotonic() + 0.05")
85+
.replace(/\btimeout=(?:30|120)(?=[,)])/gu, "timeout=2")
86+
.replace(
87+
/retry_at = time\.monotonic\(\) \+ [^\n]+/u,
88+
'print(f"fixture backoff: {seconds}", flush=True)\n retry_at = time.monotonic() + 0.05',
89+
)
8790
.replace(/--((?:checkout-)?git) 120\b/gu, "--$1 2")
8891
// Keep pre-fix standalone shell bodies executable for red/green proof.
8992
.replaceAll("120s git", "2s git")
93+
.replaceAll("sleep $((attempt * 2))", 'echo "fixture backoff: $((attempt * 2))"')
9094
.replaceAll("sleep $((attempt * 5))", "sleep 0.05")
9195
.replaceAll("sleep 5", "sleep 0.05");
9296
return options.realDrain

0 commit comments

Comments
 (0)