🔧 chore(ci): scope tsl playbook sync paths
This commit is contained in:
@@ -99,8 +99,13 @@ jobs:
|
|||||||
python3 "$BUILD_SCRIPT" --output "$bundle"
|
python3 "$BUILD_SCRIPT" --output "$bundle"
|
||||||
|
|
||||||
# These are the only paths this workflow owns on the target branch.
|
# These are the only paths this workflow owns on the target branch.
|
||||||
generated_paths=(AGENTS.md docs skills)
|
managed_paths=(
|
||||||
for path in "${generated_paths[@]}"; do
|
"AGENTS.md"
|
||||||
|
"docs/tsl"
|
||||||
|
"skills/tsl-syntax-reference"
|
||||||
|
"skills/tsl-api-reference"
|
||||||
|
)
|
||||||
|
for path in "${managed_paths[@]}"; do
|
||||||
if [ ! -e "$bundle/$path" ]; then
|
if [ ! -e "$bundle/$path" ]; then
|
||||||
echo "ERROR: bundle is missing expected path: $path" >&2
|
echo "ERROR: bundle is missing expected path: $path" >&2
|
||||||
exit 1
|
exit 1
|
||||||
@@ -116,10 +121,13 @@ jobs:
|
|||||||
git rm -rf --cached --quiet . >/dev/null 2>&1 || true
|
git rm -rf --cached --quiet . >/dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf "${generated_paths[@]}"
|
rm -rf -- "${managed_paths[@]}"
|
||||||
cp -R "$bundle"/. "$REPO_DIR"/
|
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
|
if git diff --cached --quiet; then
|
||||||
echo "No tsl-playbook changes to publish."
|
echo "No tsl-playbook changes to publish."
|
||||||
|
|||||||
@@ -126,8 +126,18 @@ class BuildTslPlaybookTests(unittest.TestCase):
|
|||||||
text = SYNC_WORKFLOW.read_text(encoding="utf-8")
|
text = SYNC_WORKFLOW.read_text(encoding="utf-8")
|
||||||
|
|
||||||
self.assertNotRegex(text, r"git rm -rf --quiet\s+\.")
|
self.assertNotRegex(text, r"git rm -rf --quiet\s+\.")
|
||||||
self.assertIn("generated_paths=(AGENTS.md docs skills)", text)
|
self.assertIn("managed_paths=(", text)
|
||||||
self.assertIn('git add -A "${generated_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(".gitea/ci/", text)
|
||||||
self.assertNotIn("https://oauth2", text)
|
self.assertNotIn("https://oauth2", text)
|
||||||
self.assertNotIn("oauth2:${TOKEN}", text)
|
self.assertNotIn("oauth2:${TOKEN}", text)
|
||||||
@@ -145,23 +155,49 @@ class BuildTslPlaybookTests(unittest.TestCase):
|
|||||||
|
|
||||||
git(repo, "checkout", "--orphan", "tsl-playbook")
|
git(repo, "checkout", "--orphan", "tsl-playbook")
|
||||||
git(repo, "rm", "-rf", ".")
|
git(repo, "rm", "-rf", ".")
|
||||||
(repo / "README.md").write_text(
|
unmanaged_files = {
|
||||||
"manual branch note\n", encoding="utf-8", newline="\n"
|
"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")
|
for relative in stale_managed_files:
|
||||||
git(repo, "commit", "-m", "manual target branch note")
|
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, "push", "-u", "origin", "tsl-playbook")
|
||||||
|
|
||||||
git(repo, "checkout", "main")
|
git(repo, "checkout", "main")
|
||||||
run_sync(repo)
|
run_sync(repo)
|
||||||
|
|
||||||
readme = run(
|
for relative, expected in unmanaged_files.items():
|
||||||
["git", "show", "HEAD:README.md"],
|
result = run(
|
||||||
cwd=repo,
|
["git", "show", f"HEAD:{relative}"],
|
||||||
check=False,
|
cwd=repo,
|
||||||
)
|
check=False,
|
||||||
self.assertEqual(readme.returncode, 0, msg=readme.stderr)
|
)
|
||||||
self.assertEqual(readme.stdout, "manual branch note\n")
|
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 (
|
for path in (
|
||||||
"AGENTS.md",
|
"AGENTS.md",
|
||||||
@@ -171,6 +207,12 @@ class BuildTslPlaybookTests(unittest.TestCase):
|
|||||||
):
|
):
|
||||||
git(repo, "cat-file", "-e", f"HEAD:{path}")
|
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):
|
def test_sync_creates_new_branch_without_source_files(self):
|
||||||
if shutil.which("bash") is None:
|
if shutil.which("bash") is None:
|
||||||
self.skipTest("bash is required to run sync workflow script")
|
self.skipTest("bash is required to run sync workflow script")
|
||||||
|
|||||||
Reference in New Issue
Block a user