1+ name : ' Test Setup'
2+ description : ' Common setup for detector test workflows'
3+
4+ inputs :
5+ component_name :
6+ description : ' Name of the component being tested (for caching)'
7+ required : true
8+ requirements_files :
9+ description : ' Space-separated list of requirements files to install'
10+ required : true
11+ precommit_paths :
12+ description : ' Space-separated list of paths to check with pre-commit'
13+ required : false
14+ default : ' '
15+ python_version :
16+ description : ' Python version to use'
17+ required : false
18+ default : ' 3.11'
19+ needs_system_deps :
20+ description : ' Whether to install system dependencies (build-essential, wget)'
21+ required : false
22+ default : ' false'
23+
24+ runs :
25+ using : ' composite'
26+ steps :
27+ - name : Set up Python ${{ inputs.python_version }}
28+ uses : actions/setup-python@v5
29+ with :
30+ python-version : ${{ inputs.python_version }}
31+
32+ - name : Generate cache key
33+ id : cache-key
34+ shell : bash
35+ run : |
36+ # Create a hash of all requirements files for cache key
37+ CACHE_KEY="${{ runner.os }}-pip-${{ inputs.component_name }}-"
38+ for file in ${{ inputs.requirements_files }}; do
39+ if [ -f "$file" ]; then
40+ CACHE_KEY="${CACHE_KEY}$(sha256sum $file | cut -d' ' -f1)-"
41+ fi
42+ done
43+ echo "cache_key=${CACHE_KEY%%-}" >> $GITHUB_OUTPUT
44+ echo "cache_restore_keys=${{ runner.os }}-pip-${{ inputs.component_name }}-" >> $GITHUB_OUTPUT
45+
46+ - name : Cache pip dependencies
47+ uses : actions/cache@v4
48+ with :
49+ path : ~/.cache/pip
50+ key : ${{ steps.cache-key.outputs.cache_key }}
51+ restore-keys : |
52+ ${{ steps.cache-key.outputs.cache_restore_keys }}
53+ ${{ runner.os }}-pip-
54+
55+ - name : Install system dependencies
56+ if : inputs.needs_system_deps == 'true'
57+ shell : bash
58+ run : |
59+ sudo apt-get update
60+ sudo apt-get install -y --no-install-recommends \
61+ build-essential \
62+ wget
63+
64+ - name : Install dependencies
65+ shell : bash
66+ run : |
67+ python -m pip install --upgrade pip
68+ # Install test dependencies
69+ pip install pytest-cov
70+ # Install component-specific requirements
71+ for file in ${{ inputs.requirements_files }}; do
72+ if [ -f "$file" ]; then
73+ echo "Installing requirements from $file"
74+ pip install -r "$file"
75+ else
76+ echo "Warning: Requirements file $file not found"
77+ fi
78+ done
79+
80+ - name : Set Python path
81+ shell : bash
82+ run : |
83+ echo "PYTHONPATH=$GITHUB_WORKSPACE/detectors/huggingface:$GITHUB_WORKSPACE/detectors/llm_judge:$GITHUB_WORKSPACE/detectors:$GITHUB_WORKSPACE" >> $GITHUB_ENV
84+
85+ - name : Lint with pre-commit (if available)
86+ if : inputs.precommit_paths != ''
87+ shell : bash
88+ run : |
89+ if [ -f .pre-commit-config.yaml ]; then
90+ # Run pre-commit on specified paths
91+ find ${{ inputs.precommit_paths }} -name '*.py' 2>/dev/null | xargs -r pre-commit run --files
92+ else
93+ echo "No pre-commit config found, skipping linting"
94+ fi
95+ continue-on-error : true
0 commit comments