[WIP] Add tests and coverage
This commit is contained in:
+287
@@ -0,0 +1,287 @@
|
||||
# GitLab CI/CD Pipeline for Gallery Generator
|
||||
# Tests container building and runs unit tests inside Apptainer
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
|
||||
variables:
|
||||
CONTAINER_IMAGE: "gallery-generator.sif"
|
||||
APPTAINER_CACHE_DIR: "$CI_PROJECT_DIR/.apptainer-cache"
|
||||
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip-cache"
|
||||
|
||||
# Cache to speed up builds
|
||||
cache:
|
||||
key: "$CI_COMMIT_REF_SLUG"
|
||||
paths:
|
||||
- .apptainer-cache/
|
||||
- .pip-cache/
|
||||
|
||||
# Build the Apptainer container
|
||||
build:container:
|
||||
stage: build
|
||||
image: ubuntu:22.04
|
||||
before_script:
|
||||
# Install Apptainer
|
||||
- apt-get update -qq
|
||||
- apt-get install -y wget
|
||||
- wget -O- http://neuro.debian.net/lists/jammy.us-ca.full | tee /etc/apt/sources.list.d/neurodebian.sources.list
|
||||
- apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com 0xA5D32F012649A5A9
|
||||
- apt-get update -qq
|
||||
- apt-get install -y apptainer
|
||||
# Create cache directory
|
||||
- mkdir -p $APPTAINER_CACHE_DIR
|
||||
script:
|
||||
- echo "Building Apptainer container..."
|
||||
- apptainer --version
|
||||
- apptainer build $CONTAINER_IMAGE Singularity.def
|
||||
- ls -lh $CONTAINER_IMAGE
|
||||
- echo "Container built successfully"
|
||||
artifacts:
|
||||
paths:
|
||||
- $CONTAINER_IMAGE
|
||||
expire_in: 1 hour
|
||||
only:
|
||||
- main
|
||||
- merge_requests
|
||||
- develop
|
||||
|
||||
# Test container build process
|
||||
test:container-build:
|
||||
stage: test
|
||||
image: ubuntu:22.04
|
||||
dependencies:
|
||||
- build:container
|
||||
before_script:
|
||||
# Install Apptainer
|
||||
- apt-get update -qq
|
||||
- apt-get install -y wget
|
||||
- wget -O- http://neuro.debian.net/lists/jammy.us-ca.full | tee /etc/apt/sources.list.d/neurodebian.sources.list
|
||||
- apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com 0xA5D32F012649A5A9
|
||||
- apt-get update -qq
|
||||
- apt-get install -y apptainer python3
|
||||
script:
|
||||
- echo "Testing container build process..."
|
||||
- python3 tests/test_build_container.py
|
||||
only:
|
||||
- main
|
||||
- merge_requests
|
||||
- develop
|
||||
|
||||
# Run tests inside the container with coverage
|
||||
test:unit-tests:
|
||||
stage: test
|
||||
image: ubuntu:22.04
|
||||
dependencies:
|
||||
- build:container
|
||||
before_script:
|
||||
# Install Apptainer
|
||||
- apt-get update -qq
|
||||
- apt-get install -y wget
|
||||
- wget -O- http://neuro.debian.net/lists/jammy.us-ca.full | tee /etc/apt/sources.list.d/neurodebian.sources.list
|
||||
- apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com 0xA5D32F012649A5A9
|
||||
- apt-get update -qq
|
||||
- apt-get install -y apptainer
|
||||
script:
|
||||
- echo "Running unit tests inside container..."
|
||||
- apptainer --version
|
||||
- ls -la $CONTAINER_IMAGE
|
||||
# Test that container works
|
||||
- apptainer exec $CONTAINER_IMAGE python3 --version
|
||||
- apptainer exec $CONTAINER_IMAGE pip list
|
||||
# Run the container test suite
|
||||
- apptainer exec $CONTAINER_IMAGE python3 /src/tests/test_container.py
|
||||
artifacts:
|
||||
reports:
|
||||
junit: test-results.xml
|
||||
when: always
|
||||
only:
|
||||
- main
|
||||
- merge_requests
|
||||
- develop
|
||||
|
||||
# Run automated coverage testing
|
||||
test:coverage:
|
||||
stage: test
|
||||
image: ubuntu:22.04
|
||||
dependencies:
|
||||
- build:container
|
||||
before_script:
|
||||
# Install Apptainer
|
||||
- apt-get update -qq
|
||||
- apt-get install -y wget
|
||||
- wget -O- http://neuro.debian.net/lists/jammy.us-ca.full | tee /etc/apt/sources.list.d/neurodebian.sources.list
|
||||
- apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com 0xA5D32F012649A5A9
|
||||
- apt-get update -qq
|
||||
- apt-get install -y apptainer
|
||||
script:
|
||||
- echo "Running automated coverage analysis..."
|
||||
- apptainer --version
|
||||
- ls -la $CONTAINER_IMAGE
|
||||
# Run automated coverage testing
|
||||
- apptainer exec $CONTAINER_IMAGE python3 /src/tests/run_coverage.py
|
||||
# Extract coverage report from container
|
||||
- apptainer exec $CONTAINER_IMAGE cat /src/coverage.xml > coverage.xml || true
|
||||
- apptainer exec $CONTAINER_IMAGE ls -la /src/coverage_html_report/ || true
|
||||
coverage: '/TOTAL.+?(\d+\.\d+)%/'
|
||||
artifacts:
|
||||
reports:
|
||||
coverage_report:
|
||||
coverage_format: cobertura
|
||||
path: coverage.xml
|
||||
paths:
|
||||
- coverage.xml
|
||||
expire_in: 30 days
|
||||
only:
|
||||
- main
|
||||
- merge_requests
|
||||
- develop
|
||||
|
||||
# Test gallery generation functionality
|
||||
test:gallery-generation:
|
||||
stage: test
|
||||
image: ubuntu:22.04
|
||||
dependencies:
|
||||
- build:container
|
||||
before_script:
|
||||
# Install Apptainer
|
||||
- apt-get update -qq
|
||||
- apt-get install -y wget
|
||||
- wget -O- http://neuro.debian.net/lists/jammy.us-ca.full | tee /etc/apt/sources.list.d/neurodebian.sources.list
|
||||
- apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com 0xA5D32F012649A5A9
|
||||
- apt-get update -qq
|
||||
- apt-get install -y apptainer
|
||||
script:
|
||||
- echo "Testing gallery generation..."
|
||||
# Create test data
|
||||
- mkdir -p test_input
|
||||
- echo "%PDF-1.4" > test_input/test.pdf
|
||||
- echo "title: Test Gallery" > test_input/metadata.yaml
|
||||
# Test the main script
|
||||
- apptainer exec $CONTAINER_IMAGE python3 /src/generate_gallery.py --help || true
|
||||
- echo "Gallery generation test completed"
|
||||
only:
|
||||
- main
|
||||
- merge_requests
|
||||
- develop
|
||||
|
||||
# Performance and integration tests
|
||||
test:performance:
|
||||
stage: test
|
||||
image: ubuntu:22.04
|
||||
dependencies:
|
||||
- build:container
|
||||
before_script:
|
||||
- apt-get update -qq
|
||||
- apt-get install -y wget time
|
||||
- wget -O- http://neuro.debian.net/lists/jammy.us-ca.full | tee /etc/apt/sources.list.d/neurodebian.sources.list
|
||||
- apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com 0xA5D32F012649A5A9
|
||||
- apt-get update -qq
|
||||
- apt-get install -y apptainer
|
||||
script:
|
||||
- echo "Running performance tests..."
|
||||
# Test container startup time
|
||||
- time apptainer exec $CONTAINER_IMAGE python3 -c "print('Container startup test')"
|
||||
# Test memory usage
|
||||
- apptainer exec $CONTAINER_IMAGE python3 -c "
|
||||
import psutil;
|
||||
print(f'Memory usage: {psutil.virtual_memory().percent}%')"
|
||||
- echo "Performance tests completed"
|
||||
only:
|
||||
- main
|
||||
- merge_requests
|
||||
allow_failure: true
|
||||
|
||||
# Security scan (optional)
|
||||
test:security:
|
||||
stage: test
|
||||
image: ubuntu:22.04
|
||||
dependencies:
|
||||
- build:container
|
||||
before_script:
|
||||
- apt-get update -qq
|
||||
- apt-get install -y wget
|
||||
- wget -O- http://neuro.debian.net/lists/jammy.us-ca.full | tee /etc/apt/sources.list.d/neurodebian.sources.list
|
||||
- apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com 0xA5D32F012649A5A9
|
||||
- apt-get update -qq
|
||||
- apt-get install -y apptainer
|
||||
script:
|
||||
- echo "Running basic security checks..."
|
||||
# Check for known vulnerabilities in base image
|
||||
- apptainer exec $CONTAINER_IMAGE python3 -c "
|
||||
import sys;
|
||||
print(f'Python version: {sys.version}');
|
||||
import subprocess;
|
||||
result = subprocess.run(['pip', 'list'], capture_output=True, text=True);
|
||||
print('Installed packages:');
|
||||
print(result.stdout)"
|
||||
- echo "Security scan completed"
|
||||
only:
|
||||
- main
|
||||
- merge_requests
|
||||
allow_failure: true
|
||||
|
||||
# Documentation and examples
|
||||
test:documentation:
|
||||
stage: test
|
||||
image: python:3.11-slim
|
||||
script:
|
||||
- echo "Validating documentation..."
|
||||
- python3 -c "
|
||||
import pathlib;
|
||||
docs = ['README.md', 'tests/README.md', 'Singularity.def'];
|
||||
for doc in docs:
|
||||
if pathlib.Path(doc).exists():
|
||||
print(f'✅ {doc} exists');
|
||||
else:
|
||||
print(f'❌ {doc} missing')"
|
||||
- echo "Documentation validation completed"
|
||||
only:
|
||||
- main
|
||||
- merge_requests
|
||||
|
||||
# Deploy (if needed)
|
||||
deploy:registry:
|
||||
stage: deploy
|
||||
image: ubuntu:22.04
|
||||
dependencies:
|
||||
- build:container
|
||||
before_script:
|
||||
- apt-get update -qq
|
||||
- apt-get install -y wget
|
||||
- wget -O- http://neuro.debian.net/lists/jammy.us-ca.full | tee /etc/apt/sources.list.d/neurodebian.sources.list
|
||||
- apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com 0xA5D32F012649A5A9
|
||||
- apt-get update -qq
|
||||
- apt-get install -y apptainer
|
||||
script:
|
||||
- echo "Deploying container to registry (placeholder)..."
|
||||
- echo "Container size:"
|
||||
- ls -lh $CONTAINER_IMAGE
|
||||
- echo "Container would be pushed to registry here"
|
||||
# Actual deployment would push to a container registry
|
||||
# - apptainer push $CONTAINER_IMAGE oras://registry.example.com/gallery-generator:latest
|
||||
only:
|
||||
- main
|
||||
when: manual
|
||||
|
||||
# Job for creating releases
|
||||
create:release:
|
||||
stage: deploy
|
||||
image: ubuntu:22.04
|
||||
dependencies:
|
||||
- build:container
|
||||
script:
|
||||
- echo "Creating release artifacts..."
|
||||
- mkdir -p release/
|
||||
- cp $CONTAINER_IMAGE release/
|
||||
- cp Singularity.def release/
|
||||
- cp tests/test_container.py release/
|
||||
- echo "Release artifacts created"
|
||||
artifacts:
|
||||
paths:
|
||||
- release/
|
||||
expire_in: 1 week
|
||||
only:
|
||||
- tags
|
||||
when: manual
|
||||
Reference in New Issue
Block a user