fix(ci): kill stale platform-server before binding port 8080 #1046

Closed
core-devops wants to merge 1 commits from fix/e2e-api-port-collision into main

View File

@ -242,6 +242,28 @@ jobs:
if: needs.detect-changes.outputs.api == 'true'
working-directory: workspace-server
run: go build -o platform-server ./cmd/server
- name: Free port 8080 before start
if: needs.detect-changes.outputs.api == 'true'
run: |
# Kill any stale platform-server from a previous run that failed to
# clean up (e.g. runner was cancelled before the Stop step ran).
# Concurrent runs on the same host-network runner all bind :8080.
# Try curl first (cheap), kill if port is occupied.
if curl -sf http://127.0.0.1:8080/health > /dev/null 2>&1; then
echo "Port 8080 in use — killing stale platform-server"
# /proc scan — works on any Linux without pkill/lsof/ss.
# comm field is truncated to 15 chars: "platform-serve" matches.
# shellcheck disable=SC2013
for pid in $(grep -l "platform-serve" /proc/[0-9]*/comm 2>/dev/null); do
kpid="${pid%/comm}"
kpid="${kpid##*/}"
echo "Killing stale process $kpid"
kill "$kpid" 2>/dev/null || true
done
sleep 2 # Wait for port to release.
else
echo "Port 8080 is free"
fi
- name: Start platform (background)
if: needs.detect-changes.outputs.api == 'true'
working-directory: workspace-server