162 lines
6.8 KiB
YAML
162 lines
6.8 KiB
YAML
|
|
name: Integration Test
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [ "main" ]
|
|
workflow_dispatch: {}
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
# ── Job 1: Platform Conformance ───────────────────────────────────────────
|
|
platform-check:
|
|
name: Platform Conformance
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Validate catalog-info.yaml
|
|
run: |
|
|
if [ ! -f catalog-info.yaml ]; then
|
|
echo "✗ catalog-info.yaml not found"
|
|
exit 1
|
|
fi
|
|
python3 -c "import yaml; list(yaml.safe_load_all(open('catalog-info.yaml')))" 2>/dev/null \
|
|
|| (pip install pyyaml -q && python3 -c "import yaml; list(yaml.safe_load_all(open('catalog-info.yaml')))")
|
|
echo "✓ catalog-info.yaml is valid YAML"
|
|
|
|
- name: Check platform initialized
|
|
run: |
|
|
if [ -f ".platform/initialized.md" ]; then
|
|
echo "✓ Platform initialized"
|
|
else
|
|
echo "⚠ .platform/initialized.md not found — skipping guard"
|
|
fi
|
|
|
|
# ── Job 2: Unit Tests + Container Smoke ───────────────────────────────────
|
|
smoke-test:
|
|
name: Unit Tests + Container Smoke
|
|
runs-on: ubuntu-latest
|
|
needs: platform-check
|
|
timeout-minutes: 20
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Free disk space
|
|
run: |
|
|
docker system prune -f 2>/dev/null || true
|
|
df -h / 2>/dev/null || true
|
|
|
|
- name: Install Docker CLI
|
|
run: command -v docker &>/dev/null || (apt-get update -qq && apt-get install -y docker.io)
|
|
|
|
- name: Build container image
|
|
run: |
|
|
if [ -f Dockerfile ]; then
|
|
docker build -t ci-image:test .
|
|
else
|
|
echo "No Dockerfile found — skipping container smoke test"
|
|
echo "SKIP_SMOKE=true" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Start service and wait for health
|
|
if: env.SKIP_SMOKE != 'true'
|
|
run: |
|
|
CONTAINER_NAME="ci-${GITHUB_RUN_ID}"
|
|
|
|
# Nothing sets CONTAINER_PORT, so this used to be 8080 on every run, for every
|
|
# application. That is fine for Spring Boot and wrong for everything else -- an
|
|
# Express app on 3000 was probed on 8080, found nothing, and failed the smoke test
|
|
# after burning the full 180 second health timeout.
|
|
#
|
|
# score.yaml is the one file in this repository that knows the answer: the agent
|
|
# writes targetPort from the port it detected in the application's own source. So
|
|
# read it, exactly as the health-path probe below discovers its path instead of
|
|
# assuming one. Both defaults stay as a last resort for a repo without a score.yaml.
|
|
PORT="${CONTAINER_PORT:-}"
|
|
if [ -z "${PORT}" ] && [ -f score.yaml ]; then
|
|
PORT=$(grep -oE 'targetPort:[[:space:]]*[0-9]+' score.yaml | head -1 | tr -dc '0-9')
|
|
[ -n "${PORT}" ] && echo "Detected container port ${PORT} from score.yaml"
|
|
fi
|
|
PORT="${PORT:-8080}"
|
|
echo "CONTAINER_NAME=${CONTAINER_NAME}" >> $GITHUB_ENV
|
|
echo "CONTAINER_PORT=${PORT}" >> $GITHUB_ENV
|
|
|
|
docker run -d --name "${CONTAINER_NAME}" -e OTEL_SDK_DISABLED=true ci-image:test
|
|
|
|
for i in $(seq 1 10); do
|
|
CONTAINER_IP=$(docker inspect "${CONTAINER_NAME}" --format '{{.NetworkSettings.IPAddress}}' 2>/dev/null)
|
|
[ -n "${CONTAINER_IP}" ] && break
|
|
sleep 1
|
|
done
|
|
echo "CONTAINER_IP=${CONTAINER_IP}" >> $GITHUB_ENV
|
|
|
|
# This factory renovates arbitrary applications, so it cannot know the health path
|
|
# in advance. The previous hardcoded /health is wrong for the single most likely
|
|
# input: a Spring Boot app serves /actuator/health and 404s on /health, so the
|
|
# smoke test sat through its full 180s timeout against a container that was up and
|
|
# answering the whole time.
|
|
#
|
|
# Probe candidates instead, and settle on whichever answers. `/` is last and is a
|
|
# legitimate result -- it proves the container serves HTTP, which is all this test
|
|
# claims. HEALTH_ENDPOINT still wins if the caller sets it.
|
|
CANDIDATES="${HEALTH_ENDPOINT:-} /actuator/health /health /healthz /health/live /api/health /"
|
|
echo "Probing for a health endpoint on ${CONTAINER_IP}:${PORT} (up to 180s)..."
|
|
DEADLINE=$(($(date +%s) + 180))
|
|
HEALTH_PATH=""
|
|
while [ -z "${HEALTH_PATH}" ]; do
|
|
for c in ${CANDIDATES}; do
|
|
if curl -sf -o /dev/null "http://${CONTAINER_IP}:${PORT}${c}" 2>/dev/null; then
|
|
HEALTH_PATH="$c"; break
|
|
fi
|
|
done
|
|
[ -n "${HEALTH_PATH}" ] && break
|
|
if [ $(date +%s) -ge $DEADLINE ]; then
|
|
echo "Timeout: no candidate path answered (${CANDIDATES})"
|
|
docker logs "${CONTAINER_NAME}" 2>&1 | tail -30
|
|
exit 1
|
|
fi
|
|
if ! docker ps --filter "name=${CONTAINER_NAME}" --format '{{.Status}}' | grep -q Up; then
|
|
echo "Container exited:"
|
|
docker logs "${CONTAINER_NAME}" 2>&1 | tail -30
|
|
exit 1
|
|
fi
|
|
echo " still waiting..."; sleep 3
|
|
done
|
|
echo "HEALTH_PATH=${HEALTH_PATH}" >> $GITHUB_ENV
|
|
echo "✓ Service healthy at ${CONTAINER_IP}:${PORT}${HEALTH_PATH}"
|
|
|
|
- name: Validate health response
|
|
if: env.SKIP_SMOKE != 'true'
|
|
run: |
|
|
curl -sf "http://${CONTAINER_IP}:${CONTAINER_PORT}${HEALTH_PATH}" > /tmp/health.json
|
|
echo "Health response:"
|
|
cat /tmp/health.json
|
|
echo ""
|
|
echo "✓ Container smoke test: PASSED"
|
|
|
|
- name: Cleanup
|
|
if: always()
|
|
run: docker rm -f "ci-${GITHUB_RUN_ID}" 2>/dev/null || true
|
|
|
|
- name: Post commit status
|
|
if: always()
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
JOB_STATUS: ${{ job.status }}
|
|
run: |
|
|
STATE=$([[ "$JOB_STATUS" == "success" ]] && echo "success" || echo "failure")
|
|
DESC=$([[ "$STATE" == "success" ]] && echo "All checks passed" || echo "Some checks failed")
|
|
curl -sf -X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}" \
|
|
-d "{\"state\":\"${STATE}\",\"context\":\"Integration Test / Unit Tests + Container Smoke (workflow_dispatch)\",\"description\":\"${DESC}\"}" \
|
|
|| true
|