Skip to content

try to fix work dire #6

try to fix work dire

try to fix work dire #6

name: test latest docker image (dev) # TODO: change
on:
push:
branches:
- 529_add_docker_testing_action_gcroci2 # TODO: change
jobs:
test_latest_docker_image:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull latest Docker image
run: |
REPO_LOWERCASE=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
docker pull ghcr.io/$REPO_LOWERCASE:latest
- name: Run tests in Docker container
run: |
REPO_LOWERCASE=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
docker run --name test_container -d ghcr.io/$REPO_LOWERCASE:latest tail -f /dev/null
WORK_DIR="/"
echo "Using working directory: $WORK_DIR"
# Copy entire project directory to the container
docker cp . test_container:$WORK_DIR
# Verify the directory structure
echo "Contents of root directory:"
docker exec test_container ls -la $WORK_DIR
echo "Contents of tests directory (if it exists):"
docker exec test_container ls -la $WORK_DIR/tests || echo "No tests directory found"
echo "Contents of data directory (if it exists):"
docker exec test_container ls -la $WORK_DIR/data || echo "No data directory found"
# Print debugging information
echo "Current working directory:"
docker exec -w $WORK_DIR test_container pwd
# Find and print content of a test file
echo "Content of a test file (first 20 lines):"
docker exec test_container find $WORK_DIR -name "test_*.py" -type f | head -n 1 | xargs -I {} docker exec test_container head -n 20 {}
# Install pytest
docker exec test_container pip install pytest
# Find the directory containing test files and run pytest
TEST_DIR=$(docker exec test_container find $WORK_DIR -name "test_*.py" -type f | head -n 1 | xargs dirname)
if [ -n "$TEST_DIR" ]; then
echo "Running pytest in directory: $TEST_DIR"
docker exec -w $TEST_DIR test_container pytest -v
else
echo "No test files found"
fi
# Clean up
docker stop test_container
docker rm test_container
- name: Output test results
if: failure()
run: |
echo "Tests failed. Please check the test output above for more details."