-
Notifications
You must be signed in to change notification settings - Fork 0
212 lines (180 loc) · 7.09 KB
/
Copy pathci.yml
File metadata and controls
212 lines (180 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
# ---------------------------------------------------------------------------
# Unit tests — pure Python, no external processes, no Docker.
# Only installs requirements/dev.txt (Flask + strenum + pytest) — the heavy
# converter packages (linkml, mdmodels, …) are not needed because the tests
# inject mock converters and register_converters is a lazy import.
# ---------------------------------------------------------------------------
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python 3.11
uses: actions/setup-python@v6
with:
python-version: "3.11"
cache: pip
cache-dependency-path: requirements/dev.txt
- name: Install test dependencies
run: pip install -r requirements/dev.txt
- name: Run unit tests
run: python -m pytest 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@v6
- name: Set up Java 11
uses: actions/setup-java@v5
with:
java-version: "11"
distribution: temurin
- name: Cache Maven repository
uses: actions/cache@v5
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@v6
with:
node-version: "18"
cache: npm
cache-dependency-path: external_converters/node/package-lock.json
- name: Build sub-packages
run: bash scripts/build_subpackages.sh
- name: Upload build artifacts
uses: actions/upload-artifact@v6
with:
name: converter-artifacts
retention-days: 1
path: |
external_converters/java/converter.jar
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@v6
- name: Download build artifacts
uses: actions/download-artifact@v7
with:
name: converter-artifacts
path: external_converters
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Docker image
uses: docker/build-push-action@v7
with:
context: .
file: deploy/docker/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@v6
- name: Download build artifacts
uses: actions/download-artifact@v7
with:
name: converter-artifacts
path: external_converters
- name: Set lowercase image name
run: |
echo "IMAGE=ghcr.io/$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')/schema-conversion-orchestrator" >> $GITHUB_ENV
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
file: deploy/docker/Dockerfile
push: true
tags: |
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max