<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alessandro Calzavara on Medium]]></title>
        <description><![CDATA[Stories by Alessandro Calzavara on Medium]]></description>
        <link>https://medium.com/@DrAL3X?source=rss-d51137d774d7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*pEQYeq0enPczgQc5.png</url>
            <title>Stories by Alessandro Calzavara on Medium</title>
            <link>https://medium.com/@DrAL3X?source=rss-d51137d774d7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 10:15:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@DrAL3X/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Automate All-The-Things With: Git Hooks]]></title>
            <link>https://medium.com/@DrAL3X/automate-all-the-things-with-git-hooks-2286e86dcb8f?source=rss-d51137d774d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/2286e86dcb8f</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Alessandro Calzavara]]></dc:creator>
            <pubDate>Sat, 05 Mar 2016 00:00:00 GMT</pubDate>
            <atom:updated>2016-03-23T10:16:35.580Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>If you had the chance to work with some colleagues/friends on some projects, you already know that automate some boring tasks you have to do quite often is really important.</p><p>Everything started from a real conversation I had the past week:</p><blockquote><em>Me: I updated the ad-hoc distribution profile. Please download it from the iOS Provisioning Portal and install it on your machine<br>My colleague: WAT?</em></blockquote><p>This sounds like something just one of us should do and the others should JUST receive it without doing anything manually.</p><p>We use <a href="https://en.wikipedia.org/wiki/Git_(software">GIT</a> to manager all our code base so all we want to do is JUST run git pull on our local repository. Which tool can we use to achieve this?</p><h3>Git Hooks</h3><p><a href="https://git-scm.com/docs/githooks">Hooks</a> are little scripts you can place in your project <em>$GIT_DIR/hooks</em> directory to trigger action at certain points.</p><p>This is exactly what we need! Each time we run the <em>git pull</em> command (or <em>git merge</em>) we should looking for changes related to provisioning profiles. If there are, install them all.</p><p>So let’s do it!</p><p><strong>Security note</strong>: we keep all our iOS provisioning profiles related to a specific app inside the same repository. To be safe, we encrypt them all using <a href="https://www.npmjs.com/package/git-encrypt">git-encrypt</a>. Take a look at it if you want to do the same!</p><p>To keep these hook files out of your app code, I created a git-hooks folder in the project root directory and save them there.</p><h4>git-hooks/install-profiles.sh</h4><pre>XCODE_PROFILES_PATH=”$HOME/Library/MobileDevice/Provisioning Profiles” </pre><pre>prepare_folder() { <br>  mkdir -p “${XCODE_PROFILES_PATH}” <br>  return 0 <br>}</pre><pre>install_profiles() { <br>  for file in ${1}/*.mobileprovision do <br>    [ -f “$file” ] || break <br>    UUID=`grep -aA1 UUID ${file}| grep -o “[-a-z0–9]\{36\}”` <br>    cp “${file}” “${XCODE_PROFILES_PATH}/${UUID}.mobileprovision” <br>    if [ $? -ne 0 ]; then <br>      echo “ERROR: Unable to copy mobileprovision file to its destination” <br>      return 1 <br>    fi<br>  done <br>  return 0<br>}</pre><pre>prepare_folder <br>install_profiles “./Certificates/development” <br>install_profiles “./Certificates/distribution”</pre><p>Now we need to run this script each time we do a git pull or git merge. So we prepared a post-merge.sh and post-checkout.sh scripts. Both are exactly the same</p><h4>git-hooks/post-merge.sh, git-hooks/post-checkout.sh</h4><pre>check_run() { <br>  changed_files=”$(git diff-tree -r — name-only — no-commit-id ORIG_HEAD HEAD)”<br>  echo “$changed_files” | grep — quiet “$1” &amp;&amp; eval “$2” <br>}</pre><pre>check_run “^Certificates/.*\.mobileprovision$” “$BASEDIR/install-profiles.sh”</pre><p>Last thing to do is to link post-merge.sh (and post-checkout.sh scripts inside the project <em>.git/hooks</em> folder. A simple setup script will do this</p><h4>setup.sh</h4><pre>echo “Configuring git hooks…” </pre><pre># Make scripts executable <br>chmod +x git-hooks/*.sh </pre><pre># make a symbolic link with for the hooks <br>if [ ! -f .git/hooks/post-checkout ]; then <br>  ln git-hooks/post-checkout.sh .git/hooks/post-checkout <br>  echo “post-checkout hook created.” <br>else <br>  echo “A post-checkout hook exists already.” <br>fi</pre><pre>if [ ! -f .git/hooks/post-merge ]; then <br>  ln git-hooks/post-merge.sh .git/hooks/post-merge <br>  echo “post-merge hook created.” <br>else<br>  echo “A post-merge hook exists already.” <br>fi</pre><p>And finally, run <em>setup.sh</em>. It’s safe to execute it multiple times but one is enough.</p><p>Now you are ready to roll! Each time you do a <em>git checkout</em>, <em>git pull</em> or <em>git merge</em>, these scripts will install each <em>.mobileprovision</em> files available.</p><p>You can do so much more of course, it’s up to you how much further to go.</p><p>Have fun with <strong>git hooks</strong>!</p><p>Alessandro</p><p><em>Originally published at </em><a href="https://alessandrocalzavara.com/blog/2016/03/05/automate-all-the-things-with-git-hooks/"><em>alessandrocalzavara.com</em></a><em> on March 5, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2286e86dcb8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>