#!/usr/bin/env bash # Start a local GitLab Runner for macOS builds (shell executor). # # First-time registration usage: # RUNNER_TOKEN="glrt-..." ./scripts/start-runner-macos.sh # or with a legacy registration token: # REGISTRATION_TOKEN="..." ./scripts/start-runner-macos.sh # # Subsequent runs (once config.toml exists): # ./scripts/start-runner-macos.sh set -euo pipefail if [ "$(uname -s)" != "Darwin" ]; then echo "ERROR: This script is intended for macOS only." >&2 exit 1 fi export PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}" if ! command -v gitlab-runner >/dev/null 2>&1; then if ! command -v brew >/dev/null 2>&1; then echo "ERROR: Homebrew is required to install gitlab-runner. Please install Homebrew from https://brew.sh" >&2 exit 1 fi echo "gitlab-runner not found. Installing via Homebrew..." brew install gitlab-runner fi RUNNER_CONFIG_DIR="${RUNNER_CONFIG_DIR:-$HOME/.gitlab-runner}" CONFIG_FILE="${RUNNER_CONFIG_DIR}/config.toml" RUNNER_WORKDIR="${RUNNER_WORKDIR:-${RUNNER_CONFIG_DIR}/builds}" CI_SERVER_URL="${CI_SERVER_URL:-https://gitlab.com}" RUNNER_NAME="${RUNNER_NAME:-asteria-qt-macos-runner}" RUNNER_TAGS="${RUNNER_TAGS:-macos-qt}" export QT_MACOS_DIR="${QT_MACOS_DIR:-/opt/qt/6.10.3/macos}" if command -v brew >/dev/null 2>&1; then LIBARCHIVE_PREFIX="$(brew --prefix libarchive 2>/dev/null || true)" if [ -n "${LIBARCHIVE_PREFIX}" ] && [ -d "${LIBARCHIVE_PREFIX}/lib/pkgconfig" ]; then export PKG_CONFIG_PATH="${LIBARCHIVE_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH:-}" fi fi mkdir -p "${RUNNER_CONFIG_DIR}" "${RUNNER_WORKDIR}" if [ ! -f "${CONFIG_FILE}" ]; then if [ -n "${RUNNER_TOKEN:-}" ]; then echo "Registering runner with authentication token..." echo "NOTE: Ensure the runner in GitLab has the tag '${RUNNER_TAGS}' assigned." gitlab-runner register \ --non-interactive \ --config "${CONFIG_FILE}" \ --url "${CI_SERVER_URL}" \ --token "${RUNNER_TOKEN}" \ --executor shell \ --shell bash \ --name "${RUNNER_NAME}" elif [ -n "${REGISTRATION_TOKEN:-}" ]; then echo "Registering runner with legacy registration token and tags '${RUNNER_TAGS}'..." gitlab-runner register \ --non-interactive \ --config "${CONFIG_FILE}" \ --url "${CI_SERVER_URL}" \ --registration-token "${REGISTRATION_TOKEN}" \ --executor shell \ --shell bash \ --name "${RUNNER_NAME}" \ --tag-list "${RUNNER_TAGS}" \ --run-untagged="${RUNNER_RUN_UNTAGGED:-false}" \ --locked="${RUNNER_LOCKED:-false}" else echo "ERROR: No runner configuration found at ${CONFIG_FILE}." >&2 echo "Provide RUNNER_TOKEN (glrt-...) or REGISTRATION_TOKEN to register first:" >&2 echo " RUNNER_TOKEN=glrt-... $0" >&2 exit 1 fi fi echo "Starting local macOS GitLab Runner (config: ${CONFIG_FILE}, workdir: ${RUNNER_WORKDIR})..." exec gitlab-runner run --config "${CONFIG_FILE}" --working-directory "${RUNNER_WORKDIR}"