-
Notifications
You must be signed in to change notification settings - Fork 10
64 lines (51 loc) · 2.04 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
61
62
63
64
name: test latest docker image
# Only trigger, when the release workflow succeeded
on:
workflow_run:
workflows: ["Build and upload to PyPI and ghcr.io"]
types:
- completed
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
PROJECT_DIR="/app"
TEST_DIR="$PROJECT_DIR/tests"
echo "Project directory: $PROJECT_DIR"
echo "Tests directory: $TEST_DIR"
# Create project directory and copy tests folder
docker exec test_container mkdir -p $PROJECT_DIR
docker cp tests test_container:$TEST_DIR
# Verify the directory structure
echo "Contents of project directory:"
docker exec test_container ls -la $PROJECT_DIR
echo "Contents of tests directory:"
docker exec test_container ls -la $TEST_DIR
# Install pytest
docker exec test_container pip install pytest
# Run pytest from the project directory
echo "Running pytest from the project directory:"
docker exec -w $PROJECT_DIR test_container python -m pytest tests -v
# 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."