test: split workflow into parts
This commit is contained in:
@@ -5,7 +5,7 @@ on:
|
|||||||
types: [opened, synchronize, edited, reopened]
|
types: [opened, synchronize, edited, reopened]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-smoke:
|
build-image:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -17,24 +17,47 @@ jobs:
|
|||||||
|
|
||||||
- name: Install uv
|
- name: Install uv
|
||||||
uses: astral-sh/setup-uv@v5
|
uses: astral-sh/setup-uv@v5
|
||||||
- name: Set up Python
|
|
||||||
run: uv python install
|
- name: (optional) Prepare dependencies
|
||||||
with:
|
|
||||||
python-version-file: "pyproject.toml"
|
|
||||||
- name: Install the project dependencies
|
|
||||||
run: |
|
run: |
|
||||||
uv sync --all-groups
|
uv python install --python-version-file pyproject.toml || true
|
||||||
uv add pip
|
uv sync --all-groups || true
|
||||||
uv export --format requirements.txt -o requirements.txt
|
uv add pip || true
|
||||||
# uv run python -m pip install --upgrade pip
|
uv export --format requirements.txt -o requirements.txt || true
|
||||||
# uv run python -m pip install -r requirements.txt
|
|
||||||
- name: Build image
|
- name: Build image
|
||||||
run: |
|
run: |
|
||||||
docker build -t semapform-api:test-pr .
|
docker build -t semapform-api:test-pr .
|
||||||
|
|
||||||
|
- name: Save image artifact
|
||||||
|
run: |
|
||||||
|
docker save semapform-api:test-pr -o semapform-api.tar
|
||||||
|
|
||||||
|
- name: Upload image artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: semapform-image
|
||||||
|
path: semapform-api.tar
|
||||||
|
|
||||||
|
smoke-tests:
|
||||||
|
needs: build-image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Download image artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: semapform-image
|
||||||
|
|
||||||
|
- name: Restore image
|
||||||
|
run: |
|
||||||
|
docker load -i semapform-api.tar
|
||||||
|
|
||||||
- name: Start container (background)
|
- name: Start container (background)
|
||||||
run: |
|
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
|
docker run -d --name semapform-test semapform-api:test-pr sleep infinity
|
||||||
|
|
||||||
- name: Start server in container and smoke test HTTP (in-container)
|
- name: Start server in container and smoke test HTTP (in-container)
|
||||||
@@ -46,30 +69,27 @@ jobs:
|
|||||||
# show container status to aid debugging
|
# show container status to aid debugging
|
||||||
docker ps -a --filter name=semapform-test || true
|
docker ps -a --filter name=semapform-test || true
|
||||||
|
|
||||||
# perform a readiness loop (try container-local /health) using small execs
|
echo "waiting for service to become ready inside container"
|
||||||
echo "waiting for service to become ready inside container"
|
set -e
|
||||||
set -e
|
READY=0
|
||||||
READY=0
|
for i in $(seq 1 20); do
|
||||||
for i in $(seq 1 20); do
|
echo "ready attempt $i"
|
||||||
echo "ready attempt $i"
|
if docker exec semapform-test python -c 'import urllib.request,sys; urllib.request.urlopen("http://127.0.0.1:8001/health", timeout=1); print("ok")' ; then
|
||||||
if docker exec semapform-test python -c 'import urllib.request,sys; urllib.request.urlopen("http://127.0.0.1:8001/health", timeout=1); print("ok")' ; then
|
READY=1
|
||||||
READY=1
|
break
|
||||||
break
|
|
||||||
fi
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
if [ "$READY" -ne 1 ]; then
|
|
||||||
echo "service did not become ready"
|
|
||||||
docker logs semapform-test --tail 200 || true
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
sleep 1
|
||||||
# Run the repository smoke-test script inside the container and surface its output
|
done
|
||||||
echo "running test_api.py inside container"
|
if [ "$READY" -ne 1 ]; then
|
||||||
docker exec semapform-test python test_api.py || true
|
echo "service did not become ready"
|
||||||
|
|
||||||
# dump the last 200 lines of logs so this step always displays useful output
|
|
||||||
docker logs semapform-test --tail 200 || true
|
docker logs semapform-test --tail 200 || true
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "running test_api.py inside container"
|
||||||
|
docker exec semapform-test python test_api.py || true
|
||||||
|
|
||||||
|
docker logs semapform-test --tail 200 || true
|
||||||
|
|
||||||
- name: Cleanup container
|
- name: Cleanup container
|
||||||
if: always()
|
if: always()
|
||||||
|
|||||||
Reference in New Issue
Block a user