🔧 chore(ci): inline skill sync and standardize git identity
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import textwrap
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
@@ -10,6 +11,7 @@ from pathlib import Path
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
MANIFEST = ROOT / ".gitea" / "ci" / "thirdparty_skills.json"
|
||||
WORKFLOW = ROOT / ".gitea" / "workflows" / "update-thirdparty-skills.yml"
|
||||
TSL_SYNC_WORKFLOW = ROOT / ".gitea" / "workflows" / "sync-tsl-playbook.yml"
|
||||
LEGACY_WORKFLOW = ROOT / ".gitea" / "workflows" / "update-thirdparty-superpowers.yml"
|
||||
UPDATE_SCRIPT = ROOT / ".gitea" / "ci" / "update_thirdparty_skills.sh"
|
||||
SYNC_SCRIPT = ROOT / ".gitea" / "ci" / "sync_thirdparty_skills.sh"
|
||||
@@ -44,6 +46,16 @@ def run_command(*args: str, cwd: Path | None = None) -> subprocess.CompletedProc
|
||||
)
|
||||
|
||||
|
||||
def extract_workflow_region(name: str) -> str:
|
||||
text = WORKFLOW.read_text(encoding="utf-8")
|
||||
begin = f"# BEGIN {name}"
|
||||
end = f"# END {name}"
|
||||
if begin not in text or end not in text:
|
||||
raise AssertionError(f"workflow region markers not found: {name}")
|
||||
body = text.split(begin, 1)[1].split(end, 1)[0]
|
||||
return textwrap.dedent(body).strip() + "\n"
|
||||
|
||||
|
||||
class ThirdpartySkillsPipelineTests(unittest.TestCase):
|
||||
def test_manifest_declares_all_thirdparty_sources(self):
|
||||
data = load_manifest()
|
||||
@@ -137,14 +149,18 @@ class ThirdpartySkillsPipelineTests(unittest.TestCase):
|
||||
superpowers = next(item for item in data["sources"] if item["id"] == "superpowers")
|
||||
self.assertEqual(superpowers["remove_paths"], ["skills/ui-ux-pro-max"])
|
||||
|
||||
def test_workflow_uses_generic_scripts_and_single_serial_job(self):
|
||||
def test_workflow_inlines_update_and_sync_in_single_serial_job(self):
|
||||
text = WORKFLOW.read_text(encoding="utf-8")
|
||||
self.assertFalse(LEGACY_WORKFLOW.exists())
|
||||
self.assertFalse(UPDATE_SCRIPT.exists())
|
||||
self.assertFalse(SYNC_SCRIPT.exists())
|
||||
self.assertIn("update_and_sync:", text)
|
||||
self.assertNotIn("\n update:\n", text)
|
||||
self.assertNotIn("\n sync:\n", text)
|
||||
self.assertIn("bash .gitea/ci/update_thirdparty_skills.sh", text)
|
||||
self.assertIn("bash .gitea/ci/sync_thirdparty_skills.sh", text)
|
||||
self.assertIn("# BEGIN update_thirdparty_snapshots", text)
|
||||
self.assertIn("# BEGIN sync_thirdparty_skills", text)
|
||||
self.assertNotIn("update_thirdparty_skills.sh", text)
|
||||
self.assertNotIn("sync_thirdparty_skills.sh", text)
|
||||
self.assertNotIn("git merge", text)
|
||||
self.assertNotIn("git pull", text)
|
||||
|
||||
@@ -153,19 +169,30 @@ class ThirdpartySkillsPipelineTests(unittest.TestCase):
|
||||
self.assertIn("concurrency:", text)
|
||||
self.assertIn("update-thirdparty-${{ github.repository }}", text)
|
||||
self.assertIn('MANIFEST_PATH: ".gitea/ci/thirdparty_skills.json"', text)
|
||||
self.assertIn('TARGET_BRANCH="$THIRDPARTY_BRANCH" bash .gitea/ci/update_thirdparty_skills.sh', text)
|
||||
self.assertIn('TARGET_BRANCH="main" \\', text)
|
||||
self.assertIn('MANIFEST_PATH="$MANIFEST_PATH" \\', text)
|
||||
self.assertIn("update_thirdparty_snapshots", text)
|
||||
self.assertIn("sync_thirdparty_skills", text)
|
||||
|
||||
def test_generic_scripts_exist_and_use_manifest(self):
|
||||
update_text = UPDATE_SCRIPT.read_text(encoding="utf-8")
|
||||
sync_text = SYNC_SCRIPT.read_text(encoding="utf-8")
|
||||
self.assertIn('MANIFEST_PATH="${MANIFEST_PATH:-.gitea/ci/thirdparty_skills.json}"', update_text)
|
||||
self.assertIn('MANIFEST_PATH="${MANIFEST_PATH:-.gitea/ci/thirdparty_skills.json}"', sync_text)
|
||||
self.assertIn('TARGET_BRANCH="${TARGET_BRANCH:-thirdparty/skill}"', update_text)
|
||||
self.assertIn('TARGET_BRANCH="${TARGET_BRANCH:-main}"', sync_text)
|
||||
self.assertIn(':package: deps(thirdparty): update snapshots', update_text)
|
||||
self.assertIn(':package: deps(skills): sync thirdparty skills', sync_text)
|
||||
def test_inline_workflow_exposes_manifest_and_publish_contract(self):
|
||||
text = WORKFLOW.read_text(encoding="utf-8")
|
||||
self.assertIn('MANIFEST_PATH="${MANIFEST_PATH:-.gitea/ci/thirdparty_skills.json}"', text)
|
||||
self.assertIn('TARGET_BRANCH="${TARGET_BRANCH:-thirdparty/skill}"', text)
|
||||
self.assertIn('TARGET_BRANCH="${TARGET_BRANCH:-main}"', text)
|
||||
self.assertIn(':package: deps(thirdparty): update snapshots', text)
|
||||
self.assertIn(':package: deps(skills): sync thirdparty skills', text)
|
||||
self.assertIn('git push origin "$TARGET_BRANCH"', text)
|
||||
|
||||
def test_ci_committers_share_explicit_git_identity(self):
|
||||
workflow_text = TSL_SYNC_WORKFLOW.read_text(encoding="utf-8")
|
||||
thirdparty_text = WORKFLOW.read_text(encoding="utf-8")
|
||||
|
||||
for text in (workflow_text, thirdparty_text):
|
||||
self.assertIn('GIT_USER_NAME: "ci[bot]"', text)
|
||||
self.assertIn('GIT_USER_EMAIL: "ci[bot]@tinysoft.com.cn"', text)
|
||||
self.assertIn('git config user.name "$GIT_USER_NAME"', text)
|
||||
self.assertIn('git config user.email "$GIT_USER_EMAIL"', text)
|
||||
self.assertNotIn("COMMIT_AUTHOR_NAME", text)
|
||||
self.assertNotIn("COMMIT_AUTHOR_EMAIL", text)
|
||||
self.assertNotIn("@local", text)
|
||||
|
||||
def test_skills_doc_points_to_generic_thirdparty_sources(self):
|
||||
text = SKILLS_MD.read_text(encoding="utf-8")
|
||||
@@ -193,8 +220,8 @@ class ThirdpartySkillsPipelineTests(unittest.TestCase):
|
||||
self.assertTrue((UI_UX_PRO_MAX_DIR / "data").is_dir())
|
||||
self.assertTrue((UI_UX_PRO_MAX_DIR / "scripts").is_dir())
|
||||
|
||||
def test_update_script_materializes_manifest_before_target_checkout(self):
|
||||
text = UPDATE_SCRIPT.read_text(encoding="utf-8")
|
||||
def test_inline_update_materializes_manifest_before_target_checkout(self):
|
||||
text = WORKFLOW.read_text(encoding="utf-8")
|
||||
self.assertIn('manifest_copy="$tmp_dir/thirdparty_skills.json"', text)
|
||||
self.assertIn('cp "$MANIFEST_PATH" "$manifest_copy"', text)
|
||||
self.assertIn('MANIFEST_PATH="$manifest_copy"', text)
|
||||
@@ -208,8 +235,8 @@ class ThirdpartySkillsPipelineTests(unittest.TestCase):
|
||||
text.index('git checkout -B "$TARGET_BRANCH" "origin/$TARGET_BRANCH"'),
|
||||
)
|
||||
|
||||
def test_sync_script_assumes_thirdparty_snapshot_is_already_clean(self):
|
||||
text = SYNC_SCRIPT.read_text(encoding="utf-8")
|
||||
def test_inline_sync_assumes_thirdparty_snapshot_is_already_clean(self):
|
||||
text = WORKFLOW.read_text(encoding="utf-8")
|
||||
self.assertIn('"\\x1f".join(', text)
|
||||
self.assertIn("while IFS=$'\\x1f' read -r", text)
|
||||
self.assertIn("include_skill_dirs", text)
|
||||
@@ -218,7 +245,7 @@ class ThirdpartySkillsPipelineTests(unittest.TestCase):
|
||||
self.assertNotIn("exclude_skill_dirs", text)
|
||||
self.assertNotIn("is_excluded_skill_dir", text)
|
||||
|
||||
def test_sync_script_generates_karpathy_outputs_in_temp_repo(self):
|
||||
def test_inline_sync_generates_karpathy_outputs_in_temp_repo(self):
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
tmp_root = Path(tmp_dir)
|
||||
mirror = tmp_root / "origin.git"
|
||||
@@ -265,9 +292,30 @@ class ThirdpartySkillsPipelineTests(unittest.TestCase):
|
||||
json.dumps(manifest_data, indent=2) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
shutil.copy2(SYNC_SCRIPT, work / ".gitea" / "ci" / "sync_thirdparty_skills.sh")
|
||||
|
||||
sync_result = run_command("bash", ".gitea/ci/sync_thirdparty_skills.sh", cwd=work)
|
||||
sync_script = extract_workflow_region("sync_thirdparty_skills")
|
||||
script_path = work / ".sync-thirdparty-test.sh"
|
||||
script_path.write_text(
|
||||
'export GIT_USER_NAME="test"\n'
|
||||
'export GIT_USER_EMAIL="test@example.invalid"\n'
|
||||
+ sync_script,
|
||||
encoding="utf-8",
|
||||
newline="\n",
|
||||
)
|
||||
env = os.environ.copy()
|
||||
env.update(
|
||||
{
|
||||
"REPO_DIR": str(work),
|
||||
"THIRDPARTY_BRANCH": "thirdparty/skill",
|
||||
"MANIFEST_PATH": ".gitea/ci/thirdparty_skills.json",
|
||||
}
|
||||
)
|
||||
sync_result = subprocess.run(
|
||||
["bash", script_path.name],
|
||||
cwd=work,
|
||||
env=env,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
sync_result.returncode,
|
||||
0,
|
||||
|
||||
Reference in New Issue
Block a user