Skip to content

Commit 4591a08

Browse files
committed
smoketest workflow
1 parent 7c529e0 commit 4591a08

1 file changed

Lines changed: 133 additions & 0 deletions

File tree

.github/workflows/smoketest.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Smoke Test
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
env:
10+
SPARQL_ENDPOINT_INDEX: https://sparql.opencitations.net/index
11+
SPARQL_ENDPOINT_META: https://sparql.opencitations.net/meta
12+
SYNC_ENABLED: "false"
13+
BASE_URL: http://localhost:8080
14+
PREVIEW: "?preview=true"
15+
16+
jobs:
17+
smoketest:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Python 3.11
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.11"
28+
29+
- name: Install uv
30+
uses: astral-sh/setup-uv@v6
31+
32+
- name: Install dependencies
33+
run: uv sync --frozen --no-dev
34+
35+
- name: Start Gunicorn
36+
run: |
37+
uv run gunicorn -c gunicorn.conf.py api_oc:application &
38+
echo "Waiting for server to start..."
39+
for i in $(seq 1 30); do
40+
if curl -s -o /dev/null -w "%{http_code}" ${BASE_URL}/health | grep -q "200"; then
41+
echo "Server is ready!"
42+
break
43+
fi
44+
echo " attempt $i/30..."
45+
sleep 2
46+
done
47+
48+
- name: Run smoke tests
49+
run: |
50+
PASS=0
51+
FAIL=0
52+
TOTAL=0
53+
54+
check() {
55+
local label="$1"
56+
local url="$2"
57+
local expected_code="${3:-200}"
58+
TOTAL=$((TOTAL + 1))
59+
60+
code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 30 "$url")
61+
62+
if [ "$code" == "$expected_code" ]; then
63+
echo " ✓ ${label} → ${code}"
64+
PASS=$((PASS + 1))
65+
else
66+
echo " ✗ ${label} → ${code} (expected ${expected_code})"
67+
FAIL=$((FAIL + 1))
68+
fi
69+
}
70+
71+
echo ""
72+
echo "============================================"
73+
echo " oc-api smoke test"
74+
echo " Target: ${BASE_URL}"
75+
echo "============================================"
76+
77+
# Health
78+
echo ""
79+
echo "[Health]"
80+
check "GET /health" "${BASE_URL}/health"
81+
82+
# Documentation pages
83+
echo ""
84+
echo "[Documentation]"
85+
check "GET /meta/v1 (docs)" "${BASE_URL}/meta/v1${PREVIEW}"
86+
check "GET /index/v1 (docs)" "${BASE_URL}/index/v1${PREVIEW}"
87+
check "GET /index/v2 (docs)" "${BASE_URL}/index/v2${PREVIEW}"
88+
89+
# Meta API v1 operations
90+
echo ""
91+
echo "[Meta API v1]"
92+
check "metadata by DOI" "${BASE_URL}/meta/v1/metadata/doi:10.1007/978-1-4020-9632-7${PREVIEW}"
93+
check "metadata by OMID" "${BASE_URL}/meta/v1/metadata/omid:br/0612058700${PREVIEW}"
94+
check "metadata by ISBN" "${BASE_URL}/meta/v1/metadata/isbn:9781402096327${PREVIEW}"
95+
check "author by ORCID" "${BASE_URL}/meta/v1/author/orcid:0000-0002-8420-0696${PREVIEW}"
96+
check "editor by ORCID" "${BASE_URL}/meta/v1/editor/orcid:0000-0003-2098-4759${PREVIEW}"
97+
98+
# Index API v1 operations
99+
echo ""
100+
echo "[Index API v1]"
101+
check "citation by OCI" "${BASE_URL}/index/v1/citation/06101801781-06180334099${PREVIEW}"
102+
check "citations by DOI" "${BASE_URL}/index/v1/citations/10.1186/1756-8722-6-59${PREVIEW}"
103+
check "references by DOI" "${BASE_URL}/index/v1/references/10.1186/1756-8722-6-59${PREVIEW}"
104+
check "citation-count" "${BASE_URL}/index/v1/citation-count/10.1142/9789812701527_0009${PREVIEW}"
105+
check "reference-count" "${BASE_URL}/index/v1/reference-count/10.1186/1756-8722-6-59${PREVIEW}"
106+
107+
# Index API v2 operations
108+
echo ""
109+
echo "[Index API v2]"
110+
check "citation by OCI" "${BASE_URL}/index/v2/citation/06101801781-06180334099${PREVIEW}"
111+
check "citations by DOI" "${BASE_URL}/index/v2/citations/doi:10.1108/jd-12-2013-0166${PREVIEW}"
112+
check "references by DOI" "${BASE_URL}/index/v2/references/doi:10.7717/peerj-cs.421${PREVIEW}"
113+
check "citation-count" "${BASE_URL}/index/v2/citation-count/doi:10.1108/jd-12-2013-0166${PREVIEW}"
114+
check "reference-count" "${BASE_URL}/index/v2/reference-count/doi:10.7717/peerj-cs.421${PREVIEW}"
115+
check "venue-citation-count" "${BASE_URL}/index/v2/venue-citation-count/issn:0138-9130${PREVIEW}"
116+
117+
# Summary
118+
echo ""
119+
echo "============================================"
120+
if [ $FAIL -eq 0 ]; then
121+
echo " Result: ALL PASSED (${PASS}/${TOTAL})"
122+
else
123+
echo " Result: ${FAIL} FAILED, ${PASS} passed (${TOTAL} total)"
124+
fi
125+
echo "============================================"
126+
echo ""
127+
128+
exit $FAIL
129+
130+
- name: Stop Gunicorn
131+
if: always()
132+
run: |
133+
pkill -f gunicorn || true

0 commit comments

Comments
 (0)