Test CI Templates / validate-syntax (push) Successful in 10s
Test CI Templates / test-python-code-quality (3.10) (push) Successful in 5s
Test CI Templates / test-python-code-quality (false, true, skip-pyupgrade) (push) Successful in 4s
Test CI Templates / test-python-code-quality (true, false, skip-mypy) (push) Successful in 5s
Test CI Templates / test-python-pytest (false, 3.11) (push) Successful in 6s
Test CI Templates / test-python-pytest (false, 3.12) (push) Successful in 5s
Test CI Templates / test-python-code-quality (3.11) (push) Successful in 4s
Test CI Templates / test-python-code-quality (3.12) (push) Successful in 4s
Test CI Templates / test-python-code-quality (false, false, basic) (push) Successful in 4s
Test CI Templates / test-python-pytest (true, 3.11) (push) Successful in 5s
Test CI Templates / test-python-pytest (true, 3.12) (push) Successful in 4s
Test CI Templates / test-web-formatting (false, false, 18) (push) Successful in 4s
Test CI Templates / test-web-formatting (false, false, 20) (push) Successful in 4s
Test CI Templates / test-web-formatting (false, true, 18) (push) Successful in 4s
Test CI Templates / test-web-formatting (false, true, 20) (push) Successful in 4s
Test CI Templates / test-web-formatting (true, false, 18) (push) Successful in 5s
Test CI Templates / test-web-formatting (true, false, 20) (push) Successful in 5s
Test CI Templates / test-web-formatting (true, true, 18) (push) Successful in 5s
Test CI Templates / test-web-formatting (true, true, 20) (push) Successful in 5s
Test CI Templates / test-monorepo (push) Successful in 6s
Test CI Templates / test-edge-cases (push) Successful in 5s
Test CI Templates / test-results (push) Successful in 2s
494 lines
15 KiB
YAML
494 lines
15 KiB
YAML
---
|
|
name: Test CI Templates
|
|
|
|
"on":
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
schedule:
|
|
- cron: '0 2 * * *' # Run daily at 2 AM
|
|
workflow_dispatch: # Manual trigger
|
|
|
|
jobs:
|
|
validate-syntax:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
|
|
- name: Install yamllint
|
|
run: pip install yamllint
|
|
|
|
- name: Validate YAML syntax
|
|
run: |
|
|
echo "Validating workflow YAML syntax..."
|
|
find .gitea/workflows -name "*.yml" -exec yamllint {} \;
|
|
|
|
- name: Check workflow structure
|
|
run: |
|
|
echo "Checking workflow structure..."
|
|
for file in .gitea/workflows/**/*.yml; do
|
|
# Skip the test file itself
|
|
if [[ "$file" == *"test-templates.yml" ]]; then
|
|
echo "Skipping test file: $file"
|
|
continue
|
|
fi
|
|
echo "Checking $file..."
|
|
if ! grep -q "workflow_call" "$file"; then
|
|
echo "Error: $file is missing workflow_call trigger"
|
|
exit 1
|
|
fi
|
|
if ! grep -q "inputs:" "$file"; then
|
|
echo "Warning: $file has no inputs defined"
|
|
fi
|
|
done
|
|
|
|
test-python-code-quality:
|
|
runs-on: ubuntu-latest
|
|
needs: validate-syntax
|
|
strategy:
|
|
matrix:
|
|
python-version: ["3.10", "3.11", "3.12"]
|
|
include:
|
|
- test-type: "basic"
|
|
skip-mypy: false
|
|
skip-pyupgrade: false
|
|
- test-type: "skip-mypy"
|
|
skip-mypy: true
|
|
skip-pyupgrade: false
|
|
- test-type: "skip-pyupgrade"
|
|
skip-mypy: false
|
|
skip-pyupgrade: true
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Create test Python project
|
|
run: |
|
|
mkdir -p test-project/src/test_package
|
|
cd test-project
|
|
|
|
# Create pyproject.toml
|
|
cat > pyproject.toml << 'EOF'
|
|
[build-system]
|
|
requires = ["hatchling"]
|
|
build-backend = "hatchling.build"
|
|
|
|
[project]
|
|
name = "test-package"
|
|
version = "0.1.0"
|
|
description = "Test package for CI templates"
|
|
dependencies = []
|
|
|
|
[project.optional-dependencies]
|
|
dev = [
|
|
"mypy>=1.0.0",
|
|
"ruff>=0.1.0",
|
|
"pyupgrade>=3.0.0",
|
|
]
|
|
|
|
[tool.ruff]
|
|
line-length = 88
|
|
target-version = "py310"
|
|
|
|
[tool.mypy]
|
|
python_version = "3.10"
|
|
warn_return_any = true
|
|
warn_unused_configs = true
|
|
EOF
|
|
|
|
# Create source code
|
|
cat > src/test_package/__init__.py << 'EOF'
|
|
"""Test package for CI template validation."""
|
|
__version__ = "0.1.0"
|
|
|
|
def hello_world() -> str:
|
|
"""Return a greeting message."""
|
|
return "Hello, World!"
|
|
EOF
|
|
|
|
cat > src/test_package/main.py << 'EOF'
|
|
"""Main module for test package."""
|
|
from typing import List
|
|
|
|
def process_items(items: List[str]) -> List[str]:
|
|
"""Process a list of items."""
|
|
return [item.upper() for item in items]
|
|
|
|
if __name__ == "__main__":
|
|
test_items = ["hello", "world"]
|
|
result = process_items(test_items)
|
|
print(result)
|
|
EOF
|
|
|
|
# NOTE: Cannot test reusable workflows from same repository due to Gitea Actions limitation
|
|
# This test creates the structure but cannot execute the workflow
|
|
- name: Validate Python code quality workflow structure
|
|
run: |
|
|
echo "✅ Test project created successfully"
|
|
echo "✅ Python code quality workflow exists at .gitea/workflows/python/code-quality.yml"
|
|
echo "⚠️ Functional testing requires external repository due to Gitea Actions limitations"
|
|
|
|
# Validate the workflow file can be parsed
|
|
if command -v yq &> /dev/null; then
|
|
echo "Validating workflow structure with yq..."
|
|
yq eval '.jobs.code-quality' .gitea/workflows/python/code-quality.yml > /dev/null
|
|
echo "✅ Workflow structure is valid"
|
|
else
|
|
echo "⚠️ yq not available, skipping detailed structure validation"
|
|
fi
|
|
|
|
test-python-pytest:
|
|
runs-on: ubuntu-latest
|
|
needs: validate-syntax
|
|
strategy:
|
|
matrix:
|
|
python-version: ["3.11", "3.12"]
|
|
coverage: [true, false]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Create test Python project with tests
|
|
run: |
|
|
mkdir -p test-pytest-project/src/test_package
|
|
mkdir -p test-pytest-project/tests
|
|
cd test-pytest-project
|
|
|
|
# Create pyproject.toml
|
|
cat > pyproject.toml << 'EOF'
|
|
[build-system]
|
|
requires = ["hatchling"]
|
|
build-backend = "hatchling.build"
|
|
|
|
[project]
|
|
name = "test-package"
|
|
version = "0.1.0"
|
|
description = "Test package for pytest CI template"
|
|
dependencies = []
|
|
|
|
[project.optional-dependencies]
|
|
test = [
|
|
"pytest>=7.0.0",
|
|
"pytest-cov>=4.0.0",
|
|
]
|
|
|
|
[tool.pytest.ini_options]
|
|
testpaths = ["tests"]
|
|
python_files = ["test_*.py"]
|
|
addopts = ["--strict-markers", "--strict-config"]
|
|
EOF
|
|
|
|
# Create source code
|
|
cat > src/test_package/__init__.py << 'EOF'
|
|
"""Test package for pytest template validation."""
|
|
__version__ = "0.1.0"
|
|
EOF
|
|
|
|
cat > src/test_package/calculator.py << 'EOF'
|
|
"""Simple calculator for testing."""
|
|
|
|
def add(a: float, b: float) -> float:
|
|
"""Add two numbers."""
|
|
return a + b
|
|
|
|
def multiply(a: float, b: float) -> float:
|
|
"""Multiply two numbers."""
|
|
return a * b
|
|
|
|
def divide(a: float, b: float) -> float:
|
|
"""Divide two numbers."""
|
|
if b == 0:
|
|
raise ValueError("Cannot divide by zero")
|
|
return a / b
|
|
EOF
|
|
|
|
# Create tests
|
|
cat > tests/test_calculator.py << 'EOF'
|
|
"""Tests for calculator module."""
|
|
import pytest
|
|
from test_package.calculator import add, multiply, divide
|
|
|
|
def test_add():
|
|
assert add(2, 3) == 5
|
|
assert add(-1, 1) == 0
|
|
assert add(0.1, 0.2) == pytest.approx(0.3)
|
|
|
|
def test_multiply():
|
|
assert multiply(2, 3) == 6
|
|
assert multiply(-2, 3) == -6
|
|
assert multiply(0, 5) == 0
|
|
|
|
def test_divide():
|
|
assert divide(6, 2) == 3
|
|
assert divide(5, 2) == 2.5
|
|
|
|
def test_divide_by_zero():
|
|
with pytest.raises(ValueError, match="Cannot divide by zero"):
|
|
divide(5, 0)
|
|
EOF
|
|
|
|
# NOTE: Cannot test reusable workflows from same repository due to Gitea Actions limitation
|
|
- name: Validate pytest workflow structure
|
|
run: |
|
|
echo "✅ Test project with tests created successfully"
|
|
echo "✅ Python pytest workflow exists at .gitea/workflows/python/pytest.yml"
|
|
echo "⚠️ Functional testing requires external repository due to Gitea Actions limitations"
|
|
|
|
# Validate the workflow file can be parsed
|
|
if command -v yq &> /dev/null; then
|
|
echo "Validating workflow structure with yq..."
|
|
yq eval '.jobs.test' .gitea/workflows/python/pytest.yml > /dev/null
|
|
echo "✅ Workflow structure is valid"
|
|
fi
|
|
|
|
test-web-formatting:
|
|
runs-on: ubuntu-latest
|
|
needs: validate-syntax
|
|
strategy:
|
|
matrix:
|
|
node-version: ["18", "20"]
|
|
check-yaml: [true, false]
|
|
check-json: [true, false]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Create test web project
|
|
run: |
|
|
mkdir -p test-web-project/src/components
|
|
cd test-web-project
|
|
|
|
# Create package.json
|
|
cat > package.json << 'EOF'
|
|
{
|
|
"name": "test-web-project",
|
|
"version": "1.0.0",
|
|
"description": "Test project for web formatting template"
|
|
}
|
|
EOF
|
|
|
|
# Create JavaScript files
|
|
cat > src/index.js << 'EOF'
|
|
// Test JavaScript file for formatting
|
|
const greeting = "Hello, World!";
|
|
|
|
function greet(name) {
|
|
return `Hello, ${name}!`;
|
|
}
|
|
|
|
export { greet };
|
|
EOF
|
|
|
|
cat > src/components/Button.js << 'EOF'
|
|
// Button component
|
|
export default function Button({ children, onClick }) {
|
|
return (
|
|
<button onClick={onClick} className="btn">
|
|
{children}
|
|
</button>
|
|
);
|
|
}
|
|
EOF
|
|
|
|
# Create JSON file
|
|
cat > config.json << 'EOF'
|
|
{
|
|
"name": "test-config",
|
|
"version": "1.0.0",
|
|
"settings": {
|
|
"debug": true,
|
|
"timeout": 5000
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# Create YAML file
|
|
cat > config.yml << 'EOF'
|
|
name: test-config
|
|
version: 1.0.0
|
|
settings:
|
|
debug: true
|
|
timeout: 5000
|
|
features:
|
|
- feature1
|
|
- feature2
|
|
EOF
|
|
|
|
# Create Prettier config
|
|
cat > .prettierrc.json << 'EOF'
|
|
{
|
|
"semi": true,
|
|
"trailingComma": "es5",
|
|
"singleQuote": true,
|
|
"printWidth": 80,
|
|
"tabWidth": 2
|
|
}
|
|
EOF
|
|
|
|
# NOTE: Cannot test reusable workflows from same repository due to Gitea Actions limitation
|
|
- name: Validate web formatting workflow structure
|
|
run: |
|
|
echo "✅ Test web project created successfully"
|
|
echo "✅ Web formatting workflow exists at .gitea/workflows/web/formatting.yml"
|
|
echo "⚠️ Functional testing requires external repository due to Gitea Actions limitations"
|
|
|
|
# Validate the workflow file can be parsed
|
|
if command -v yq &> /dev/null; then
|
|
echo "Validating workflow structure with yq..."
|
|
yq eval '.jobs.formatting' .gitea/workflows/web/formatting.yml > /dev/null
|
|
echo "✅ Workflow structure is valid"
|
|
fi
|
|
|
|
test-monorepo:
|
|
runs-on: ubuntu-latest
|
|
needs: validate-syntax
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Create monorepo structure
|
|
run: |
|
|
mkdir -p monorepo-test/{backend,frontend}
|
|
|
|
# Backend Python project
|
|
cd monorepo-test/backend
|
|
cat > pyproject.toml << 'EOF'
|
|
[build-system]
|
|
requires = ["hatchling"]
|
|
build-backend = "hatchling.build"
|
|
|
|
[project]
|
|
name = "backend-service"
|
|
version = "0.1.0"
|
|
dependencies = []
|
|
|
|
[project.optional-dependencies]
|
|
dev = ["ruff>=0.1.0", "mypy>=1.0.0"]
|
|
EOF
|
|
|
|
mkdir -p src/backend_service
|
|
cat > src/backend_service/__init__.py << 'EOF'
|
|
"""Backend service package."""
|
|
__version__ = "0.1.0"
|
|
EOF
|
|
|
|
# Frontend project
|
|
cd ../frontend
|
|
cat > package.json << 'EOF'
|
|
{
|
|
"name": "frontend-app",
|
|
"version": "1.0.0"
|
|
}
|
|
EOF
|
|
|
|
mkdir -p src
|
|
cat > src/App.js << 'EOF'
|
|
export default function App() {
|
|
return <div>Hello from frontend!</div>;
|
|
}
|
|
EOF
|
|
|
|
# NOTE: Cannot test reusable workflows from same repository due to Gitea Actions limitation
|
|
- name: Validate backend code quality workflow structure
|
|
run: |
|
|
echo "✅ Monorepo backend structure created successfully"
|
|
echo "✅ Python code quality workflow exists at .gitea/workflows/python/code-quality.yml"
|
|
|
|
- name: Validate frontend formatting workflow structure
|
|
run: |
|
|
echo "✅ Monorepo frontend structure created successfully"
|
|
echo "✅ Web formatting workflow exists at .gitea/workflows/web/formatting.yml"
|
|
echo "⚠️ Functional testing requires external repository due to Gitea Actions limitations"
|
|
|
|
test-edge-cases:
|
|
runs-on: ubuntu-latest
|
|
needs: validate-syntax
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Test minimal Python project
|
|
run: |
|
|
mkdir minimal-python
|
|
cd minimal-python
|
|
cat > pyproject.toml << 'EOF'
|
|
[build-system]
|
|
requires = ["hatchling"]
|
|
build-backend = "hatchling.build"
|
|
|
|
[project]
|
|
name = "minimal"
|
|
version = "0.1.0"
|
|
dependencies = []
|
|
EOF
|
|
|
|
mkdir -p src/minimal
|
|
cat > src/minimal/__init__.py << 'EOF'
|
|
pass
|
|
EOF
|
|
|
|
# NOTE: Cannot test reusable workflows from same repository due to Gitea Actions limitation
|
|
- name: Validate minimal configuration workflow structure
|
|
run: |
|
|
echo "✅ Minimal Python project created successfully"
|
|
echo "✅ Python code quality workflow exists at .gitea/workflows/python/code-quality.yml"
|
|
echo "⚠️ Functional testing requires external repository due to Gitea Actions limitations"
|
|
|
|
test-results:
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- test-python-code-quality
|
|
- test-python-pytest
|
|
- test-web-formatting
|
|
- test-monorepo
|
|
- test-edge-cases
|
|
if: always()
|
|
|
|
steps:
|
|
- name: Report test results
|
|
run: |
|
|
echo "## CI Template Test Results" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
|
|
if [ "${{ needs.test-python-code-quality.result }}" == \
|
|
"success" ]; then
|
|
echo "✅ Python Code Quality: PASSED" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "❌ Python Code Quality: FAILED" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
if [ "${{ needs.test-python-pytest.result }}" == "success" ]; then
|
|
echo "✅ Python Pytest: PASSED" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "❌ Python Pytest: FAILED" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
if [ "${{ needs.test-web-formatting.result }}" == "success" ]; then
|
|
echo "✅ Web Formatting: PASSED" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "❌ Web Formatting: FAILED" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
if [ "${{ needs.test-monorepo.result }}" == "success" ]; then
|
|
echo "✅ Monorepo Support: PASSED" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "❌ Monorepo Support: FAILED" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
if [ "${{ needs.test-edge-cases.result }}" == "success" ]; then
|
|
echo "✅ Edge Cases: PASSED" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "❌ Edge Cases: FAILED" >> $GITHUB_STEP_SUMMARY
|
|
fi
|