Writing script to automate project clone and run

Writing script to automate project clone and run

This is my first blog post in almost a month. I apologize if you have been following my blog posts more regularly than I have been updating it. Workload has been crazy since last few weeks which kept me much busy. But, here it goes

A Script to automate task of cloning iOS git repository with sample project and directly run it into simulator

I have been thinking about it for a while since each time I try to download an open source library from Github it takes ages to manually clone, compile and run it into appropriate simulator. (iPhone, iPad, Apple Watch et cetra)

Couple of weeks back I came up with the script which when provided few parameters such as URL of Github repo, name of simulator type to run project into, build config will automate these all tasks. At then end you will have a project running into your simulator.

I would like to take this opportunity to thank creator of iOS-sim library and This Github Gist.

In summary this script takes following parameters. Except for Git cloning URL other command line are optional. But I would strongly recommend for you to consider giving input of simulator type and iOS version you want to run project with.

Shell script performs following series of actions.

  1. Input the clone URL and download a Git repo in the same directory as the script

  2. Try to find a .xcodeproj or .xcworkspace file. Make sure this file does not belong to pods project

  3. Once suitable file is found we can be sure that the demo project for library lies under it

  4. Try if current folder has podfile. If yes we can be ascertain that we need to to pod install in order to install required dependencies and use .xcworkspace file to view demo

  5. If podfile does not exist, then we can directly use .xcodeproj to run the demo

  6. Use command line tool to run the project and store the generated .app file under the umbrella of current folder

  7. Once project has successfully run, use ios-sim plug-in to run this executable directly into simulator based on the device type passed.

An example of demo run of this script on random Github library is as follows

Picture of demo run for automated project clone and run

You can directly clone the script from Github Repository. If you run into any issues or have pull request, I would be happy to have a look at it.

Some notes:

  1. In order to successfully run the project, make sure the project has at least one scheme. The scheme associated with demo should be marked as shared. (Schemes marked as private won't be recognized by the command line tool and will result in project file not found error)

  2. Script has subtle bug where if the project has multiple .xcodeproj files with more than one schemes where one of the schemes belongs to framework and other belongs to actual demo project. It will sometimes try to run project with .scheme file belonging to framework which will not generate a valid .app file. (This is essentially true with swift project since developers try to ship them in the form of standard iOS frameworks)

Again, you can download this script from Github Repo. Of course script is not perfect. I will appreciate if you could find any bugs within it and let me know so that I can take quick and necessary action to fix them