xref: /openbsd/gnu/llvm/libcxx/utils/ci/macos-ci-setup (revision 5a38ef86)
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.
6#
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:
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
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:
22#
23#   $ caffeinate -s buildkite-agent start --build-path /tmp/buildkite-builds
24
25set -e
26
27# Install a Launchd agent that will automatically start the BuildKite agent at login
28if [[ ${1} == "--setup-launchd" ]]; then
29  HOMEBREW_PREFIX="$(brew --prefix)"
30  mkdir -p ~/Library/LaunchAgents
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>
75EOF
76
77  echo "Starting BuildKite agent"
78  launchctl load ~/Library/LaunchAgents/libcxx.buildkite-agent.plist
79
80else
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"
100fi
101