All checks were successful
PR tests / build-and-smoke (pull_request) Successful in 1m43s
feat: add test_api file
76 lines
2.5 KiB
YAML
76 lines
2.5 KiB
YAML
name: PR tests
|
|
|
|
on:
|
|
pull_request:
|
|
types: [opened, synchronize, edited, reopened]
|
|
|
|
jobs:
|
|
build-and-smoke:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v5
|
|
- name: Set up Python
|
|
run: uv python install
|
|
with:
|
|
python-version-file: "pyproject.toml"
|
|
- name: Install the project dependencies
|
|
run: |
|
|
uv sync --all-groups
|
|
uv add pip
|
|
uv export --format requirements.txt -o requirements.txt
|
|
# uv run python -m pip install --upgrade pip
|
|
# uv run python -m pip install -r requirements.txt
|
|
- name: Build image
|
|
run: |
|
|
docker build -t semapform-api:test-pr .
|
|
|
|
- name: Start container (background)
|
|
run: |
|
|
# do NOT bind the container port to the host to avoid port conflicts on the runner
|
|
docker run -d --name semapform-test semapform-api:test-pr sleep infinity
|
|
|
|
- name: Start server in container and smoke test HTTP (in-container)
|
|
run: |
|
|
set -x
|
|
# start the server inside the container (detached)
|
|
docker exec -d semapform-test python api_service.py || true
|
|
|
|
# show container status to aid debugging
|
|
docker ps -a --filter name=semapform-test || true
|
|
|
|
# perform a readiness loop and then run the repo test script to exercise the API
|
|
docker exec semapform-test python - << 'PY'
|
|
import time, urllib.request, sys
|
|
url = 'http://127.0.0.1:8001/health'
|
|
for i in range(20):
|
|
try:
|
|
with urllib.request.urlopen(url, timeout=2) as r:
|
|
print('ready', i, 'status', r.status)
|
|
if 200 <= r.status < 300:
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
print('ready attempt', i, 'failed:', e)
|
|
time.sleep(1)
|
|
print('service did not become ready')
|
|
sys.exit(1)
|
|
PY
|
|
|
|
# Run the repository smoke-test script inside the container and surface its output
|
|
docker exec semapform-test python test_api.py || true
|
|
|
|
# dump the last 200 lines of logs so this step always displays useful output
|
|
docker logs semapform-test --tail 200 || true
|
|
|
|
- name: Cleanup container
|
|
if: always()
|
|
run: |
|
|
docker rm -f semapform-test || true
|