98 lines
2.7 KiB
YAML
98 lines
2.7 KiB
YAML
name: PR tests
|
|
|
|
on:
|
|
pull_request:
|
|
types: [opened, synchronize, edited, reopened]
|
|
|
|
jobs:
|
|
build-image:
|
|
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: (optional) Prepare dependencies
|
|
run: |
|
|
uv python install --python-version-file pyproject.toml || true
|
|
uv sync --all-groups || true
|
|
uv add pip || true
|
|
uv export --format requirements.txt -o requirements.txt || true
|
|
|
|
- name: Build image
|
|
run: |
|
|
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: https://github.com/christopherHX/gitea-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: christopherhx/gitea-download-artifact@v4
|
|
with:
|
|
name: semapform-image
|
|
|
|
- name: Restore image
|
|
run: |
|
|
docker load -i semapform-api.tar
|
|
|
|
- name: Start container (background)
|
|
run: |
|
|
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
|
|
|
|
echo "waiting for service to become ready inside container"
|
|
set -e
|
|
READY=0
|
|
for i in $(seq 1 20); do
|
|
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
|
|
READY=1
|
|
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
|
|
|
|
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
|
|
if: always()
|
|
run: |
|
|
docker rm -f semapform-test || true
|