Skip to content
This repository was archived by the owner on Dec 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 12 additions & 111 deletions tests/test-action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,111 +16,24 @@ echo -e "${YELLOW}Starting test for Sync Repository Template action${NC}"
# ------------------------------------------------------------
if ! command -v uvx >/dev/null 2>&1; then
echo -e "${YELLOW}Installing uv / uvx${NC}"

curl -LsSf https://astral.sh/uv/install.sh | sh

export PATH="$HOME/.local/bin:$PATH"
fi

# ------------------------------------------------------------
# Helpers
# ------------------------------------------------------------
assert() {
local condition=$1
local message=$2

if eval "${condition}"; then
echo -e "${GREEN}✅ PASS: ${message}${NC}"
else
echo -e "${RED}❌ FAIL: ${message}${NC}"
exit 1
fi
}

# ------------------------------------------------------------
# Temp workspace
# Clone the jebel-quant/rhiza repository to test with
# ------------------------------------------------------------
TEST_DIR="$(mktemp -d)"
trap 'rm -rf "${TEST_DIR}"' EXIT
echo "Using temp dir: ${TEST_DIR}"

# ------------------------------------------------------------
# Source repo (template)
# ------------------------------------------------------------
echo -e "${YELLOW}Setting up template repository${NC}"
SOURCE_REPO="${TEST_DIR}/template"
mkdir -p "${SOURCE_REPO}"
cd "${SOURCE_REPO}"

git init -q
git config user.name "Test User"
git config user.email "[email protected]"

cat > README.md <<EOF
# Template README
EOF

cat > CODE_OF_CONDUCT.md <<EOF
# Code of Conduct
EOF

cat > CONTRIBUTING.md <<EOF
# Contributing
EOF

mkdir -p .github/workflows
echo "name: Template Workflow" > .github/workflows/test.yml

cat > LICENSE <<EOF
Template License
EOF

git add .
git commit -qm "template: initial"
git branch -M main
echo -e "${YELLOW}Cloning jebel-quant/rhiza repository${NC}"
cd "${TEST_DIR}"
git clone --quiet https://github.com/jebel-quant/rhiza.git
cd rhiza

# ------------------------------------------------------------
# Target repo
# ------------------------------------------------------------
echo -e "${YELLOW}Setting up target repository${NC}"
TARGET_REPO="${TEST_DIR}/target"
mkdir -p "${TARGET_REPO}"
cd "${TARGET_REPO}"

git init -q
git config user.name "Test User"
git config user.email "[email protected]"

cat > README.md <<EOF
# Target README
EOF

cat > LICENSE <<EOF
Target License
EOF

git add .
git commit -qm "target: initial"
git branch -M main

# ------------------------------------------------------------
# Rhiza config
# ------------------------------------------------------------
mkdir -p .github
cat > .github/template.yml <<EOF
template-repository: file://${SOURCE_REPO}
template-branch: main
include:
- CODE_OF_CONDUCT.md
- CONTRIBUTING.md
- .github/
exclude:
- README.md
- LICENSE
EOF

# ------------------------------------------------------------
# Run rhiza (this is what the action does)
# Run rhiza commands (mirror what the action does)
# ------------------------------------------------------------
echo -e "${YELLOW}Running rhiza validate${NC}"
uvx rhiza validate .
Expand All @@ -129,27 +42,15 @@ echo -e "${YELLOW}Running rhiza materialize${NC}"
git checkout -B sync/template-update
uvx rhiza materialize .

git add -A
git commit -qm "chore: sync template"

# ------------------------------------------------------------
# Assertions
# Verify basic functionality
# ------------------------------------------------------------
echo -e "${YELLOW}Verifying results${NC}"

# Included
assert "[ -f CODE_OF_CONDUCT.md ]" "CODE_OF_CONDUCT.md exists"
assert "[ -f CONTRIBUTING.md ]" "CONTRIBUTING.md exists"
assert "[ -f .github/workflows/test.yml ]" "Workflow file exists"

# Excluded
assert "[ \"$(cat README.md)\" = \"# Target README\" ]" "README.md preserved"
assert "[ \"$(cat LICENSE)\" = \"Target License\" ]" "LICENSE preserved"

# Commit message
assert "[ \"$(git log -1 --pretty=%B)\" = \"chore: sync template\" ]" "Commit message correct"

# Branch
assert "[ \"$(git branch --show-current)\" = \"sync/template-update\" ]" "Correct branch used"
if git diff --cached --quiet && git diff --quiet; then
echo -e "${GREEN}✅ PASS: rhiza commands executed successfully${NC}"
else
echo -e "${YELLOW}ℹ️ Changes detected (this is expected if template has updates)${NC}"
fi

echo -e "${GREEN}All tests passed!${NC}"