Travis CI - Swift Package Manage - checkout already exists?

Joe Susnick

Attempting to setup a sample project within a project that is configured to use Swift Package Manager and getting a strange error.

Project Structure:

MyProject/
    - Package.swift
    MyProject/
        - etc...
    Samples/
        - MySampleProject/

Swift Package Repository Setup:

MySampleProject is set up to use a local Swift package that should exist in the travis job:

file:///Users/travis/build/MyProject/MyProject <- pointed to branch: HEAD

Travis build command:

The travis script cd's into Sample/MySampleProject and runs:

xcodebuild clean build -target MySampleProject -sdk iphonesimulator

Error:

During the run, travis is claiming the checkout of the package already exists.

From the logs:

Resolve Package Graph

Fetching /Users/travis/build/<namespace>/MyProject

Cloning /Users/travis/build/<namespace>/MyProject

xcodebuild: error: Could not resolve package dependencies:

  An unknown error occurred. '/Users/travis/Library/Developer/Xcode/DerivedData/MySampleProject-agdvdspgtwakvignsmkkrkoxijnm/SourcePackages/checkouts/MyProject' exists and is not an empty directory (-4)

This works locally. Why would the checkout already be present in derived data for the travis builds? I'm not running any special commands to modify anything regarding SPM.

Joe Susnick

Two things to realize:

  1. The error message is very misleading. You will get this error message if there is not actually a commit to pull.

  2. A coworker pointed out that Travis is actually using refs/pull/$TRAVIS_PULL_REQUEST/merge for the value of $TRAVIS_COMMIT

Full solution:

Find the object in the plist that corresponds to XCRemoteSwiftPackageReference You can find this by opening YourProject.xcodeproj/project.pbxproj in a text editor and searching for XCRemoteSwiftPackageReference. Grab the ID since you'll need to hardcode it in your build step.

Note: You'll need to update this if you remove and re-add the package.

Next use PlistBuddy to update the branch to be the merge ref for the pull request.

    echo "Updating project file to point to merge commit at: refs/pull/$TRAVIS_PULL_REQUEST/merge"
    /usr/libexec/PlistBuddy \
        -c "set :objects:F4CEA53E23C29C9E0086EB16:requirement:branch refs/pull/$TRAVIS_PULL_REQUEST/merge" \
        YourProject.xcodeproj/project.pbxproj

    # Redirecting to /dev/null because we only care about errors here and the full output drowns Travis
    xcodebuild build -scheme YourScheme \
      -sdk iphonesimulator > /dev/null
  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Issue with Travis-ci, unable to fetch dependencies Swift Package Manager

Git checkout -b, branch already exists

Conda installs a package that already exists

Install package on Travis-ci with sudo:false

Specify valgrind options to R package on Travis CI

Travis CI R package error in documentation

travis-ci build for r package

How to change the "Account already exists" error in Woocommerce on checkout, into a login box?

TeamCity + VSTS - Failed to perform checkout on agent target file already exists

How to make Travis CI test package for Linux, OS X, Windows?

Travis CI: "Unable to locate package python-opencv" Python 2.7

R package dependency error on travis-ci but not local machine

Package Deployer - Creating a Package that skips import step if data already exists

Check if user already exists Firebase swift 3.0

Travis CI build [Cocoapod Swift] fails with no 'such module...' error

Swift project on GitHub travis-ci check always fail?

Swift Package Manager - Distribute an already existing Cocoapod

Xcode is gives error upon checkout: The branch could not be created because one named “master” already exists

Django: relation "auth_user" already exists when executing manage.py test myApp

How to remove Firestore documents from an array if they already exists in Swift iOS

Build webpack on travis ci

Using Travis CI with Android

Update SQLite in travis CI

SShpass not allowed with Travis CI

Multiple Environments in Travis CI

Chromedriver crashes on Travis CI

Searchkick Failing on Travis CI

Use ActiveMQ in Travis CI

Travis CI and Laravel Dusk

TOP Ranking

HotTag

Archive