xcodegit-lfsxcode-cloud

How do you get Xcode Cloud to download Git LFS images?


I am trying to run Xcode Cloud on my unit tests, which include a large number of snapshot tests using png images that are all stored using Git LFS. But when I run the tests on Xcode Cloud, the logs indicate that the images aren't on disk, implying they haven't been downloaded from Git LFS. The documentation says Xcode Cloud comes with Git LFS support but doesn't indicate you need to do anything special to set it up for Xcode Cloud. I've connected Xcode Cloud to my repo, and it shows the tests running, but they're failing because the images are missing.

I have a .gitattributes file at the root level of my repository which contains rules for adding various image file formats to Git LFS. For example, one line says:

*.png filter=lfs diff=lfs merge=lfs -text

What am I missing here? How do I get Xcode Cloud to fetch Git LFS files when it checks out my repo?


Solution

  • Xcode Cloud clones with Git LFS during Build, but then runs Test on another VM that only receives the .xctest package; your repo and PNGs are gone.

    Quick Fix : Option A (simplest) – Put the images in the test bundle

    1. In the test target ➜ Resources / Copy Bundle Resources ➜ add the snapshot folder.

    2. Verify locally that the .png files appear inside <Tests>.xctest/Contents/Resources.

    3. Upload; Xcode Cloud will push those images to the test VM, and everything will work.

    Option B (if you don't want to inflate the repo) – Use a build script:

    # Run Script en el target de tests (fase Build)
    SNAP_DIR="${SRCROOT}/Snapshots"
    DEST="${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Snapshots"
    rsync -a "${SNAP_DIR}/" "${DEST}/"
    

    This way you copy the PNGs to the bundle only during compilation.