From df8c402afb4895f4a57722263e657ce48c74ea22 Mon Sep 17 00:00:00 2001 From: csh Date: Mon, 13 Jul 2026 10:29:23 +0800 Subject: [PATCH] :wrench: chore(ci): scope tsl playbook sync paths --- .gitea/workflows/sync-tsl-playbook.yml | 18 +++++-- test/test_build_tsl_playbook.py | 68 +++++++++++++++++++++----- 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/.gitea/workflows/sync-tsl-playbook.yml b/.gitea/workflows/sync-tsl-playbook.yml index 1f15821a..9886a2be 100644 --- a/.gitea/workflows/sync-tsl-playbook.yml +++ b/.gitea/workflows/sync-tsl-playbook.yml @@ -99,8 +99,13 @@ jobs: python3 "$BUILD_SCRIPT" --output "$bundle" # These are the only paths this workflow owns on the target branch. - generated_paths=(AGENTS.md docs skills) - for path in "${generated_paths[@]}"; do + managed_paths=( + "AGENTS.md" + "docs/tsl" + "skills/tsl-syntax-reference" + "skills/tsl-api-reference" + ) + for path in "${managed_paths[@]}"; do if [ ! -e "$bundle/$path" ]; then echo "ERROR: bundle is missing expected path: $path" >&2 exit 1 @@ -116,10 +121,13 @@ jobs: git rm -rf --cached --quiet . >/dev/null 2>&1 || true fi - rm -rf "${generated_paths[@]}" - cp -R "$bundle"/. "$REPO_DIR"/ + rm -rf -- "${managed_paths[@]}" + for path in "${managed_paths[@]}"; do + mkdir -p "$(dirname "$path")" + cp -R -- "$bundle/$path" "$path" + done - git add -A "${generated_paths[@]}" + git add -A -- "${managed_paths[@]}" if git diff --cached --quiet; then echo "No tsl-playbook changes to publish." diff --git a/test/test_build_tsl_playbook.py b/test/test_build_tsl_playbook.py index b2e25eac..fc3b93ba 100644 --- a/test/test_build_tsl_playbook.py +++ b/test/test_build_tsl_playbook.py @@ -126,8 +126,18 @@ class BuildTslPlaybookTests(unittest.TestCase): text = SYNC_WORKFLOW.read_text(encoding="utf-8") self.assertNotRegex(text, r"git rm -rf --quiet\s+\.") - self.assertIn("generated_paths=(AGENTS.md docs skills)", text) - self.assertIn('git add -A "${generated_paths[@]}"', text) + self.assertIn("managed_paths=(", text) + for path in ( + "AGENTS.md", + "docs/tsl", + "skills/tsl-syntax-reference", + "skills/tsl-api-reference", + ): + self.assertIn(f'"{path}"', text) + self.assertNotIn("generated_paths=(AGENTS.md docs skills)", text) + self.assertIn('rm -rf -- "${managed_paths[@]}"', text) + self.assertIn('git add -A -- "${managed_paths[@]}"', text) + self.assertNotIn('cp -R "$bundle"/. "$REPO_DIR"/', text) self.assertNotIn(".gitea/ci/", text) self.assertNotIn("https://oauth2", text) self.assertNotIn("oauth2:${TOKEN}", text) @@ -145,23 +155,49 @@ class BuildTslPlaybookTests(unittest.TestCase): git(repo, "checkout", "--orphan", "tsl-playbook") git(repo, "rm", "-rf", ".") - (repo / "README.md").write_text( - "manual branch note\n", encoding="utf-8", newline="\n" + unmanaged_files = { + "README.md": "manual branch note\n", + "docs/python/index.md": "manual python docs\n", + "skills/manual-skill/SKILL.md": "manual skill\n", + } + for relative, content in unmanaged_files.items(): + path = repo / relative + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(content, encoding="utf-8", newline="\n") + + stale_managed_files = ( + "docs/tsl/stale.md", + "skills/tsl-syntax-reference/stale.md", + "skills/tsl-api-reference/stale.md", ) - git(repo, "add", "README.md") - git(repo, "commit", "-m", "manual target branch note") + for relative in stale_managed_files: + path = repo / relative + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text("stale\n", encoding="utf-8", newline="\n") + + git(repo, "add", ".") + git(repo, "commit", "-m", "manual target branch content") git(repo, "push", "-u", "origin", "tsl-playbook") git(repo, "checkout", "main") run_sync(repo) - readme = run( - ["git", "show", "HEAD:README.md"], - cwd=repo, - check=False, - ) - self.assertEqual(readme.returncode, 0, msg=readme.stderr) - self.assertEqual(readme.stdout, "manual branch note\n") + for relative, expected in unmanaged_files.items(): + result = run( + ["git", "show", f"HEAD:{relative}"], + cwd=repo, + check=False, + ) + self.assertEqual(result.returncode, 0, msg=result.stderr) + self.assertEqual(result.stdout, expected) + + for relative in stale_managed_files: + result = run( + ["git", "cat-file", "-e", f"HEAD:{relative}"], + cwd=repo, + check=False, + ) + self.assertNotEqual(result.returncode, 0, msg=relative) for path in ( "AGENTS.md", @@ -171,6 +207,12 @@ class BuildTslPlaybookTests(unittest.TestCase): ): git(repo, "cat-file", "-e", f"HEAD:{path}") + first_publish = git(repo, "rev-parse", "HEAD").stdout.strip() + git(repo, "checkout", "main") + run_sync(repo) + second_publish = git(repo, "rev-parse", "HEAD").stdout.strip() + self.assertEqual(second_publish, first_publish) + def test_sync_creates_new_branch_without_source_files(self): if shutil.which("bash") is None: self.skipTest("bash is required to run sync workflow script")