Louis Dionne | cc7d084 | 2020-10-06 14:13:55 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # This simple script can be used to set up a CI node running MacOS. |
| 4 | # An additional requirement that is *not* handled by this script is the |
| 5 | # installation of Xcode, which requires manual intervention. |
Louis Dionne | 2c7a3b5 | 2021-07-13 13:07:45 -0400 | [diff] [blame] | 6 | # |
Louis Dionne | 51fc0b3 | 2021-07-16 11:37:16 -0400 | [diff] [blame] | 7 | # This script should first be run from an administrator account to install |
| 8 | # the dependencies necessary for running CI. It can be run without having |
| 9 | # to clone the LLVM repository with: |
Louis Dionne | 2c7a3b5 | 2021-07-13 13:07:45 -0400 | [diff] [blame] | 10 | # |
| 11 | # $ /bin/bash -c "$(curl -fsSl https://raw.githubusercontent.com/llvm/llvm-project/main/libcxx/utils/ci/macos-ci-setup)" |
| 12 | # |
| 13 | # Once the necessary dependencies have been installed, you can switch |
Louis Dionne | 51fc0b3 | 2021-07-16 11:37:16 -0400 | [diff] [blame] | 14 | # to a non-administrator account and run the script again, passing the |
| 15 | # --setup-launchd argument. That will install a Launchd agent to run the |
| 16 | # BuildKite agent whenever the current user is logged in. You should enable |
| 17 | # automatic login for that user, so that if the CI node goes down, the user |
| 18 | # is logged back in automatically when the node goes up again, and the |
| 19 | # BuildKite agent starts automatically. |
| 20 | # |
| 21 | # Alternatively, you can simply run the BuildKite agent by hand using: |
Louis Dionne | 2c7a3b5 | 2021-07-13 13:07:45 -0400 | [diff] [blame] | 22 | # |
| 23 | # $ caffeinate -s buildkite-agent start --build-path /tmp/buildkite-builds |
Louis Dionne | cc7d084 | 2020-10-06 14:13:55 -0400 | [diff] [blame] | 24 | |
Louis Dionne | af413c5 | 2021-07-12 15:44:28 -0400 | [diff] [blame] | 25 | set -e |
| 26 | |
Louis Dionne | 51fc0b3 | 2021-07-16 11:37:16 -0400 | [diff] [blame] | 27 | # Install a Launchd agent that will automatically start the BuildKite agent at login |
| 28 | if [[ ${1} == "--setup-launchd" ]]; then |
| 29 | HOMEBREW_PREFIX="$(brew --prefix)" |
Louis Dionne | d87ccde | 2021-07-16 11:46:47 -0400 | [diff] [blame^] | 30 | mkdir -p ~/Library/LaunchAgents |
Louis Dionne | 51fc0b3 | 2021-07-16 11:37:16 -0400 | [diff] [blame] | 31 | cat <<EOF > ~/Library/LaunchAgents/libcxx.buildkite-agent.plist |
| 32 | <?xml version="1.0" encoding="UTF-8"?> |
| 33 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 34 | <plist version="1.0"> |
| 35 | <dict> |
| 36 | <key>Label</key> |
| 37 | <string>libcxx.buildkite-agent</string> |
| 38 | |
| 39 | <key>ProgramArguments</key> |
| 40 | <array> |
| 41 | <string>${HOMEBREW_PREFIX}/bin/buildkite-agent</string> |
| 42 | <string>start</string> |
| 43 | <string>--build-path</string> |
| 44 | <string>${HOME}/libcxx.buildkite-agent/builds</string> |
| 45 | </array> |
| 46 | |
| 47 | <key>EnvironmentVariables</key> |
| 48 | <dict> |
| 49 | <key>PATH</key> |
| 50 | <string>${HOMEBREW_PREFIX}/bin:/usr/bin:/bin:/usr/sbin:/sbin</string> |
| 51 | </dict> |
| 52 | |
| 53 | <key>RunAtLoad</key> |
| 54 | <true/> |
| 55 | |
| 56 | <key>KeepAlive</key> |
| 57 | <dict> |
| 58 | <key>SuccessfulExit</key> |
| 59 | <false/> |
| 60 | </dict> |
| 61 | |
| 62 | <key>ProcessType</key> |
| 63 | <string>Interactive</string> |
| 64 | |
| 65 | <key>ThrottleInterval</key> |
| 66 | <integer>30</integer> |
| 67 | |
| 68 | <key>StandardOutPath</key> |
| 69 | <string>${HOME}/libcxx.buildkite-agent/stdout.log</string> |
| 70 | |
| 71 | <key>StandardErrorPath</key> |
| 72 | <string>${HOME}/libcxx.buildkite-agent/stderr.log</string> |
| 73 | </dict> |
| 74 | </plist> |
| 75 | EOF |
| 76 | |
| 77 | echo "Starting BuildKite agent" |
| 78 | launchctl load ~/Library/LaunchAgents/libcxx.buildkite-agent.plist |
| 79 | |
| 80 | else |
| 81 | echo "Installing CI dependencies for macOS" |
| 82 | |
| 83 | if [[ -z "${BUILDKITE_AGENT_TOKEN}" ]]; then |
| 84 | echo "The BUILDKITE_AGENT_TOKEN environment variable must be set to a BuildKite Agent token when calling this script." |
| 85 | exit 1 |
| 86 | fi |
| 87 | |
| 88 | # Install Homebrew |
| 89 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" |
| 90 | HOMEBREW_PREFIX="$(brew --prefix)" |
| 91 | |
| 92 | # Install the required tools to run CI |
| 93 | brew install sphinx-doc python3 ninja cmake clang-format buildkite/buildkite/buildkite-agent |
| 94 | |
| 95 | # Setup BuildKite Agent config |
| 96 | version="$(sw_vers -productVersion | sed -E 's/([0-9]+).([0-9]+).[0-9]+/\1.\2/')" |
| 97 | arch="$(uname -m)" |
| 98 | sed -i '' "s/token=xxx/token=${BUILDKITE_AGENT_TOKEN}/g" "${HOMEBREW_PREFIX}/etc/buildkite-agent/buildkite-agent.cfg" |
| 99 | echo "tags=\"queue=libcxx-builders,arch=${arch},os=macos,os=macos${version}\"" >> "${HOMEBREW_PREFIX}/etc/buildkite-agent/buildkite-agent.cfg" |
Louis Dionne | 137daee | 2021-06-14 15:55:36 -0400 | [diff] [blame] | 100 | fi |