Add unit tests, smoke test script, fix CI to debian-host + test job
- tests/test_catalog.py: 5 unit tests for PypiCatalog (fetch, cache, sort prefix, completions) - tests/test_proxy.py: 5 unit tests for BicepProxy (framing, injection, list result, passthrough) - tests/conftest.py: pytest asyncio_mode=auto config - scripts/smoke_test.sh: end-to-end TCP + health smoke test script - .gitea/workflows/ci.yml: split into test + build-and-deploy jobs (test blocks deploy) - runs-on: debian-host (was ubuntu-latest = broken) - test job installs deps + runs pytest before building image - pyproject.toml: [project.optional-dependencies] dev = pytest + pytest-asyncio
This commit is contained in:
@@ -1,64 +1,75 @@
|
||||
name: CI
|
||||
name: Build and Deploy iLSP
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
REGISTRY: registry.i80.dk
|
||||
IMAGE: registry.i80.dk/gitea/ilsp
|
||||
SERVICE_NAME: ilsp
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
test:
|
||||
runs-on: debian-host
|
||||
|
||||
env:
|
||||
PATH: /usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/bin:/snap/bin
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set image tag
|
||||
id: tag
|
||||
run: echo "tag=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"
|
||||
- name: Install Python deps
|
||||
run: pip3 install --break-system-packages "python-lsp-server[all]" lsprotocol pytest pytest-asyncio aiohttp 2>&1 | tail -5
|
||||
|
||||
- name: Run unit tests
|
||||
run: python3 -m pytest tests/ -v
|
||||
|
||||
build-and-deploy:
|
||||
runs-on: debian-host
|
||||
needs: test
|
||||
|
||||
env:
|
||||
PATH: /usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/bin:/snap/bin
|
||||
DOCKER_HOST: unix:///var/run/docker.sock
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: System info
|
||||
run: uname -a && whoami && docker version --format '{{.Server.Version}}'
|
||||
|
||||
- name: Log in to registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
run: |
|
||||
echo "${{ secrets.HARBOR_ROBOT_TOKEN }}" | \
|
||||
docker login registry.i80.dk -u "robot\$gitserver" --password-stdin
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.ref == 'refs/heads/main' }}
|
||||
tags: |
|
||||
${{ env.IMAGE }}:${{ steps.tag.outputs.tag }}
|
||||
${{ env.IMAGE }}:latest
|
||||
cache-from: type=registry,ref=${{ env.IMAGE }}:latest
|
||||
cache-to: type=inline
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
SHA=$(git rev-parse --short HEAD)
|
||||
docker build \
|
||||
-t registry.i80.dk/gitea/ilsp:latest \
|
||||
-t registry.i80.dk/gitea/ilsp:$SHA .
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-and-push
|
||||
if: github.ref == 'refs/heads/main'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set image tag
|
||||
id: tag
|
||||
run: echo "tag=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"
|
||||
- name: Push Docker image
|
||||
run: |
|
||||
SHA=$(git rev-parse --short HEAD)
|
||||
docker push registry.i80.dk/gitea/ilsp:latest
|
||||
docker push registry.i80.dk/gitea/ilsp:$SHA
|
||||
|
||||
- name: Deploy to Nomad
|
||||
run: |
|
||||
scp ilsp.nomad ${{ secrets.DEPLOY_HOST }}:/tmp/ilsp.nomad
|
||||
ssh ${{ secrets.DEPLOY_HOST }} \
|
||||
"NOMAD_ADDR=https://nomad.i80.dk:4646 nomad job run \
|
||||
-var='image_tag=${{ steps.tag.outputs.tag }}' /tmp/ilsp.nomad"
|
||||
nomad job validate ${SERVICE_NAME}.nomad
|
||||
nomad job run ${SERVICE_NAME}.nomad
|
||||
env:
|
||||
NOMAD_ADDR: "https://nomad.i80.dk:4646"
|
||||
|
||||
- name: Health check
|
||||
- name: Wait and verify
|
||||
run: |
|
||||
echo "Waiting for service to come up..."
|
||||
sleep 20
|
||||
curl -sf https://ilsp.i80.dk/health | jq .
|
||||
nomad job status ${SERVICE_NAME}
|
||||
curl -sf http://autobox.i80.dk:2089/health | python3 -m json.tool || true
|
||||
env:
|
||||
NOMAD_ADDR: "https://nomad.i80.dk:4646"
|
||||
|
||||
Reference in New Issue
Block a user