4040 persist-credentials : false
4141 submodules : false
4242
43+ - name : Prepare Git owner
44+ uses : openclaw/openclaw/.github/actions/git-owner@dd4528b6393e7d00063067a080ca7241b48ce475
45+
4346 - name : Gate trusted main activity and hourly cadence
4447 id : gate
4548 env :
@@ -49,35 +52,55 @@ jobs:
4952 run : |
5053 set -euo pipefail
5154
52- if [ "$EVENT_NAME" != "workflow_run" ]; then
53- head_sha="$(git rev-parse HEAD)"
54- review_base="$(git rev-parse "${head_sha}^" 2>/dev/null || printf '%s' "$head_sha")"
55- {
56- echo "run_agent=true"
57- echo "base_sha=${head_sha}"
58- echo "review_base_sha=${review_base}"
59- echo "review_head_sha=${head_sha}"
60- } >> "$GITHUB_OUTPUT"
61- exit 0
62- fi
55+ remote_main_file="$(mktemp "$RUNNER_TEMP/docs-agent-main.XXXXXX")"
56+ trap 'rm -f -- "$remote_main_file" "$RUNNER_TEMP/docs-agent-runs.json"' EXIT
57+ python3 -I -S "$CI_GIT_OWNER" --policy - "$remote_main_file" <<'PYTHON'
58+ import os
59+ import subprocess
60+ import sys
61+ import tempfile
62+ from ci_git_owner import run_git, git_output, GitFailure, FetchTimeout, backoff, check_cancelled
6363
64- for attempt in 1 2 3 4 5; do
65- if timeout --signal=TERM --kill-after=10s 120s git fetch --no-tags origin main; then
66- break
67- fi
68- if [ "$attempt" = "5" ]; then
69- echo "Failed to fetch main after retries." >&2
70- exit 1
71- fi
72- echo "Fetch attempt ${attempt} failed; retrying."
73- sleep $((attempt * 2))
74- done
75- remote_main="$(git rev-parse origin/main)"
76- if [ "$remote_main" != "$WORKFLOW_HEAD_SHA" ]; then
77- echo "CI run is superseded by ${remote_main}; skipping docs agent for ${WORKFLOW_HEAD_SHA}."
78- echo "run_agent=false" >> "$GITHUB_OUTPUT"
64+ workspace = os.getcwd()
65+ if os.environ["EVENT_NAME"] != "workflow_run":
66+ head_sha = git_output(workspace, "rev-parse", "HEAD").rstrip("\n")
67+ try:
68+ with tempfile.TemporaryFile(dir=os.environ["RUNNER_TEMP"]) as parent:
69+ run_git(workspace, "rev-parse", f"{head_sha}^", stdout=parent, stderr=subprocess.DEVNULL)
70+ parent.seek(0)
71+ review_base = parent.read().decode().rstrip("\n")
72+ except GitFailure:
73+ review_base = head_sha
74+ check_cancelled()
75+ with open(os.environ["GITHUB_OUTPUT"], "a") as output:
76+ output.write(f"run_agent=true\nbase_sha={head_sha}\nreview_base_sha={review_base}\nreview_head_sha={head_sha}\n")
77+ raise SystemExit(0)
78+
79+ for attempt in range(1, 6):
80+ try:
81+ run_git(workspace, "fetch", "--no-tags", "origin", "main", timeout=120, reclaim_locks=True)
82+ break
83+ except (GitFailure, FetchTimeout):
84+ if attempt == 5:
85+ print("Failed to fetch main after retries.", file=sys.stderr)
86+ raise SystemExit(1)
87+ print(f"Fetch attempt {attempt} failed; retrying.", flush=True)
88+ backoff(attempt * 2)
89+ remote_main = git_output(workspace, "rev-parse", "origin/main").rstrip("\n")
90+ check_cancelled()
91+ if remote_main != os.environ["WORKFLOW_HEAD_SHA"]:
92+ print(f"CI run is superseded by {remote_main}; skipping docs agent for {os.environ['WORKFLOW_HEAD_SHA']}.")
93+ with open(os.environ["GITHUB_OUTPUT"], "a") as output:
94+ output.write("run_agent=false\n")
95+ else:
96+ # Only a current, fully drained main read permits the shell cadence query.
97+ with open(sys.argv[3], "w") as fact:
98+ fact.write(remote_main + "\n")
99+ PYTHON
100+ if [ ! -s "$remote_main_file" ]; then
79101 exit 0
80102 fi
103+ remote_main="$(cat "$remote_main_file")"
81104
82105 runs_json="$RUNNER_TEMP/docs-agent-runs.json"
83106 gh api --method GET "repos/${GITHUB_REPOSITORY}/actions/workflows/docs-agent.yml/runs" \
@@ -117,16 +140,31 @@ jobs:
117140 | select(. != $remote_main)
118141 ' "$runs_json" | head -n 1
119142 )"
120- if [ -z "$review_base" ] || ! git cat-file -e "${review_base}^{commit}" 2>/dev/null; then
121- review_base="$(git rev-parse "${remote_main}^" 2>/dev/null || printf '%s' "$remote_main")"
122- fi
143+ python3 -I -S "$CI_GIT_OWNER" --policy - "$remote_main" "$review_base" <<'PYTHON'
144+ import os
145+ import subprocess
146+ import sys
147+ import tempfile
148+ from ci_git_owner import run_git, GitFailure, check_cancelled
123149
124- {
125- echo "run_agent=true"
126- echo "base_sha=${remote_main}"
127- echo "review_base_sha=${review_base}"
128- echo "review_head_sha=${remote_main}"
129- } >> "$GITHUB_OUTPUT"
150+ remote_main, review_base = sys.argv[3:]
151+ try:
152+ if review_base:
153+ run_git(os.getcwd(), "cat-file", "-e", f"{review_base}^{{commit}}", stderr=subprocess.DEVNULL)
154+ except GitFailure:
155+ review_base = ""
156+ if not review_base:
157+ try:
158+ with tempfile.TemporaryFile(dir=os.environ["RUNNER_TEMP"]) as parent:
159+ run_git(os.getcwd(), "rev-parse", f"{remote_main}^", stdout=parent, stderr=subprocess.DEVNULL)
160+ parent.seek(0)
161+ review_base = parent.read().decode().rstrip("\n")
162+ except GitFailure:
163+ review_base = remote_main
164+ check_cancelled()
165+ with open(os.environ["GITHUB_OUTPUT"], "a") as output:
166+ output.write(f"run_agent=true\nbase_sha={remote_main}\nreview_base_sha={review_base}\nreview_head_sha={remote_main}\n")
167+ PYTHON
130168
131169 - name : Setup Node environment
132170 if : steps.gate.outputs.run_agent == 'true'
@@ -166,27 +204,30 @@ jobs:
166204 run : |
167205 set -euo pipefail
168206
169- untracked="$(git ls-files --others --exclude-standard)"
207+ untracked="$(python3 -I -S "$CI_GIT_OWNER" --checkout- git 0 ls-files --others --exclude-standard)"
170208 if [ -n "$untracked" ]; then
171209 echo "Docs agent created untracked files; forbidden:"
172210 printf '%s\n' "$untracked"
173211 exit 1
174212 fi
175213
176- added_or_deleted="$(git diff --name-status --diff-filter=AD)"
214+ added_or_deleted="$(python3 -I -S "$CI_GIT_OWNER" --checkout- git 0 diff --name-status --diff-filter=AD)"
177215 if [ -n "$added_or_deleted" ]; then
178216 echo "Docs agent added or deleted tracked files; forbidden:"
179217 printf '%s\n' "$added_or_deleted"
180218 exit 1
181219 fi
182220
183- bad_paths="$(
184- git diff --name-only | while IFS= read -r path; do
221+ filter_bad_paths() {
222+ while IFS= read -r path; do
185223 case "$path" in
186224 docs/*|README.md|CHANGELOG.md) ;;
187225 *) printf '%s\n' "$path" ;;
188226 esac
189227 done
228+ }
229+ bad_paths="$(
230+ python3 -I -S "$CI_GIT_OWNER" --checkout-git 0 diff --name-only | filter_bad_paths
190231 )"
191232 if [ -n "$bad_paths" ]; then
192233 echo "Docs agent touched non-doc paths; forbidden:"
@@ -218,33 +259,46 @@ jobs:
218259 run : |
219260 set -euo pipefail
220261
221- if git diff --quiet; then
222- echo "No docs changes."
223- exit 0
224- fi
262+ exec python3 -I -S "$CI_GIT_OWNER" --policy - <<'PYTHON'
263+ import os
264+ import sys
265+ from ci_git_owner import run_git, git_output, GitFailure, FetchTimeout, backoff
266+
267+ workspace = os.getcwd()
268+ target = os.environ["TARGET_BRANCH"]
269+ base_sha = os.environ["BASE_SHA"]
270+ try:
271+ run_git(workspace, "diff", "--quiet")
272+ except GitFailure:
273+ pass
274+ else:
275+ print("No docs changes.")
276+ raise SystemExit(0)
225277
226- git config user.name "openclaw-docs-agent[bot]"
227- git config user.email "openclaw-docs-agent[bot]@users.noreply.github.com"
228- git add docs README.md CHANGELOG.md
229- git commit --no-verify -m "docs: refresh documentation"
230-
231- for attempt in 1 2 3 4 5; do
232- if ! timeout --signal=TERM --kill-after=10s 120s git fetch --no-tags origin "${TARGET_BRANCH}"; then
233- echo "Fetch attempt ${attempt} failed; retrying."
234- sleep $((attempt * 2))
235- continue
236- fi
237- if git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" HEAD:"${TARGET_BRANCH}"; then
238- exit 0
239- fi
240- remote_main="$(git rev-parse "origin/${TARGET_BRANCH}")"
241- if [ "$remote_main" != "$BASE_SHA" ]; then
242- echo "main advanced from ${BASE_SHA} to ${remote_main}; skipping stale docs update."
243- exit 0
244- fi
245- echo "Docs update attempt ${attempt} failed; retrying."
246- sleep $((attempt * 2))
247- done
248-
249- echo "Failed to push docs updates after retries." >&2
250- exit 1
278+ run_git(workspace, "config", "user.name", "openclaw-docs-agent[bot]", reclaim_locks=True)
279+ run_git(workspace, "config", "user.email", "openclaw-docs-agent[bot]@users.noreply.github.com", reclaim_locks=True)
280+ run_git(workspace, "add", "docs", "README.md", "CHANGELOG.md", reclaim_locks=True)
281+ run_git(workspace, "commit", "--no-verify", "-m", "docs: refresh documentation", reclaim_locks=True)
282+ for attempt in range(1, 6):
283+ try:
284+ run_git(workspace, "fetch", "--no-tags", "origin", target, timeout=120, reclaim_locks=True)
285+ except (GitFailure, FetchTimeout):
286+ print(f"Fetch attempt {attempt} failed; retrying.", flush=True)
287+ backoff(attempt * 2)
288+ continue
289+ try:
290+ run_git(workspace, "push",
291+ f"https://x-access-token:{os.environ['GITHUB_TOKEN']}@github.com/{os.environ['GITHUB_REPOSITORY']}.git",
292+ f"HEAD:{target}", reclaim_locks=True)
293+ raise SystemExit(0)
294+ except GitFailure:
295+ # A push failure permits stale/retry decisions only after verified cleanup.
296+ remote_main = git_output(workspace, "rev-parse", f"origin/{target}").rstrip("\n")
297+ if remote_main != base_sha:
298+ print(f"main advanced from {base_sha} to {remote_main}; skipping stale docs update.")
299+ raise SystemExit(0)
300+ print(f"Docs update attempt {attempt} failed; retrying.", flush=True)
301+ backoff(attempt * 2)
302+ print("Failed to push docs updates after retries.", file=sys.stderr)
303+ raise SystemExit(1)
304+ PYTHON
0 commit comments