#!/usr/bin/env bash set -euo pipefail # Charge l'env utilisateur si monté if [[ -f "/root/.4nk_template/.env" ]]; then set -a . "/root/.4nk_template/.env" set +a fi MODE="${RUNNER_MODE:-agents}" TARGET_DIR="${TARGET_DIR:-/work}" OUTPUT_DIR="${OUTPUT_DIR:-/work/tests/reports/agents}" # Rendre le dépôt monté sûr pour Git (propriétaire différent dans le conteneur) git config --global --add safe.directory "/work" || true git config --global --add safe.directory "${TARGET_DIR}" || true normalize_scripts() { if command -v dos2unix >/dev/null 2>&1; then find /work/scripts -type f -name "*.sh" -print0 | xargs -0 -r dos2unix -f || true fi find /work/scripts -type f -name "*.sh" -exec chmod +x {} + || true } start_runner() { # Démarre le runner gitea/act_runner (processus au premier plan) # Requiert : GITEA_INSTANCE_URL (BASE_URL), REGISTRATION_TOKEN ou config existante if [[ -n "${BASE_URL:-}" && -n "${REGISTRATION_TOKEN:-}" ]]; then act_runner register --no-interactive \ --instance "$BASE_URL" \ --token "$REGISTRATION_TOKEN" \ --labels "self-hosted,linux" || true fi exec act_runner daemon } run_agents() { normalize_scripts mkdir -p "$OUTPUT_DIR" cd "$TARGET_DIR" /work/scripts/agents/run.sh "$TARGET_DIR" "$OUTPUT_DIR" all || true echo "Rapports disponibles dans $OUTPUT_DIR" >&2 } case "$MODE" in runner) start_runner ;; agents) run_agents ;; both) start_runner & run_agents wait -n || true ;; *) run_agents ;; esac