fix: feat: restore smoke-init CI pipeline using mock Forgejo (#124) #138

Closed
dev-qwen wants to merge 4 commits from fix/issue-124 into main
2 changed files with 24 additions and 4 deletions
Showing only changes of commit dfedd80d0d - Show all commits

View file

@ -33,6 +33,6 @@ steps:
commands:
- apk add --no-cache bash curl jq git coreutils
- MOCK_FORGE_PORT=3001 python3 tests/mock-forgejo.py > /tmp/mock.log 2>&1 &
# Wait for mock to be ready
- for i in $(seq 1 30); do curl -sf http://localhost:3001/api/v1/version >/dev/null 2>&1 && break || sleep 1; done
- SMOKE_FORGE_URL=http://localhost:3001 FORGE_URL=http://localhost:3001 bash tests/smoke-init.sh
# Wait for mock to be ready (might be on a different port if 3001 is in use)
- for i in $(seq 1 30); do curl -sf http://localhost:$MOCK_FORGE_PORT/api/v1/version >/dev/null 2>&1 && break || sleep 1; done
- SMOKE_FORGE_URL=http://localhost:$MOCK_FORGE_PORT FORGE_URL=http://localhost:$MOCK_FORGE_PORT bash tests/smoke-init.sh

View file

@ -698,11 +698,31 @@ class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
allow_reuse_address = True
def find_free_port(start_port):
"""Find a free port starting from start_port."""
for port in range(start_port, start_port + 100):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("0.0.0.0", port))
s.close()
return port
except OSError:
continue
return start_port
def main():
"""Start the mock server."""
global SHUTDOWN_REQUESTED
port = int(os.environ.get("MOCK_FORGE_PORT", 3000))
base_port = int(os.environ.get("MOCK_FORGE_PORT", 3000))
port = find_free_port(base_port)
# If we found a different port, update the environment variable
if port != base_port:
os.environ["MOCK_FORGE_PORT"] = str(port)
server = ThreadingHTTPServer(("0.0.0.0", port), ForgejoHandler)
print(f"Mock Forgejo server starting on port {port}", file=sys.stderr)