XCode Cloud permissions regression breaking homebrew installations

Sometime between Aug 19, 2022 at 3:19pm CA time and Aug 21 at 1:25pm CA time, there seems to have been a change in XCode cloud which made the /usr/local directories unreadable by whatever user is running the ci_post_install.sh script.

This makes homebrew basically broken and essentially makes XCode Cloud unusable.

The only workaround I can think of is to do a user-only install of homebrew and run the user-only brew commands. However, I'd like to get an answer from Apple on if that is necessary.

Do you use cocaopods as well? I'm getting errors regarding it not being able to finding node in $PATH, even though it is clearly set correctly if I dump the env variables in the pre_xcodebuild script

This directory is not writable:

Linking /usr/local/Cellar/node@16/16.17.0... 
Error: Could not symlink include/node
/usr/local/include is not writable.

Any package installation with Homebrew is thus broken.

We have the same problem. Most of our workflows stopped working, because homebrew can no longer install certain casks. Our CI is essentially down.

Symptom A: Installation, e.g. of brew install jq, fails:

$ brew install jq
==> Installing jq dependency: oniguruma
==> Pouring oniguruma--6.9.8.monterey.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink include/oniggnu.h
/usr/local/include is not writable.

Symptom B: running brew doctor lists multiple missing directories:

$ brew doctor
Warning: The following directories do not exist:
/usr/local/Frameworks
/usr/local/include
/usr/local/lib
/usr/local/sbin
/usr/local/var/homebrew/linked

Anecdotally, brew install swiftlint does not have the same problem.

Any ideas?

Same problem here with the ci_post_clone.sh.

A temporary fix is to have a local brew installation:

https://github.com/Homebrew/brew/blob/664d0c67d5947605c914c4c56ebcfaa80cb6eca0/docs/Installation.md#untar-anywhere

then calling the local homebrew/bin/brew

Filed FB11350583 Xcode Cloud Homebrew permissions regression. Seeing the same issue installing jq with brew. Worked until 8/19 at some point.

After a day of debugging this, I gave up and left a stackoverflow question to see if anyone else was having the issue. I hope it gets fixed soon.

I gave up and just went ahead with local hombrew. Its not great, but feel free to grab my ci_post_clone.sh script. Note that this overwrites .xcode.env so if you have anything in there besides your NODE_BINARY path you'll need to adjust accordingly.

#!/bin/zsh

set -e

export CI_SCRIPTS_DIR=${PWD}
export RN_DIR=${PWD}/../../
export RN_IOS_DIR=${PWD}/../
export BREW_DIR=${CI_DERIVED_DATA_PATH}/opt/hombrew

echo "*** Date: $(date)"
echo "*** Running post clone script in: ${PWD}. RootDir = ${ROOT_DIR}"
echo "*** Running RN_DIR ${RN_DIR}"
echo "*** Running RN_IOS_DIR ${RN_IOS_DIR}"
echo "*** Running BREW_DIR ${BREW_DIR}"

mkdir -p ${BREW_DIR}

export PATH=${BREW_DIR}/bin:${PATH}

cd ${BREW_DIR}
if [[ ! -e "${BREW_DIR}/bin/homebrew" ]]
then
	echo "*** Installing home brew"
	curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1
else
	echo "*** Brew already installed.  using $(command -v brew)"
fi


echo "*** PATH: ${PATH}"
cd ${ROOT_DIR}

which brew

# Install CocoaPods using Homebrew.
brew install cocoapods node@16 yarn --quiet
brew link --overwrite node@16 --quiet
ls /Users/local/Homebrew/bin

NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}"


echo "### AUTOMATICALLY GENERATED FILE FOR LOCAL HOMEBREW" > ${RN_IOS_DIR}/.xcode.env
echo "export NODE_BINARY=${NODE_BINARY}" >> ${RN_IOS_DIR}/.xcode.env

echo "*** ${RN_IOS_DIR}/.xcode.env: "
cat "${RN_IOS_DIR}/.xcode.env"

# Install dependencies you manage with CocoaPods.
pod install
echo "*** Finish Date: $(date)"

It started to fail with the recent macOS 12.5.1 update. Changing the macOS version to 12.4 in Workflow environment settings fixes the issue in my case.

I switched to a local version of homebrew and it was able to install jq, however jq command isn't found in the ci_post_xcodebuild script :(

This has started working again for us recently. We can now again (at least for the moment) install jq using the built-in homebrew installation in Xcode Cloud.

Build are running on latest realease, which at the moment is macOS 12.6 and Xcode 14.0.1.

We have switched back to using the built-in homebrew, shaving ~3 minutes of each of our builds, but we are ready if it stops working again ;-)

XCode Cloud permissions regression breaking homebrew installations
 
 
Q