ci(gitea): run planning smoke API requests inside container
DH V2 CI / API · typecheck, tests, build (pull_request) Canceled after 0s
DH V2 CI / WEB · typecheck, build (pull_request) Canceled after 0s
DH V2 CI / Docker / scripts contract (pull_request) Canceled after 0s
Production dependency audit / API · production dependencies (pull_request) Canceled after 0s
Production dependency audit / WEB · production dependencies (pull_request) Canceled after 0s
Android CI / RC / Android · lint, tests, debug APK, release compile (pull_request) Canceled after 4m11s
Inspection planning smoke / F6.1 · real inspection create (pull_request) Successful in 27s
DH V2 CI / API · typecheck, tests, build (pull_request) Canceled after 0s
DH V2 CI / WEB · typecheck, build (pull_request) Canceled after 0s
DH V2 CI / Docker / scripts contract (pull_request) Canceled after 0s
Production dependency audit / API · production dependencies (pull_request) Canceled after 0s
Production dependency audit / WEB · production dependencies (pull_request) Canceled after 0s
Android CI / RC / Android · lint, tests, debug APK, release compile (pull_request) Canceled after 4m11s
Inspection planning smoke / F6.1 · real inspection create (pull_request) Successful in 27s
This commit is contained in:
@@ -126,11 +126,20 @@ INSERT INTO auth_sessions(
|
||||
SQL
|
||||
|
||||
docker compose --env-file .env.example up -d api
|
||||
|
||||
# Gitea Actions runs Docker through DinD: the job container's 127.0.0.1 is
|
||||
# not the Docker daemon host. Probe the API from inside its own container,
|
||||
# matching the main CI contract instead of relying on the published host port.
|
||||
api_health() {
|
||||
docker compose --env-file .env.example exec -T api \
|
||||
node -e 'fetch(`http://127.0.0.1:${process.env.API_PORT}/api/v3/health`).then(async r => { const t = await r.text(); if (!r.ok) { console.error(t); process.exit(1); } }).catch(() => process.exit(1))'
|
||||
}
|
||||
|
||||
for _ in $(seq 1 30); do
|
||||
curl -fsS http://127.0.0.1:3101/api/v3/health >/dev/null 2>&1 && break
|
||||
if api_health >/dev/null 2>&1; then break; fi
|
||||
sleep 2
|
||||
done
|
||||
curl -fsS http://127.0.0.1:3101/api/v3/health >/dev/null
|
||||
api_health >/dev/null
|
||||
|
||||
TOKEN="$(docker compose --env-file .env.example exec -T api node - <<'NODE'
|
||||
const jwt = require('jsonwebtoken');
|
||||
@@ -164,28 +173,29 @@ CONTEXT="$(docker compose --env-file .env.example exec -T db \
|
||||
IFS='|' read -r DEPARTMENT_ID AREA_ID YACIMIENTO_ID COMPANY_ID <<< "$CONTEXT"
|
||||
test -n "$DEPARTMENT_ID" && test -n "$AREA_ID" && test -n "$YACIMIENTO_ID" && test -n "$COMPANY_ID"
|
||||
|
||||
curl -fsS -H "Authorization: Bearer $TOKEN" \
|
||||
http://127.0.0.1:3101/api/v3/inspection-visits/planning-context/departments \
|
||||
>/tmp/dhv2-departments.json
|
||||
api_get() {
|
||||
local request_path="$1"
|
||||
docker compose --env-file .env.example exec -T \
|
||||
-e REQUEST_TOKEN="$TOKEN" -e REQUEST_PATH="$request_path" api \
|
||||
node -e 'fetch(`http://127.0.0.1:${process.env.API_PORT}${process.env.REQUEST_PATH}`, {headers:{Authorization:`Bearer ${process.env.REQUEST_TOKEN}`}}).then(async r => { const t=await r.text(); process.stdout.write(t); if (!r.ok) process.exit(1); }).catch(e => { console.error(e); process.exit(1); })'
|
||||
}
|
||||
|
||||
api_get '/api/v3/inspection-visits/planning-context/departments' >/tmp/dhv2-departments.json
|
||||
grep -Fq "$DEPARTMENT_ID" /tmp/dhv2-departments.json
|
||||
|
||||
curl -fsS -H "Authorization: Bearer $TOKEN" \
|
||||
"http://127.0.0.1:3101/api/v3/inspection-visits/planning-context/departments/$DEPARTMENT_ID/areas" \
|
||||
>/tmp/dhv2-areas.json
|
||||
api_get "/api/v3/inspection-visits/planning-context/departments/$DEPARTMENT_ID/areas" >/tmp/dhv2-areas.json
|
||||
grep -Fq "$AREA_ID" /tmp/dhv2-areas.json
|
||||
|
||||
curl -fsS -H "Authorization: Bearer $TOKEN" \
|
||||
"http://127.0.0.1:3101/api/v3/inspection-visits/planning-context/areas/$AREA_ID/yacimientos" \
|
||||
>/tmp/dhv2-yacimientos.json
|
||||
api_get "/api/v3/inspection-visits/planning-context/areas/$AREA_ID/yacimientos" >/tmp/dhv2-yacimientos.json
|
||||
grep -Fq "$YACIMIENTO_ID" /tmp/dhv2-yacimientos.json
|
||||
|
||||
START_AT="$(date -u -d '+1 day' +'%Y-%m-%dT%H:%M:%S.000Z')"
|
||||
HTTP_CODE="$(curl -sS -o /tmp/dhv2-created.json -w '%{http_code}' \
|
||||
-X POST \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "{\"operationalAreaId\":\"$AREA_ID\",\"scopeAssetId\":\"$YACIMIENTO_ID\",\"operatorCompanyId\":\"$COMPANY_ID\",\"plannedStartAt\":\"$START_AT\",\"leadInspectorUserId\":\"22222222-2222-4222-8222-222222222222\"}" \
|
||||
http://127.0.0.1:3101/api/v3/inspection-visits)"
|
||||
REQUEST_BODY="{\"operationalAreaId\":\"$AREA_ID\",\"scopeAssetId\":\"$YACIMIENTO_ID\",\"operatorCompanyId\":\"$COMPANY_ID\",\"plannedStartAt\":\"$START_AT\",\"leadInspectorUserId\":\"22222222-2222-4222-8222-222222222222\"}"
|
||||
POST_RESULT="$(docker compose --env-file .env.example exec -T \
|
||||
-e REQUEST_TOKEN="$TOKEN" -e REQUEST_BODY="$REQUEST_BODY" api \
|
||||
node -e 'fetch(`http://127.0.0.1:${process.env.API_PORT}/api/v3/inspection-visits`, {method:"POST",headers:{Authorization:`Bearer ${process.env.REQUEST_TOKEN}`,"Content-Type":"application/json"},body:process.env.REQUEST_BODY}).then(async r => process.stdout.write(JSON.stringify({status:r.status,body:await r.text()}))).catch(e => { console.error(e); process.exit(1); })')"
|
||||
HTTP_CODE="$(printf '%s' "$POST_RESULT" | python -c 'import json,sys; print(json.load(sys.stdin)["status"])')"
|
||||
printf '%s' "$POST_RESULT" | python -c 'import json,sys; sys.stdout.write(json.load(sys.stdin)["body"])' >/tmp/dhv2-created.json
|
||||
if [ "$HTTP_CODE" != 201 ]; then
|
||||
echo "ERROR: real inspection create returned HTTP $HTTP_CODE" >&2
|
||||
cat /tmp/dhv2-created.json >&2
|
||||
|
||||
Reference in New Issue
Block a user