-
Notifications
You must be signed in to change notification settings - Fork 10
60 lines (49 loc) · 1.91 KB
/
test-docker-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
# Inspect container filesystem
echo "Container filesystem structure:"
docker exec test_container ls -R /
# Determine the appropriate directory for tests
if docker exec test_container [ -d "/app" ]; then
TEST_DIR="/app/tests"
elif docker exec test_container [ -d "/usr/src/app" ]; then
TEST_DIR="/usr/src/app/tests"
else
TEST_DIR="/tests"
fi
echo "Using test directory: $TEST_DIR"
# Copy tests to the container
docker cp tests test_container:$TEST_DIR
# Install pytest and run tests
docker exec test_container pip install pytest
docker exec -e PYTHONPATH=$TEST_DIR test_container pytest $TEST_DIR
# 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."