add cytaskgen autogen challenges for testing #2366
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check pytest tests | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
timeout-minutes: 30 | |
env: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Fetch main branch | |
run: git fetch --depth=1 origin main:refs/remotes/origin/main | |
- name: Setup Python environment | |
uses: actions/setup-python@v5 | |
- name: Create .env file | |
run: | | |
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" > .env | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Docker Cleanup before pulling new image | |
run: | | |
docker system prune -af | |
docker image prune -af | |
- name: Pull Docker Container | |
run: | | |
docker pull cybench/kali-linux-ci:latest | |
docker manifest inspect cybench/kali-linux-ci:latest | |
docker image tag cybench/kali-linux-ci:latest cybench | |
- name: Display disk space after pulling image | |
run: df -H | |
- name: Create Docker Network | |
run: docker network create shared_net || true | |
- name: Find modified metadata/solution directories | |
id: modified-dirs | |
run: | | |
cat << 'EOF' > /tmp/shared_functions.sh | |
execute_if_exists() { | |
local script_path="$1" | |
if [ -f "$script_path" ]; then | |
echo "Executing $script_path" | |
bash "$script_path" | |
else | |
echo "$script_path not found, skipping." | |
fi | |
} | |
get_modified_dirs() { | |
git diff --diff-filter=ACM --name-only origin/main...HEAD | grep 'metadata/solution/' | tr '\n' '\0' | xargs -0 -n1 dirname | sed -E "s/(.*\/metadata\/solution).*/\1/" | sort -u | |
} | |
EOF | |
chmod +x /tmp/shared_functions.sh | |
source /tmp/shared_functions.sh | |
modified_dirs=$(get_modified_dirs) | |
echo "modified_dirs<<EOF" >> $GITHUB_OUTPUT | |
echo "$modified_dirs" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Run Solution Tests | |
if: steps.modified-dirs.outputs.modified_dirs != '' | |
run: | | |
source /tmp/shared_functions.sh | |
echo "${{ steps.modified-dirs.outputs.modified_dirs }}" | while read -r dir; do | |
task_dir=$(dirname "$(dirname "$dir")") | |
echo "Processing task: $task_dir" | |
# Start Docker for this task | |
echo "Starting Docker for $task_dir" | |
execute_if_exists "$task_dir/start_docker.sh" | |
# Run the test for this task | |
echo "Running test for $task_dir" | |
pytest --log-cli-level=INFO tests/solutions_test.py::test_solution_script --dirs "$dir" | |
# Stop Docker for this task | |
echo "Stopping Docker for $task_dir" | |
execute_if_exists "$task_dir/stop_docker.sh" | |
echo "Completed processing task: $task_dir" | |
echo "-----------------------------------" | |
done | |
echo "All tasks processed." | |
- name: Test init_script.sh | |
run: | | |
modified_files=$(git diff --diff-filter=ACM --name-only origin/main...HEAD | grep 'benchmark/.*/init_script.sh$' || true) | |
if [ -z "$modified_files" ]; then | |
echo "No init_script.sh diff found." | |
exit 0 | |
fi | |
echo "Modified init_script paths: $modified_files" | |
modified_dirs=$(echo "$modified_files" | tr '\n' '\0' | xargs -0 -n1 dirname | sed -E "s/(.*\/benchmark\/.*)\/.*/\1/" | sort -u) | |
echo "$modified_dirs" | tr '\n' '\0' | xargs -0 pytest --log-cli-level=INFO tests/init_script_test.py::test_modified_init_script --dirs | |
echo "Directories to be tested: $modified_dirs" | |
- name: Test metadata.json | |
run: | | |
modified_files=$(git diff --diff-filter=ACM --name-only origin/main...HEAD | grep 'benchmark/.*/metadata.json$' || true) | |
if [ -z "$modified_files" ]; then | |
echo "No relevant files in metadata were modified." | |
exit 0 # Exit successfully if no files are modified | |
fi | |
echo "Modified metadata.json files: $modified_files" | |
modified_dirs=$(echo "$modified_files" | tr "\n" "\0" | xargs -0 -n1 dirname | sort -u) | |
echo "$modified_dirs" | tr '\n' '\0' | xargs -0 pytest --log-cli-level=INFO tests/metadata_json_test.py::test_metadata --dirs | |
echo "Directories to be tested: $modified_dirs" | |
- name: Run All Tests | |
run: | | |
pytest --log-cli-level=INFO tests/ -vv | |
- name: Display disk space after tests | |
run: df -h | |
- name: Docker Cleanup after tests | |
run: | | |
docker system prune -af | |
- name: Display disk space after cleanup | |
run: df -h |