Add 7 and update 2 files
Some checks failed
Test and Publish Templates / test-and-publish (push) Failing after 14s

This commit is contained in:
Your Name
2025-08-24 20:50:58 +12:00
parent f917e8cb4f
commit bedc68373d
9 changed files with 907 additions and 0 deletions

145
test.sh Executable file
View File

@@ -0,0 +1,145 @@
#!/bin/bash
set -e
SCRIPT_DIR=$(dirname "$0")
cd "$SCRIPT_DIR"
function die() {
echo "ERROR: $1" >&2
exit 1
}
function info() {
echo "INFO: $1"
}
function success() {
echo -e "\033[32m✓ $1\033[0m"
}
function warning() {
echo -e "\033[33m⚠ $1\033[0m"
}
# Get list of template directories (exclude hidden directories)
TEMPLATES=$(find . -maxdepth 1 -type d ! -name ".*" ! -name "." | sed 's|^\./||' | grep -v ".gitea")
if [ -z "$TEMPLATES" ]; then
die "No templates found to test"
fi
info "Found templates to test: $(echo $TEMPLATES | tr '\n' ' ')"
FAILED_TESTS=""
SKIPPED_TESTS=""
# Run basic validation tests for each template
for TEMPLATE in $TEMPLATES; do
echo ""
info "Testing template: $TEMPLATE"
# Check if template directory exists
if [ ! -d "$TEMPLATE" ]; then
warning "Template directory $TEMPLATE does not exist, skipping"
SKIPPED_TESTS="$SKIPPED_TESTS $TEMPLATE"
continue
fi
# Check for required scripts
REQUIRED_SCRIPTS="install.sh uninstall.sh start.sh stop.sh status.sh"
MISSING_SCRIPTS=""
for SCRIPT in $REQUIRED_SCRIPTS; do
if [ ! -f "$TEMPLATE/$SCRIPT" ]; then
MISSING_SCRIPTS="$MISSING_SCRIPTS $SCRIPT"
fi
done
if [ -n "$MISSING_SCRIPTS" ]; then
echo " ERROR: Missing required scripts:$MISSING_SCRIPTS"
FAILED_TESTS="$FAILED_TESTS $TEMPLATE"
continue
fi
success "All required scripts present"
# Check if scripts are executable
NON_EXECUTABLE=""
for SCRIPT in $TEMPLATE/*.sh; do
if [ -f "$SCRIPT" ] && [ ! -x "$SCRIPT" ]; then
chmod +x "$SCRIPT"
info "Made $SCRIPT executable"
fi
done
# Check for config directory
if [ ! -d "$TEMPLATE/config" ]; then
echo " ERROR: Missing config directory"
FAILED_TESTS="$FAILED_TESTS $TEMPLATE"
continue
fi
success "Config directory exists"
# Check for service.env file
if [ ! -f "$TEMPLATE/config/service.env" ]; then
echo " ERROR: Missing config/service.env file"
FAILED_TESTS="$FAILED_TESTS $TEMPLATE"
continue
fi
success "service.env file exists"
# Validate shell scripts for basic syntax errors
SYNTAX_ERRORS=""
for SCRIPT in $TEMPLATE/*.sh; do
if [ -f "$SCRIPT" ]; then
if ! bash -n "$SCRIPT" 2>/dev/null; then
SCRIPT_NAME=$(basename "$SCRIPT")
SYNTAX_ERRORS="$SYNTAX_ERRORS $SCRIPT_NAME"
fi
fi
done
if [ -n "$SYNTAX_ERRORS" ]; then
echo " ERROR: Syntax errors in scripts:$SYNTAX_ERRORS"
FAILED_TESTS="$FAILED_TESTS $TEMPLATE"
continue
fi
success "All scripts pass syntax check"
# If we have the ds command available and we're in CI, we could run full tests
# For now, we'll skip integration tests in CI to avoid dependencies
if [ -n "$CI" ]; then
info "Skipping integration tests in CI environment"
else
if which ds >/dev/null 2>&1; then
info "ds command found, could run integration tests (skipping for safety)"
# Uncomment to enable integration tests:
# ./test_template.sh "$TEMPLATE" || FAILED_TESTS="$FAILED_TESTS $TEMPLATE"
else
info "ds command not found, skipping integration tests"
fi
fi
success "Template $TEMPLATE passed all tests"
done
echo ""
echo "========================================"
echo "Test Summary"
echo "========================================"
if [ -n "$SKIPPED_TESTS" ]; then
warning "Skipped templates:$SKIPPED_TESTS"
fi
if [ -n "$FAILED_TESTS" ]; then
echo -e "\033[31m✗ Failed templates:$FAILED_TESTS\033[0m"
exit 1
else
echo -e "\033[32m✓ All templates passed validation tests!\033[0m"
exit 0
fi