Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lottadot/4b65500de97a5d42358806c5cb892405 to your computer and use it in GitHub Desktop.
Save lottadot/4b65500de97a5d42358806c5cb892405 to your computer and use it in GitHub Desktop.
[ -f Cartfile.resolved ]; then
CARTFILE_CHANGED=`git diff --stat $(GIT_PREVIOUS_SUCCESSFUL_COMMIT) $(GIT_COMMIT) | grep '\|' | awk '{print $$1}' | grep Cartfile.resolved`
if test "$(CARTFILE_CHANGED)" ; then
echo "## STEP: Updating Carthage"
carthage bootstrap --platform iOS --no-use-binaries
else
echo "## Carthage is up to date"
fi
else
echo "## STEP: Installing Carthage Dependencies"
carthage bootstrap --platform iOS --no-use-binaries
fi
@eseay
Copy link

eseay commented Oct 19, 2017

I modified the code above to the following below. In order to get the script to run in the first place in my Jenkins setup, I needed to add the #!/bin/sh at the top as well as I needed to add the if at the beginning of line one - a typo I imagine. As well, instead of () for the variables, I opted to use {}; for some reason the () weren't working.

Aside from syntactical changes, the main logical difference in my script is that it is ideal for situations when you check in your Carthage/Checkouts into version control for backup purposes. If you do that, then by checking for Carthage/Build, you are able to determine whether or not Carthage dependencies have ever been built - something necessary for the first run. If they have never been built (meaning that folder is not in the workspace), then you need to go ahead and perform the bootstrap

#!/bin/sh

if [ -d Carthage/Build ]; then
  CARTFILE_CHANGED=`git diff --stat ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} ${GIT_COMMIT} | grep '\|' | awk '{print $1}' | grep Cartfile.resolved`     
  if test "${CARTFILE_CHANGED}" ; then          
    echo "## STEP: Updating Carthage" 
    carthage bootstrap --platform iOS --cache-builds --no-use-binaries
   else          
    echo "## Carthage is up to date"
  fi 
else      
  echo "## STEP: Installing Carthage Dependencies" 
  carthage bootstrap --platform iOS --cache-builds --no-use-binaries 
fi

@surajthomask
Copy link

@eseay
Thanks for the updated script. Your script did actually work. Did you encounter any issues when pushing an amended patchset? I'm getting a bad object error in the "CARTFILE_CHANGED=" line.

@robertoschwald
Copy link

Shouldn't "carthage update" be used instead of "carthage bootstrap" when updating?
Carthage/Carthage#848 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment