|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +TUIST_REPOSITORY_ROOT="$( |
| 4 | + cd "$(dirname "${BASH_SOURCE[0]}")/../.." >/dev/null 2>&1 |
| 5 | + pwd -P |
| 6 | +)" |
| 7 | +TUIST_CACHE_SOCKET_PATH="${TUIST_CACHE_SOCKET_PATH:-${XDG_STATE_HOME:-$HOME/.local/state}/tuist/OpenSwiftUIProject_openattributegraph.sock}" |
| 8 | + |
| 9 | +tuist_cache_service_is_ready() { |
| 10 | + [[ -S "$TUIST_CACHE_SOCKET_PATH" ]] || return 1 |
| 11 | + |
| 12 | + if command -v lsof >/dev/null 2>&1; then |
| 13 | + lsof "$TUIST_CACHE_SOCKET_PATH" >/dev/null 2>&1 |
| 14 | + fi |
| 15 | +} |
| 16 | + |
| 17 | +tuist_wait_for_cache_service() { |
| 18 | + local attempt |
| 19 | + for ((attempt = 0; attempt < 40; attempt++)); do |
| 20 | + if tuist_cache_service_is_ready; then |
| 21 | + return 0 |
| 22 | + fi |
| 23 | + sleep 0.25 |
| 24 | + done |
| 25 | + |
| 26 | + echo "Tuist cache service is not listening at $TUIST_CACHE_SOCKET_PATH." >&2 |
| 27 | + echo "If Tuist reported a different socket, set TUIST_CACHE_SOCKET_PATH to that path." >&2 |
| 28 | + return 69 |
| 29 | +} |
| 30 | + |
| 31 | +tuist_ci_setup() ( |
| 32 | + set -e |
| 33 | + |
| 34 | + cd "$TUIST_REPOSITORY_ROOT" |
| 35 | + mise trust mise.toml |
| 36 | + mise install |
| 37 | + mise exec -- tuist auth login |
| 38 | + mise exec -- tuist setup cache --path "$TUIST_REPOSITORY_ROOT" |
| 39 | + tuist_wait_for_cache_service |
| 40 | +) |
| 41 | + |
| 42 | +tuist_xcodebuild() ( |
| 43 | + set -e |
| 44 | + |
| 45 | + if [[ $# -lt 2 ]]; then |
| 46 | + echo "Usage: tuist_xcodebuild <result-bundle.xcresult> <action> [arguments ...]" >&2 |
| 47 | + return 64 |
| 48 | + fi |
| 49 | + |
| 50 | + local result_bundle_path="$1" |
| 51 | + local action="$2" |
| 52 | + shift 2 |
| 53 | + |
| 54 | + if [[ -z "$result_bundle_path" || "$result_bundle_path" != *.xcresult ]]; then |
| 55 | + echo "Tuist result bundle path must end in .xcresult: $result_bundle_path" >&2 |
| 56 | + return 64 |
| 57 | + fi |
| 58 | + |
| 59 | + if [[ "$result_bundle_path" != /* ]]; then |
| 60 | + result_bundle_path="$PWD/$result_bundle_path" |
| 61 | + fi |
| 62 | + |
| 63 | + local cache_settings=() |
| 64 | + if tuist_cache_service_is_ready; then |
| 65 | + cache_settings=( |
| 66 | + COMPILATION_CACHE_ENABLE_CACHING=YES |
| 67 | + "COMPILATION_CACHE_REMOTE_SERVICE_PATH=$TUIST_CACHE_SOCKET_PATH" |
| 68 | + COMPILATION_CACHE_ENABLE_PLUGIN=YES |
| 69 | + COMPILATION_CACHE_ENABLE_DIAGNOSTIC_REMARKS=YES |
| 70 | + ) |
| 71 | + elif [[ -n "${CI:-}" ]]; then |
| 72 | + echo "Tuist cache service is unavailable at $TUIST_CACHE_SOCKET_PATH." >&2 |
| 73 | + return 69 |
| 74 | + else |
| 75 | + echo "Tuist cache service is unavailable; building without compilation caching." >&2 |
| 76 | + echo "Run 'mise exec -- tuist setup cache' to enable it locally." >&2 |
| 77 | + cache_settings=( |
| 78 | + COMPILATION_CACHE_ENABLE_CACHING=NO |
| 79 | + COMPILATION_CACHE_ENABLE_PLUGIN=NO |
| 80 | + ) |
| 81 | + fi |
| 82 | + |
| 83 | + rm -rf "$result_bundle_path" |
| 84 | + mise exec -- tuist xcodebuild "$action" \ |
| 85 | + -resultBundlePath "$result_bundle_path" \ |
| 86 | + "$@" \ |
| 87 | + "${cache_settings[@]}" |
| 88 | +) |
0 commit comments