update workflows #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| # --------------------------------------------------------------------------- | |
| # Unit tests — pure Python, no external processes, no Docker | |
| # --------------------------------------------------------------------------- | |
| unit-tests: | |
| name: Unit tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python 3.11 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| cache: pip | |
| cache-dependency-path: | | |
| schema-conversion-orchestrator/requirements.txt | |
| schema-conversion-orchestrator/requirements-dev.txt | |
| - name: Install dependencies | |
| run: | | |
| pip install \ | |
| -r schema-conversion-orchestrator/requirements.txt \ | |
| -r schema-conversion-orchestrator/requirements-dev.txt | |
| - name: Run unit tests | |
| run: pytest schema-conversion-orchestrator/tests/ -v --tb=short | |
| # --------------------------------------------------------------------------- | |
| # Build sub-packages (Java JAR + TypeScript dist) | |
| # --------------------------------------------------------------------------- | |
| build-subpackages: | |
| name: Build sub-packages | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Java 11 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "11" | |
| distribution: temurin | |
| - name: Cache Maven repository | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: ${{ runner.os }}-maven- | |
| - name: Set up Node.js 18 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "18" | |
| cache: npm | |
| cache-dependency-path: schema-conversion-orchestrator/external_converters/node/package-lock.json | |
| - name: Build sub-packages | |
| run: bash build_subpackages.sh | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: converter-artifacts | |
| retention-days: 1 | |
| path: | | |
| schema-conversion-orchestrator/external_converters/java/converter.jar | |
| schema-conversion-orchestrator/external_converters/node/dist/ | |
| # --------------------------------------------------------------------------- | |
| # Docker integration test — build image, start service, hit real endpoints | |
| # --------------------------------------------------------------------------- | |
| integration-test: | |
| name: Docker integration test | |
| runs-on: ubuntu-latest | |
| needs: build-subpackages | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: converter-artifacts | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: schema-conversion-orchestrator | |
| file: schema-conversion-orchestrator/Dockerfile | |
| push: false | |
| load: true | |
| tags: schema-converter:ci | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Start service | |
| run: docker run -d -p 5002:5002 --name schema-converter schema-converter:ci | |
| - name: Wait for service to become healthy | |
| run: | | |
| echo "Waiting for service (up to 3 minutes)..." | |
| for i in $(seq 1 36); do | |
| if curl -sf http://localhost:5002/health > /dev/null 2>&1; then | |
| echo "Service healthy after $((i * 5)) seconds" | |
| exit 0 | |
| fi | |
| echo " attempt $i/36 — retrying in 5 s" | |
| sleep 5 | |
| done | |
| echo "Service failed to become healthy" | |
| docker logs schema-converter | |
| exit 1 | |
| - name: Test /health endpoint | |
| run: | | |
| curl -sf http://localhost:5002/health \ | |
| | python3 -c "import sys,json; d=json.load(sys.stdin); assert d['status']=='ok', d" | |
| - name: Test /convert — JsonSchema to LinkMl (direct path) | |
| run: | | |
| RESPONSE=$(curl -sf -X POST http://localhost:5002/convert \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "sourceLanguage": "JsonSchema", | |
| "targetLanguage": "LinkMl", | |
| "schema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"title\":\"Person\",\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"}}}" | |
| }') | |
| echo "$RESPONSE" | python3 -c " | |
| import sys, json | |
| d = json.load(sys.stdin) | |
| assert 'results' in d, f'Missing results key: {d}' | |
| assert len(d['results']) > 0, 'Empty results list' | |
| print('OK — got', len(d['results']), 'result(s)') | |
| " | |
| - name: Test /convert — unknown language returns 400 | |
| run: | | |
| STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://localhost:5002/convert \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"sourceLanguage":"FakeLang","targetLanguage":"LinkMl","schema":"{}"}') | |
| [ "$STATUS" -eq 400 ] || { echo "Expected 400, got $STATUS"; exit 1; } | |
| - name: Test /convert — no path returns 400 | |
| run: | | |
| STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://localhost:5002/convert \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"sourceLanguage":"Mermaid","targetLanguage":"Protobuf","schema":"{}"}') | |
| [ "$STATUS" -eq 400 ] || { echo "Expected 400, got $STATUS"; exit 1; } | |
| - name: Print container logs on failure | |
| if: failure() | |
| run: docker logs schema-converter | |
| # --------------------------------------------------------------------------- | |
| # Publish image to GHCR on every push to main | |
| # --------------------------------------------------------------------------- | |
| publish: | |
| name: Publish Docker image | |
| runs-on: ubuntu-latest | |
| needs: [unit-tests, integration-test] | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: converter-artifacts | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: schema-conversion-orchestrator | |
| file: schema-conversion-orchestrator/Dockerfile | |
| push: true | |
| tags: | | |
| ghcr.io/${{ github.repository_owner }}/schema-conversion-orchestrator:latest | |
| ghcr.io/${{ github.repository_owner }}/schema-conversion-orchestrator:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |