forked from doe-iri/iri-facility-api-python
-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (124 loc) · 4.85 KB
/
Copy pathapi-validation.yml
File metadata and controls
141 lines (124 loc) · 4.85 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
name: API Validation with Schemathesis
on:
pull_request:
push:
branches: [ main ]
jobs:
schemathesis:
runs-on: ubuntu-latest
steps:
- name: Checkout repository (with demo-adapter submodule)
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout schema validator repository
uses: actions/checkout@v4
with:
repository: doe-iri/iri-facility-api-docs
ref: main
path: schema-validator
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install uv
run: pip install uv
- name: Build the main image
run: docker build --platform=linux/amd64 -t iri-facility-api-base .
# Mount the demo adapter from the examples/demo-adapter submodule so schemathesis runs
# against the PR's main code backed by the demo data.
- name: Run Facility API container (main image + demo adapter submodule)
run: |
docker run -d \
-p 8000:8000 \
--platform=linux/amd64 \
--name iri-facility-api-base \
-v "$GITHUB_WORKSPACE/examples/demo-adapter:/demo-adapter" \
-e PYTHONPATH=/demo-adapter \
-e IRI_API_ADAPTER_facility=demo_adapter.combined.DemoAdapter \
-e IRI_API_ADAPTER_status=demo_adapter.combined.DemoAdapter \
-e IRI_API_ADAPTER_account=demo_adapter.combined.DemoAdapter \
-e IRI_API_ADAPTER_compute=demo_adapter.combined.DemoAdapter \
-e IRI_API_ADAPTER_filesystem=demo_adapter.combined.DemoAdapter \
-e IRI_API_ADAPTER_storage=demo_adapter.combined.DemoAdapter \
-e IRI_API_ADAPTER_task=demo_adapter.combined.DemoAdapter \
-e IRI_IDEMPOTENCY_STORE=demo_adapter.compute.idempotency.InMemoryIdempotencyStore \
-e API_URL_ROOT=http://127.0.0.1:8000 \
-e IRI_API_TOKEN=12345 \
iri-facility-api-base \
sh -c "uv pip install --system 'redis>=7.2.0,<8.0.0' && fastapi run app/main.py --port 8000"
- name: Create venv & install validator dependencies
run: |
uv venv
source .venv/bin/activate
uv pip install -r schema-validator/verification/requirements.txt
- name: Wait for API to be ready
run: |
for i in {1..60}; do
if curl -fs http://127.0.0.1:8000/api/v2/openapi.json; then
echo "API ready"
exit 0
fi
sleep 2
done
echo "API did not start"
exit 1
- name: Run Schemathesis validation (local spec)
id: schemathesis_local
env:
IRI_API_TOKEN: "12345" # This is dummy token for testing (demo adapter)
run: |
set +e
source .venv/bin/activate
python schema-validator/verification/api-validator.py \
--baseurl http://127.0.0.1:8000 \
--schema-url http://127.0.0.1:8000/api/v2/openapi.json \
--report-name schemathesis-local
echo "exitcode=$?" >> $GITHUB_OUTPUT
- name: Run Schemathesis validation (official spec)
id: schemathesis_official
env:
IRI_API_TOKEN: "12345"
run: |
set +e
source .venv/bin/activate
python schema-validator/verification/api-validator.py \
--baseurl http://localhost:8000 \
--schema-url https://raw.githubusercontent.com/doe-iri/iri-facility-api-docs/refs/heads/main/specification-v2/openapi/all_spec_v2.yaml \
--report-name schemathesis-official
echo "exitcode=$?" >> $GITHUB_OUTPUT
- name: Fail if any Schemathesis run failed
if: always()
run: |
if [ "${{ steps.schemathesis_local.outputs.exitcode }}" != "0" ] || \
[ "${{ steps.schemathesis_official.outputs.exitcode }}" != "0" ]; then
echo "One or more Schemathesis validations failed"
exit 1
else
echo "Both Schemathesis validations passed"
fi
- name: Upload Schemathesis report # This only works on git actions
if: always() && env.ACT != 'true'
uses: actions/upload-artifact@v4
with:
if-no-files-found: warn
name: schemathesis-report
path: |
schemathesis-local.html
schemathesis-local.xml
schemathesis-official.html
schemathesis-official.xml
- name: Save Schemathesis reports locally # This only works if run locally with act
if: always() && env.ACT == 'true'
run: |
mkdir -p artifacts
cp schemathesis-local.html schemathesis-local.xml artifacts/ || true
cp schemathesis-official.html schemathesis-official.xml artifacts/ || true
- name: Dump API logs
if: always()
run: docker logs iri-facility-api-base || true
- name: Stop container
if: always()
run: docker stop iri-facility-api-base || true