<?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 Pranav Kasetti on Medium]]></title>
        <description><![CDATA[Stories by Pranav Kasetti on Medium]]></description>
        <link>https://medium.com/@pranav.kasetti?source=rss-59ed2ec3be22------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ozr8NYPQslZk854UIcL8bw.jpeg</url>
            <title>Stories by Pranav Kasetti on Medium</title>
            <link>https://medium.com/@pranav.kasetti?source=rss-59ed2ec3be22------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 21:23:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pranav.kasetti/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[SwiftFormat Automation for iOS Apps]]></title>
            <link>https://medium.com/@pranav.kasetti/swiftformat-automation-for-ios-apps-42c91000a9af?source=rss-59ed2ec3be22------2</link>
            <guid isPermaLink="false">https://medium.com/p/42c91000a9af</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[swiftformat]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Pranav Kasetti]]></dc:creator>
            <pubDate>Sat, 30 Sep 2023 14:09:32 GMT</pubDate>
            <atom:updated>2023-10-02T08:25:05.199Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SA3BFKZAW0Tj_Si1Tjd2rQ.jpeg" /></figure><h3>What is SwiftFormat?</h3><p>SwiftFormat is a code library and command-line tool for reformatting Swift code on macOS, Linux or Windows, according to their <a href="https://github.com/nicklockwood/SwiftFormat">GitHub</a> documentation.</p><p>SwiftFormat is more powerful than another very similar Swift command line utility called <a href="https://github.com/realm/SwiftLint">SwiftLint</a>. SwiftFormat is a code formatting tool that extends SwiftLint’s static analysis (linting) capability. The difference here is that SwiftFormat has a more powerful autocorrect capability than SwiftLint, so it is able to fix more issues, even though SwiftLint may be able to identify a wider range of issues, such as file length, and cyclomatic complexity.</p><p>In this article, I’ll go through various options to implement SwiftFormat on a production project rather than how to integrate the tool locally (this is relatively straightforward). This is because I believe the tool provides greater benefit as an automation for every developer on the team, rather than a few only. We’ll also cover the relative advantages or disadvantages. I hope that this will help you choose the right tool for your project!</p><h3>Article Agenda</h3><ol><li>What is SwiftFormat?</li><li>An overview of SwiftFormat integrations</li><li>CLI tool</li><li>Xcode format on save</li><li>Build phase</li><li>Pre-commit hook on local machines</li><li>Post-receive hook on CI</li><li>Danger Ruby plugin</li><li>Why use SwiftFormat?</li><li>Overview of pre-commit hook solution</li></ol><h3>SwiftFormat Integrations</h3><h3><a href="https://github.com/nicklockwood/SwiftFormat#command-line-tool">CLI Tool</a></h3><p>There are various ways to integrate the SwiftFormat Command Line tool, including Homebrew, Mint and building from source, as outlined in the link above.</p><p>It’s straightforward to run the tool with:</p><p>$ swiftformat .</p><p>The disadvantage here is that we lose the ability to manage SwiftFormat tool versions that we get if we integrated the tool as a CocoaPod or Swift Package with SPM. We also don’t enforce the tool on every developer machine, and integrate it into the development lifecycle. As a result, I won’t suggest this approach for production apps.</p><h3><a href="https://github.com/nicklockwood/SwiftFormat#xcode-source-editor-extension">Xcode source editor extension</a></h3><p>We can install the Xcode extension with:</p><p>$ brew install --cask swiftformat-for-xcode</p><p>as outlined in the above link. Once you have launched the app and restarted Xcode, you’ll find a SwiftFormat option under Xcode’s Editor menu.</p><p>The disadvantage here is that we don’t automate the SwiftFormat tool and enforce it’s usage during the development lifecycle because the developer has to manually trigger the tool. Furthermore we cannot enforce the tool gets installed on every developer’s machine. As a result, I won’t suggest this approach for production apps.</p><h3><a href="https://github.com/nicklockwood/SwiftFormat#xcode-build-phase">Xcode build phase</a></h3><p>There are 3 options outlined in the link above for installation as an Xcode build phase: SPM, CocoaPods and Locally Installed SwiftFormat. Please refer to this official documentation for detailed instructions.</p><p>Out of the three, I suggest CocoaPods for faster build times. SPM makes use of swift run -c release swiftformat &quot;$SRCROOT&quot; which has the annoying side-effect of building the tool from source before format. CocoaPods uses a cached tool in the Pods folder thus improving build times, and still maintaining the advantages of using a dependency manager. Unlike the locally installed CLI tool which also has faster build times, CocoaPods enables us to manage and enforce versions on a project-wide basis.</p><p>Running SwiftFormat as an Xcode Build Phase means the undo history gets lost when building the app. This can be painful and slow down development. Furthermore, we may forget to build the app before committing changes so formatting issues may not be included for every commit.</p><h3><a href="https://github.com/nicklockwood/SwiftFormat#swift-package-manager-plugin">SPM Plugin</a></h3><p>Note that using the SPM SwiftFormat <em>Plugin</em> rather than the Package itself is much faster as it doesn’t build from source.</p><p>As a result, it can be helpful during development, but doesn’t <em>automate</em> the tool. The same argument applies for the other SwiftFormat text editor extensions for VSCode, Sublime Text and Nova.</p><h3><a href="https://github.com/nicklockwood/SwiftFormat#git-pre-commit-hook">Git pre-commit hook</a></h3><p>Once installed as outlined in the official documentation above, the pre-commit hook will now run whenever you run git commit. Running git commit --no-verify will skip the pre-commit hook.</p><p>A pain point with Git pre-commit hooks are Merge Commits. Merge commits can add additional formatting changes in addition to the original changes. This can create noise for Pull Requests and needs to be managed in the short term either by disabling SwiftFormat from Merge Commits manually (using --no-verify), or running the tool on the whole project in one PR or a set of PRs dedicated for formatting changes.</p><p>We can share pre commit hooks on every machine using Husky which is an NPM library, however it’s hard to enforce SwiftFormat on every developer machine without bringing in additional libraries. Another option is <a href="https://github.com/rycus86/githooks">this library</a> which works without NPM.</p><h3>Post-receive hook on CI</h3><p>There are numerous articles online that show how to run a script on the CI server using the post-receive hook e.g. <a href="https://medium.com/@Dungeon_Master/the-simple-way-to-integrate-continuous-integration-ci-cd-with-git-hooks-f6e871b14856">The simple way to integrate Continuous-Integration(CI/CD) with Git hooks </a>. This has the advantage that formatting changes will never be missed from the commit history with automation, however it may be inconvenient to have to pull changes from the server after making every commit especially because the new commit may not be pushed immediately. Also, it may not be practical or scalable to set up every CI machine with post-receive hooks, because we need to manually set up each machine for enabling post-receive hooks.</p><h3><a href="https://github.com/nicklockwood/SwiftFormat#on-ci-using-danger">Danger Ruby plugin on CI</a></h3><p>As outlined in the above SwiftFormat documentation, we can use the Danger Ruby plugin by adding the <a href="https://github.com/garriguv/danger-ruby-swiftformat">danger-swiftformat</a> plugin to our Gemfile.</p><p>However, not every project can make use of the SwiftFormat Danger Ruby plugin. This is because the project may already make use of DangerJS and associated plugins. The SwiftFormat plugin doesn’t integrate seamlessly with the existing CI infrastructure and furthermore we run into similar issues described for the post-receive hook. These include potential delays applying formatting changes in separate CI commits and having to synchronise local branches with the remote regularly during development.</p><h3>Why use SwiftFormat?</h3><p>I believe the benefits of SwiftFormat outweigh its disadvantages because the disadvantages can be mitigated in the short term, and the long-term benefits outweigh the short term friction.</p><h3>Benefits</h3><ol><li>SwiftFormat and SwiftLint configs codify a standardised style guide for the codebase. So rather than having to worry about enforcing a style guide after deciding on one, we can automate best practice by deploying the tool on the project. Individual developers may have their own personal style preferences that differ from others on the team, and using this tool enables every developer to align to the project’s specific conventions automatically.</li><li>Static analysis tools improve code quality in the codebase and pay dividends over time, even if the initial deployment stages can be painful. SwiftFormat helps us to follow the KISS principle with numerous rules to remove implicit self, remove unnecessary weak keywords and much more.</li><li>Integrating SwiftFormat into CI, Git or the Build Process enables us to catch formatting/style issues before they are added to the codebase and automatically enforces it without additional effort. They reduce the number of comments during code review and thus improve developer velocity. Developers get more time to focus on more important issues such as testing, architecture and design patterns!</li></ol><h3>Disadvantage</h3><p>It can take time to agree on a common set of rules for the project to follow, what folders to exclude, and figuring out the optimal solution for the specific codebase. In the short term, we need to monitor feedback from the wider team to ensure a stable transition.</p><h3>My favourite SwiftFormat solution</h3><p>I have successfully deployed SwiftFormat on multiple projects and formatted all files on the project through the typical PR merging process.</p><p>I considered all approaches for deployment in the early stages, but decided on the pre-commit hook solution in the end because it was the easiest to deploy for my current setup and provided most of the automation benefits I was after.</p><p>I made use of the <a href="https://www.npmjs.com/package/husky">NPM husky package</a> which was already integrated in the app, adding the following changes to our package.json to lint only the staged files:</p><pre>&quot;husky&quot;: {<br>  &quot;hooks&quot;: {<br>    &quot;pre-commit&quot;: &quot;lint-staged&quot;<br>  }<br>},<br>&quot;lint-staged&quot;: {<br>  &quot;ios/**/*.swift&quot;: [<br>    &quot;ios/Pods/SwiftFormat/CommandLineTool/swiftformat&quot;,<br>    &quot;ios/Pods/SwiftLint/swiftlint autocorrect&quot;,<br>    &quot;git add&quot;<br>  ]<br>}</pre><p>I came up with a solution to integrate SwiftLint autocorrect after applying SwiftFormat into the commit pipeline, so that the tools don’t have conflicting changes. SwiftLint was now integrated deeply within the app both as a build phase and pre-commit hook.</p><p>Others found the tool painful to work with in the beginning because of Merge Commits, as outlined above. I worked around this by disabling hooks on merge commits and also creating an Open PR to apply swiftformat to all remaining files once the majority of the project had been formatted organically.</p><p>I collated feedback from other developers to align on rules and agreed on the following .swiftlint.yml:</p><pre># File options, update these for your project<br>--exclude Pods,Project/GraphQL/CodeGen/generated,ProjectTests/Source/AutoMocks<br>​<br># Format options<br>--commas always<br>--stripunusedargs closure-only<br>--ranges no-space<br>--patternlet inline<br>--closurevoid preserve<br>--decimalgrouping 3,5<br>​<br>--disable strongoutlets, wrapMultilineStatementBraces, andOperator, extensionAccessControl</pre><p>We experienced friction during the early stages, but worked around this by updating the config as we went along, for example to exclude certain folder paths for excluding generated files from formatting and to disable certain rules. I disabled the strong outlets rule because I found some outlets were in fact causing memory cycles. Other rules were disabled because they were found to provide negligible cosmetic improvements.</p><p>Overall though, I found that we have fewer PR comments around style changes and velocity has improved! Teams have voted to maintain usage of the tool as the tool is a well established best practice for large codebases, and because they worked through the major teething issues.</p><h3>Want to connect?</h3><p>I hope you enjoyed reading this article! If you want to keep in touch, feel free to follow me on X.com <a href="https://twitter.com/spidey_vitamins">@spidey_vitamins</a>.</p><h3>Resources</h3><ol><li><a href="https://github.com/nicklockwood/SwiftFormat">https://github.com/nicklockwood/SwiftFormat</a></li><li><a href="https://medium.com/@Dungeon_Master/the-simple-way-to-integrate-continuous-integration-ci-cd-with-git-hooks-f6e871b14856">https://medium.com/@Dungeon_Master/the-simple-way-to-integrate-continuous-integration-ci-cd-with-git-hooks-f6e871b14856</a></li><li><a href="https://github.com/garriguv/danger-ruby-swiftformat">https://github.com/garriguv/danger-ruby-swiftformat</a></li><li><a href="https://www.npmjs.com/package/husky">https://www.npmjs.com/package/husky</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42c91000a9af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your guide to Danger Swift on CI]]></title>
            <link>https://medium.com/kinandcartacreated/your-guide-to-danger-swift-on-ci-83e3f5136a9a?source=rss-59ed2ec3be22------2</link>
            <guid isPermaLink="false">https://medium.com/p/83e3f5136a9a</guid>
            <category><![CDATA[static-code-analysis]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[testing-tools]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Pranav Kasetti]]></dc:creator>
            <pubDate>Wed, 04 May 2022 08:58:50 GMT</pubDate>
            <atom:updated>2022-07-04T09:39:28.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3qlpZMkUYbc6tjCNDxiRLQ.jpeg" /></figure><p>We were excited to automate <strong>static analysis (linting) and rigorous testing </strong>with <strong>Danger CI </strong>because we are committed to delivering stable and maintainable codebases for our clients here at Kin + Carta. 🧱</p><p>As covered in <a href="https://medium.com/kinandcartacreated/the-missing-handbook-for-continuous-integration-continuous-deployment-start-here-a859f595793b">The missing handbook for CI/CD</a>, code coverage and the number of linting warnings are helpful metrics for our engineering team to measure product health 📊. Many companies (including Kin + Carta!) use CI company-wide so improving our CI on one app can improve our approach on other projects too ⭐️!</p><p>We inherited a <a href="https://github.com/danger/swift">Danger Swift</a> configuration running <a href="https://github.com/realm/SwiftLint">SwiftLint</a> for a client iOS project but wanted to extend Danger further to supercharge our tooling. 🍄 We love pushing the boundaries of technology, so wanted to explore this together.</p><p>We extended Danger Swift’s official docs CI configuration on a sample project to run tests, track code coverage, analyse PRs, as well as run SwiftLint automatically ✨. We are excited to share our work because many team members found our CI setup useful in developing our sample app 😃.</p><p>PS: For those of you who haven’t worked with SwiftLint before, skimming their <a href="https://github.com/realm/SwiftLint">README</a> to understand the tool to set it up locally could be helpful (optional though!).</p><p>We supplement Danger’s <a href="https://danger.systems/swift/guides/getting_started.html">getting started guidelines</a> with steps for M1 machines, updated Package configurations, plugin support and other helpful enhancements 💪.</p><h3>Requirements ☑️</h3><ul><li>We’ll use <strong>Swift Package Manager 📦 </strong>instead of Homebrew so that we can lock versions (Xcode 10+).</li><li>We’ll use <strong>GitHub</strong> as our source control provider rather than Bitbucket / GitLab. The steps for other source control providers can be adapted on a case-by-case basis, and should be similar.</li><li>A <strong>CI environment</strong> ☁️ to run the Danger builds. I’ve used TeamCity but the steps are very similar to other CI providers.</li></ul><h3>Article Agenda ⏱</h3><ol><li><a href="#a5f1">Installation 📲</a></li><li><a href="#3917">Create a Dangerfile ⚠️</a></li><li><a href="#7878">Import Danger Plugins 🔌 (optional!)</a></li><li><a href="#16c1">Create a GitHub Danger bot 🤖</a></li><li><a href="#3b90">Test Danger locally 📍</a></li><li><a href="#9d85">Set up Danger on CI ⚙️</a></li><li><a href="#a248">Conclusion 🎬</a></li></ol><p>To skip to the final working solution, you can clone <a href="https://github.com/theappbusiness/ModularSlothCreator">ModularSlothCreator</a> 🦥. Our project uses an extra Danger plugin (<a href="https://github.com/WeTransfer/WeTransfer-iOS-CI">WeTransfer-iOS-CI</a>) which we used for code coverage reporting 📈 and SwiftLint-ing PRs, but <em>not</em> deployment.</p><p>Note: For those of you wondering “What’s a Modular Sloth Creator ??” 😄, I’m adapting Apple’s Sample Code for DocC that used an app called Sloth Creator 🦥. I’m extending the <strong>Modular “SlothCreator”</strong> sample project from my previous post about <a href="https://medium.com/kinandcartacreated/host-and-automate-your-docc-documentation-c6ac29dc0feb">DocC<strong> </strong>with CI</a> to test Danger.</p><p>You may prefer to try a configuration without the plugin, so we’ve provided alternate steps for a more lightweight project.</p><h3>Installation 📲</h3><p>First, we run our Dangerfile locally before deploying to CI.</p><p>We are using Danger Swift rather than Danger JS for several reasons:</p><ol><li>We wanted to report code coverage with Danger, so we leveraged Danger Swift‘s wider iOS plugin ecosystem. I loved using WeTransfer-iOS-CI because it was very easy to set up and came with a lot of great features for free e.g. code coverage, fastlane integration, provisioning and App Store Connect deployments. We wanted to extend our DangerJS config with these extra features because Danger-Swift is now stable to use.</li><li>You may also prefer to stay within Xcode for a smoother developer experience. While editing our config Dangerfile.swift file in Xcode, we leverage Swift’s great features of type safety, optionals, and more. As an iOS developer, I really liked being able to write my CI configuration using the same language I used for dev and was able to set it up faster.</li><li>Type completion and static analysis in Xcode ensure your Dangerfile is valid before you deploy using swift run danger-swift edit. This gave me confidence in my deployments and saved time.</li></ol><p>To install Danger-Swift correctly, we need to use Danger-JS as a dependency rather than Danger-Ruby(!!). Danger-Ruby is installed by default when we install danger-swift through Homebrew 😅.</p><p>Install Danger-JS globally on your local machine with npm / yarn:</p><p>npm install -g danger</p><p>Now, we can install Danger-Swift using SPM. For example, our ModularSlothCreator project uses the following Package.swift:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e52dab5787ea415c85a2a7d9b87e0824/href">https://medium.com/media/e52dab5787ea415c85a2a7d9b87e0824/href</a></iframe><p>Our Package.swift differs from Danger’s getting started documentation to enable builds on M1 machines. You may notice we’ve added a defaultLocalization to our Package, and used a .dynamic library to get Danger to build successfully (at the time of writing).</p><p>We’ve now got two projects, one Swift Package solely to integrate Danger and a separate iOS Xcode project.</p><p>I’ve used the main target name ModularSlothCreator and appended -PRLinter to clearly separate the main target from the Package. Feel free to adopt the same or a similar naming convention to help you navigate the codebase.</p><p>We are linking a stub called DangerProxy.swift from our main target that only contains import Foundation so that our Danger Package can link with our Swift codebase. Danger needs to be able to read the files to lint them 🪄.</p><p>swift build installs Danger-Swift and its dependencies. If you ever run into issues, I suggest reading the <a href="https://github.com/danger/swift/issues">Issues</a> page on the Danger-Swift repo or closed PRs with similar bugs before filing a new Issue. There are lots of helpful and talented community members to help out.</p><p>From this point on you can use swift run danger-swift [cmd] to run Danger locked correctly to your project. 😎</p><h3>Create a Dangerfile ⚠️</h3><p>A Dangerfile defines our project’s Danger configuration as code.</p><p>If you want to run Danger without any plugins as a lightweight solution, create the following Dangerfile.swift in the root folder for your project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8bd4c06ef29cd75301a21b631fcfbc6/href">https://medium.com/media/e8bd4c06ef29cd75301a21b631fcfbc6/href</a></iframe><p>This Dangerfile generates warnings for large PRs, WIP PRs, and PRs with no description for PR linting and runs SwiftLint out of the box with Danger without any plugins.</p><p>If you’re happy to configure the CI a bit more, we can leverage WeTransfer-iOS-CI which defines the following Dangerfile.swift:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/378724b7098b5a32e3fac1ef6c4d97d5/href">https://medium.com/media/378724b7098b5a32e3fac1ef6c4d97d5/href</a></iframe><p>WeTransferPRLinter does the same work as the above config and incorporates code coverage tracking! I really like the WeTransfer-iOS-CI because it is modular and very powerful. WeTransfer’s CI is one of the most popular Danger-Swift plugins (153 GitHub ⭐️s!).</p><p>ModularSlothCreator imports WeTransfer-iOS-CI as a Git submodule so we <em>don&#39;t</em> actually need to create a Dangerfile. You can skip the next section if you don’t want to use WeTransfer-iOS-CI, because we’ve now set up Danger. ⭐️</p><h3>Import Danger Plugins 🔌 (optional!)</h3><p>We need to follow additional set-up steps for Danger plugins, defined in their READMEs. WeTransfer-iOS-CI current <a href="https://github.com/WeTransfer/WeTransfer-iOS-CI#readme">README.md</a> outlines the following steps:</p><ol><li>Add as a submodule with the correct path Submodules/WeTransfer-iOS-CI.</li><li>Enable fastlane on your project. Import the fastlane/Fastfile from this repo and trigger the test lane.</li><li>Add a run script to the main target: ./Submodules/WeTransfer-iOS-CI/BuildTools/swiftlint.sh.</li></ol><p>We can now authenticate our GitHub requests and test our local Danger configuration 🧪.</p><p><strong>Note 🚨: Third-party plugin steps may change in the future, so double-check the latest plugin README before committing.</strong></p><h3>Create a GitHub Danger bot 🤖</h3><h4><strong>Fun fact 🤗</strong></h4><p>We can skip <em>creating a new email </em>if we already use<em> </em><strong>Gmail.</strong><em> </em>The feature is called<em> </em><strong>plus addressing<em>. </em></strong>Simply sign up for a new GitHub account with your email address suffixed with a + and your identifier. e.g. <strong>pranav+dangerbot@gmail.com</strong>. 🎉</p><p><a href="http://github.com/signup">Sign up</a> for a new GitHub account for your Danger bot to use exclusively. I used a plus addressing email address, but you may prefer to use a dedicated bot email.</p><p><a href="https://github.com/settings/tokens/new">Create a GitHub Personal Access Token</a> for your bot account with the <em>repo </em>permission.</p><p>Copy the token, and save it for the next step.</p><p><a href="https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/adding-outside-collaborators-to-repositories-in-your-organization">Add the bot as a collaborator</a> with <strong>Write</strong> access to your repository from your main GitHub account.</p><h3>Test Danger locally 📍</h3><p>In order to access the GitHub API with Danger, we’ll need to export our Danger GitHub token as an environment variable to authenticate our GitHub operations. We run danger-swift from within the root folder as follows:</p><pre>$ brew install mint # Only for WeTransfer-iOS-CI projects<br>$ cd ModularSlothCreator<br>$ bundle exec fastlane test # Only for WeTransfer-iOS-CI projects<br>$ export DANGER_GITHUB_API_TOKEN=&lt;insert token here&gt;<br>$ swift build<br>$ swift run danger-swift pr <a href="https://github.com/theappbusiness/ModularSlothCreator/pull/1">https://github.com/theappbusiness/ModularSlothCreator/pull/1</a></pre><p>Great! We’ve now verified that Danger compiles locally. 🥳</p><p>For ModularSlothCreator, bundle exec fastlane test generates a .xcresult bundle that Danger uses for calculating code coverage and test metadata. This is a great time to validate our local fastlane setup. We technically only use fastlane test with WeTransfer-iOS-CI in this article, but I highly recommend using fastlane scan on your PR workflows separately.</p><p>Once we’ve verified our Danger setup works as expected, we can deploy our configuration to CI with confidence ⬆️.</p><h3>Set up Danger on CI ⚙️</h3><h4>Environment Variables 🌳</h4><p>Now add your Danger Bot GitHub Personal Access token to your CI configuration as an envvar DANGER_GITHUB_API_TOKEN.</p><p>Configure a CI envvar PULL_REQUEST_URL with a dynamic URL to point to the PR URL. How you configure this will depend on your CI provider. In TeamCity, we nest envvars:</p><pre>env.PULL_REQUEST_URL=https://github.com/theappbusiness/ModularSlothCreator/%teamcity.build.branch%</pre><h4>CI Build Steps 🪜</h4><p>In these build steps, we are simply migrating what we ran with danger-swift local locally to a danger-swift ci command by leveraging envvars.</p><p>If you’re running Danger without WeTransfer-iOS-CI then you only need one build step to run a shell script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d158e279d70c5985f9393122d29bc82/href">https://medium.com/media/1d158e279d70c5985f9393122d29bc82/href</a></iframe><h4>CI build steps for WeTransfer-iOS-CI 📲</h4><p>We tweak the configuration slightly to run WeTransfer-iOS-CI with fastlane, and you may need to do a similar plugin-specific configuration for other Danger plugins.</p><p>We are writing shell scripts that run fastlane test as above, however, we may need to install mint in a different way on CI before running danger. I’ve added it to the shell script, but you may prefer to use a Build Feature on your CI provider (or another CI installation method) and remove this line from Build step 1.</p><p><strong>Build step 1:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf7e332f0a1f1fcd89daa479efb193df/href">https://medium.com/media/cf7e332f0a1f1fcd89daa479efb193df/href</a></iframe><p><strong>Build step 2:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3848b7e424bd5e8d77655d686bbd250/href">https://medium.com/media/e3848b7e424bd5e8d77655d686bbd250/href</a></iframe><p>Do note that Danger configurations vary by CI provider and VCS provider, so reference the <a href="https://danger.systems/swift/guides/getting_started.html">official docs</a> to be safe. We used TeamCity CI for ModularSlothCreator and adapted Bitrise workflow steps from the WeTransfer-iOS-CI repository.</p><p>Try triggering a build to check everything is hooked up correctly! 🙏</p><h3>Conclusion 🎬</h3><p>I hope you enjoyed learning about Danger Swift as much as I did writing this article! 🎉</p><p>I wrote this article to supplement Danger-Swifts official documentation, because I wanted to extend my configuration and help people set up faster. I hope that my pain saves you some sweat down the road 😅.</p><p>Danger Swift should now post to GitHub PRs without any extra work. I hope you enjoy the automation of tabulated code coverage reporting within every PR as much as I do 😍!</p><p>Ps. Danger <em>edits </em>summaries for later commits so that your PR doesn’t get spammed with comments ✍️.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HSOjOaTnuy0otwF1RLG_Pw.png" /><figcaption>Figure 1: Danger Swift Bot summary for Modular Sloth Creator PR 📊</figcaption></figure><p>We also get inlined PR comments for SwiftLint warnings 📝 out of the box. The great thing is Danger <strong><em>deletes </em></strong><em>warnings </em>that have been fixed in later commits!<em> </em>Here’s an example for ModularSlothCreator:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LUkNDRq2jmawJE0MlG4Amg.png" /><figcaption>Figure 2: Danger Swift Bot SwiftLint warnings on ModularSlothCreator PR ⚠️</figcaption></figure><p><em>Commit Status Publishers</em> ensure Danger PR checks pass before merging ⬆️.</p><p>I recommend Danger Swift on CI because the tool <strong>codifies and enforces best practices</strong> on projects through easy automation. As with most automation, it takes time to reap the benefits, so <em>it’s worth the initial effort setting up</em> for most projects.</p><p>Check out the <a href="https://github.com/theappbusiness/ModularSlothCreator/pull/1">real PR</a> where the magic is all happening to see Danger Swift in action 🪄. I’ve left the SwiftLint warnings unaddressed for <em>demo purposes</em> but <strong><em>fix warnings</em></strong> on real projects!</p><p>I recommend iOS developers to learn and implement CI on projects because tooling is an <strong>important component in the app development ecosystem</strong> (raises project awareness!). It’s been a pleasure using Danger on our internal project at K+C and we’ve <em>already addressed 1 code coverage regression</em>! ✅</p><p>Ps. I‘m really proud to work somewhere where everybody strives to constantly <strong>push the boundaries of what’s possible</strong>. If that sounds like your cup of tea, why not <a href="https://www.kinandcarta.com/en/careers/">join us</a>?</p><p>I hope you found the article useful! 🙌 If you want to hear more from me, feel free to follow me on <a href="https://twitter.com/spidey_vitamins">Twitter</a> 🐤.</p><p><em>Thanks to </em><a href="https://medium.com/@felipericieri"><em>Felipe Ricieri</em></a><em> and </em><a href="https://medium.com/@oli_d"><em>Oliver Dew</em></a><em> for providing feedback.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83e3f5136a9a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kinandcartacreated/your-guide-to-danger-swift-on-ci-83e3f5136a9a">Your guide to Danger Swift on CI</a> was originally published in <a href="https://medium.com/kinandcartacreated">Kin + Carta Created</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Host and Automate your DocC documentation]]></title>
            <link>https://medium.com/kinandcartacreated/host-and-automate-your-docc-documentation-c6ac29dc0feb?source=rss-59ed2ec3be22------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6ac29dc0feb</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[docc]]></category>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Pranav Kasetti]]></dc:creator>
            <pubDate>Wed, 20 Apr 2022 14:55:22 GMT</pubDate>
            <atom:updated>2022-06-16T19:39:51.959Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VYb9S-QTjxCl0fV1jCguIA.png" /><figcaption>Figure 1: The DocC Build Process</figcaption></figure><p>We strive to keep up with the latest technologies at Kin + Carta because we are committed to delivering innovative, valuable projects for our clients. Naturally, the team were all very excited 🤩 when <strong>DocC was announced at WWDC 21</strong>, so we tested out the tool internally on a demo project.</p><p>If you’re interested in learning more about the tool, I recommend reading <a href="https://developer.apple.com/documentation/docc">Apple’s Developer Documentation</a> and watching their related <a href="https://developer.apple.com/videos/play/wwdc2021/10166/">WWDC DocC Introduction</a> and <a href="https://developer.apple.com/videos/play/wwdc2021/10236">WWDC DocC Hosting</a> videos before diving into this article.</p><p>We didn’t end up using DocC very much after our demo because the tool <strong>lacked some essential features like support for app targets and static website hosting</strong>. Don’t get me wrong though, I am a huge fan of documentation! In fact, I try to follow <strong>Documentation-Driven Development</strong> wherever possible! 😀 However, the tool didn’t make sense to use on client projects because we <strong>mainly build Apps</strong> rather than <strong>Swift Packages 📦</strong>.</p><p>At WWDC, Apple showcased how to generate and host DocC documentation and went into the details of <strong>configuring an Apache server with RewriteRules</strong> in a .htaccess file 🫣. We found this process cumbersome and so didn’t explore hosting.</p><p>However, with the release of Xcode 13.3, Apple has improved DocC a <strong>LOT</strong> with <a href="https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/publishing-to-github-pages/#Understanding-your-Project%E2%80%99s-Configuration">static hosting on GitHub Pages</a>, and app targets! 🥳 As a result, DocC can now provide value on a wider range of projects to implement Documentation-Driven Development.</p><p>In this article, I’ll cover how to <strong>automate the deployment of a modular Xcode workspace</strong> (frameworks, as well as an iOS App Target) with multiple .doccarchives to <strong>GitHub Pages as part of a single CI script ⚙️.</strong></p><h3>Requirements 📦</h3><ul><li>We’ll need to use <strong>Xcode 13.3 or above</strong> because only these Xcode CLI tools have the DocC CLI with support for static hosting.</li><li>We’ll need to have a GitHub Pro or Enterprise membership to host private repos with <strong>GitHub Pages</strong>. Alternatively, public repositories can use GitHub Pages for free.</li></ul><h3>Article Agenda ⏱</h3><ol><li><a href="#ba44">Setup Steps 🪜</a></li><li><a href="#b444">DocC CI Deployment Shell Script 🚀</a></li><li><a href="#53c7">DocC GitHub Workflow 🚏</a></li><li><a href="#e9a9">Documentation URLs 📝</a></li><li><a href="#d600">Conclusion 🎬</a></li></ol><h3>Setup Steps 🪜</h3><p>If you don’t have a project you’d like to integrate with DocC, fork the following repository: <a href="https://github.com/theappbusiness/ModularSlothCreator">https://github.com/theappbusiness/ModularSlothCreator</a>.</p><p>Clone the forked repository on your machine. Test out the documentation features in Xcode to ensure that DocC is configured correctly.</p><p>We will need to modify the forked CI script if we want to integrate DocC with our fork. Change ONLY the username in <em>ci_site_deploy.sh</em> to reflect the forked URL:</p><pre>git remote set-url origin <a href="https://$DOCC_GITHUB_USERNAME:$DOCC_GITHUB_API_TOKEN@github.com/theappbusiness/ModularSlothCreator/">https://$DOCC_GITHUB_USERNAME:$DOCC_GITHUB_API_TOKEN@github.com/&lt;insert_username&gt;/ModularSlothCreator/</a></pre><p><a href="https://github.com/settings/tokens/new">Create a GitHub Personal Access Token</a> with the <em>admin:repo_hook, repo </em>permissions. Copy and save the token for later.</p><p>You may notice in the <em>ci_site_deploy.sh </em>script that we have $ signs. These aren’t typos! $ signs are used to reference environment variables in Bash shell scripts. Define the environment variables in your CI configuration:</p><ul><li>DOCC_GITHUB_NAME to your Name.</li><li>DOCC_GITHUB_EMAIL to your GitHub Email.</li><li>DOCC_GITHUB_USERNAME to your GitHub Username.</li><li>DOCC_GITHUB_API_TOKEN to your Personal Access Token on your CI provider.</li></ul><p>Enable GitHub Pages on your feature/docc-hosting branch before deploying your repo on CI as outlined <a href="https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site">here</a>. Select docs as the deployed folder.</p><p>Great! We’ve now authenticated Git operations in the DocC deployment shell script. Use</p><pre>./ci_site_deploy.sh</pre><p>as a build step for a CI workflow. We can trigger this for every commit to the main / develop branch, or whatever makes sense for your project. I’ve used the main branch for ModularSlothCreator.</p><p>Now that our shell script is configured to run, let’s explore how the script works. You can skip the next section if you want because running the CI job should generate the required documentation.</p><p>NB: For those of you wondering “What’s a Modular Sloth Creator ??” 😄, I’m adapting Apple’s Sample Code for DocC that used an app called Sloth 🦥 Creator. We’ll be using a <strong>Modular SlothCreator project </strong>to test the hosting of <em>multiple .doccarchives with a single CI script</em>.</p><h3>DocC CI Deployment Shell Script 🚀</h3><h4>Build Documentation 🧱</h4><p>We build the documentation for all modules with:</p><pre>xcodebuild -project ModularSlothCreator.xcodeproj -derivedDataPath docsData -scheme ModularSlothCreator -destination &#39;platform=iOS Simulator,name=iPhone 13 Pro Max&#39; -parallelizeTargets docbuild</pre><p>The docbuild command builds documentation as we might expect from the name, and we need the -parallelizeTargets flag to build modular workspaces.</p><p>We’ve selected the -project flag rather than the -workspace flag for our project with the associated -scheme, however, you may need to change this on a case-by-case basis, for example with CocoaPods projects.</p><p>We’ve specified a specific simulator using the -destination specifier to ensure we use an eligible <em>virtual</em> destination for our project. You may need to change this to a macOS destination for macOS projects.</p><p>docbuild generates documentation in the “DerivedData” by default, so we’ve used a local Derived Data path with -derivedDataPath docsData to ensure easy access with the later script commands.</p><h4>Store documentation archives 🗃</h4><pre>echo &quot;Copying DocC archives to doc_archives...&quot;</pre><pre>mkdir doc_archives</pre><pre>cp -R `find docsData -type d -name &quot;*.doccarchive&quot;` doc_archives</pre><p>I plan to check in the .doccarchive packages themselves into Version Control for easier maintenance and regression tracking. To make things easier, the above commands copy the archives into a dedicated doc_archives folder.</p><h4>Generate the Static Site 🕸</h4><pre>$(xcrun --find docc) process-archive transform-for-static-hosting &quot;$ARCHIVE&quot; --hosting-base-path ModularSlothCreator/$ARCHIVE_NAME --output-path docs/$ARCHIVE_NAME</pre><p>The above command is part of a for loop that generates the static website content for each .doccarchive. The transform-for-static-hosting flag is new with Xcode 13.3.</p><p>We store the hosted content in the docs folder to ensure GitHub Pages only host the generated website content. We configured GitHub Pages to only host from the docs folder if you remember from above.</p><p>We’ve used the Repository Name and the Archive Name (lowercased!) together for the --hosting-base-path to enable us to host multiple .doccarchives on the same top-level domain. URLs are case-sensitive, so be careful.</p><h4>Push to GitHub ⬆</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9fd79f8318d50701055fa6ce1a1dd40/href">https://medium.com/media/c9fd79f8318d50701055fa6ce1a1dd40/href</a></iframe><p>The remainder of the script authenticates our CI to push to our GitHub repository’s feature/docc-hosting branch, which then gets hosted automatically. 🪄</p><h3>DocC GitHub Workflow 🚏</h3><p>Rather than merging in a lot of statically generated website content which can total 1000s of files(!!), we’ve used a simpler workflow where we dedicate a single feature/docc-hosting branch that never gets merged into main or develop but exists for the sole purpose of hosting documentation. We trigger our DocC script on merges to develop / main.</p><p>It’s not feasible to code review 1000s of files, but we can catch documentation errors using multiple strategies:</p><ol><li>Ensure the <em>public </em>APIs are documented with /// as part of the code review process.</li><li>Add a checklist to the PULL_REQUEST_TEMPLATE.md file to ensure documentation comments are added to new functions, types, or modules.</li><li>Enable build failure notifications for DocC CI jobs to ensure deployments are all passing as expected.</li><li>Sanity checking the generated documentation after merging a PR.</li></ol><p>This workflow worked well for us because we had confidence in our CI process and script.</p><h3>Documentation URLs 📝</h3><p>We can view the documentation for my original repository at the following URLs:</p><ul><li><a href="https://theappbusiness.github.io/ModularSlothCreator/care/documentation/care">https://theappbusiness.github.io/ModularSlothCreator/care/documentation/care</a></li><li><a href="https://theappbusiness.github.io/ModularSlothCreator/creation/documentation/creation">https://theappbusiness.github.io/ModularSlothCreator/creation/documentation/creation</a></li><li><a href="https://theappbusiness/">https://theappbusiness</a>.<a href="http://github.io/ModularSlothCreator/models/documentation/models">github.io/ModularSlothCreator/models/documentation/models</a></li><li><a href="https://theappbusiness.github.io/ModularSlothCreator/viewing/documentation/viewing">https://theappbusiness.github.io/ModularSlothCreator/viewing/documentation/viewing</a></li></ul><p>Note that these generated URLs are case sensitive! If you’ve triggered your own CI job, we need to replace <a href="https://theappbusiness.github.io/">https://theappbusiness.github.io</a> with https://&lt;username&gt;.github.io in the above example.</p><p>Play around with the fancy Apple Developer style documentation in Dark Mode or Light Mode to your heart&#39;s content! 😍</p><figure><img alt="DocC Hosted Documentation for the ModularSlothCreator Creation module in Dark Mode" src="https://cdn-images-1.medium.com/max/1024/1*YH4C-WvbScO9xAjFWgni8w.png" /><figcaption>Figure 3: DocC ModularSlothCreator Documentation for the Creation module in Dark Mode</figcaption></figure><h3>Conclusion 🎬</h3><p>Documentation-Driven Development is easy with DocC for modular workspaces because they have public APIs. I’d recommend adopting the workflow for new projects because the Hosted Documentation provides a lot of <em>value</em> without a lot of <em>maintenance</em> 💯.</p><p>Generating documentation on the fly is great for improving the onboarding process to help developers get up to speed quickly when joining a new project. It may even be helpful for non-technical team members to get a feel for the codebase.</p><p>DocC Hosting makes sense for greenfield projects where it’s feasible to document the codebase as it grows, but this would be harder for migrating existing large codebases. I recommend using DocC for newer projects because we also can’t always use Xcode 13.3 (and the latest tools) for older codebases.</p><p>As the Apple ecosystem matures, I hope more codebases use DocC to ensure a great developer experience and project transparency. It’s been a pleasure to use on our internal project at Kin + Carta, and has already helped onboard some new team members! 😃</p><p>Ps. It’s worth keeping an eye on DocC because there are <a href="https://forums.swift.org/t/document-extensions-to-external-types-using-docc/56060">plans on Swift Evolution</a> to improve it further!</p><p>I hope you found the article useful! 🙌 If you want to hear more from me, feel free to follow me on <a href="https://twitter.com/spidey_vitamins">Twitter</a> 🐤.</p><p><em>Thanks to </em><a href="https://medium.com/@felipericieri"><em>Felipe Ricieri</em></a><em> for providing feedback.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6ac29dc0feb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kinandcartacreated/host-and-automate-your-docc-documentation-c6ac29dc0feb">Host and Automate your DocC documentation</a> was originally published in <a href="https://medium.com/kinandcartacreated">Kin + Carta Created</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with Xcode Cloud: Pull Request (PR) Workflow]]></title>
            <link>https://medium.com/kinandcartacreated/getting-started-with-xcode-cloud-pull-request-pr-workflow-ce02bb83f9e5?source=rss-59ed2ec3be22------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce02bb83f9e5</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[xcode-cloud]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Pranav Kasetti]]></dc:creator>
            <pubDate>Tue, 08 Mar 2022 12:44:39 GMT</pubDate>
            <atom:updated>2022-03-08T12:44:39.963Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Figure 1: Xcode Cloud development cycle" src="https://cdn-images-1.medium.com/max/1024/1*4UK7r_HsJqk85CbhoJ66zQ.png" /><figcaption>Figure 1: Xcode Cloud Development Cycle</figcaption></figure><blockquote>This tutorial is for people who know about Version Control, what CI and CD are about and are looking to try out Xcode Cloud on their project. We will be covering getting set up to CI and CD with Xcode Cloud, and walkthrough a GitHub Pull Request (PR) workflow.</blockquote><p>Xcode Cloud is currently in private beta, however, I am in a lucky position because I am one of the first developers who has been provided <strong>free</strong> access. Hopefully, this series will help those looking to set up Xcode Cloud as Apple provides wider access to the community.</p><p>I recommend reading my “<a href="https://medium.com/kinandcartacreated/the-missing-handbook-for-continuous-integration-continuous-deployment-start-here-a859f595793b">missing handbook for Continuous Integration &amp; Continuous Deployment</a>” article first if you’re new to CI and CD.</p><h3>Prerequisites</h3><ul><li>Apple Developer Program membership ($99 / yr) 💸</li><li>Xcode Cloud (beta at the time of writing) access</li><li>Xcode 13.3 beta or above</li></ul><p>If you already meet the pre-requisites to use Xcode Cloud, congratulations! 🥳Only about 10,000 developers worldwide have free access at the time of writing. If you don’t, don’t worry! You can easily sign up for the Xcode Cloud beta in App Store Connect as a Developer Program Member from your App pages by selecting and requesting access on the new Xcode Cloud tab. Or <a href="https://developer.apple.com/xcode-cloud/beta/">here</a>.</p><p><strong>PRO TIP 😉:</strong> Sign up for the beta from every developer account in your team. I think demonstrating eagerness helped me get early access 👀.</p><p>To follow along with the tutorial, clone and open the Xcode project from the <a href="https://github.com/LemonSpike/CloudJokes">CloudJokes repo</a>.</p><h3>Article Agenda</h3><ol><li><a href="#8273">What is Xcode Cloud? ☁️</a></li><li><a href="#bd2a">What are Workflows? 💼</a></li><li><a href="#b73f">What’s a Pull Request Workflow? 🕵️</a></li><li><a href="#a812">Set up a PR Workflow 🦦</a></li><li><a href="#54ad">Set up Code Signing ✍️</a></li><li><a href="#fce0">Add new Remote 📺</a></li><li><a href="#4d37">Create a Workflow ✨</a></li><li><a href="#06f9">PR Workflow General 🏠</a></li><li><a href="#a4fe">PR Workflow Environment 🌳</a></li><li><a href="#fd1a">PR Workflow Start Conditions 🎬</a></li><li><a href="#231c">PR Workflow Actions 👷‍♀️</a></li><li><a href="#7132">Grant Access to your Source Code 🔓</a></li><li><a href="#c76a">Create App on App Store Connect 🔗</a></li><li><a href="#f396">PR Workflow Post-Actions 🎁</a></li></ol><h3>What is Xcode Cloud? ☁️</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ODGOlet9jmr3rM7CA_CreA.png" /><figcaption>Figure 2: Xcode Cloud tightly integrates Testflight, App Store Connect and Xcode</figcaption></figure><p>Xcode Cloud is Apple’s hosted CI and CD service that integrates Xcode with Testflight and App Store Connect to build, test, and distribute apps for the Apple ecosystem (as shown in Figure 2). Apple currently offers a self-hosted solution with Xcode Server, but developers complained that build issues are hard to debug, machines need to be maintained with DevOps teams, and there are fewer integrations with Slack or PR webhooks. 😭</p><p>GitHub Actions, Bitrise, Fastlane, and CircleCI offer very popular hosted CI solutions. Fastlane has 34k ⭐️s on GitHub, and Bitrise has millions of daily builds 🛠. Apple currently does not offer a competitive product in the hosted developer tooling space.</p><blockquote>That all changes with Xcode Cloud 🎉.</blockquote><p>Xcode Cloud is Apple’s answer to Fastlane, Bitrise and Actions for its ecosystem. Apple tried to acquire Fastlane a few years ago but failed. Apple has since then been working hard to develop its infrastructure, for example, by acquiring BuddyBuild. Apple released the App Store Connect API in 2019 and are now leveraging the API to build a higher-level CD and CI platform.</p><p>Xcode Cloud supports builds across iOS, macOS, watchOS and tvOS. Apple doesn’t offer cross-platform support with Android 🤖 or Windows 🪟 though. As a result, Xcode Cloud may not make financial sense for cross-functional development teams because it’s less flexible than other excellent providers like GitHub Actions.</p><p>Xcode Cloud was designed by Apple with simplicity, ease of use and great user experience in mind. As with most Apple products, technical details are abstracted away from the user, enabling powerful functionality for the essential Apple development workflows. Xcode Cloud supports Swift Package dependencies out of the box along with CocoaPods and Carthage. 🏆</p><p><strong>NOTE:</strong> Xcode Cloud does NOT support projects using the Legacy Build System. This isn’t a problem for newer projects but can be a blocker when migrating legacy projects to Xcode Cloud.</p><h3>What are Workflows? 💼</h3><p>Workflows define the steps taken for every CI job in chronological order. Workflows are Xcode Cloud’s equivalent to a single GitHub Action or Bitrise Workflows. Workflows are categorised into 4 stages:</p><ol><li><strong>Environment 🌳:</strong> The environment includes the macOS and Xcode versions used by the CI runners and environment settings such as environment variables or clean builds.</li><li><strong>Start conditions</strong> 🎬<strong>:</strong> Xcode Cloud enables 4 start conditions — Branch Changes, PR Changes (the focus of this article), Tag Changes or On a Schedule. Xcode Cloud integrates with VCS providers like GitHub and BitBucket to enable actions by subscribing to webhooks. We can further customise each category in the Workflow Editor.</li><li><strong>Actions</strong> 👷‍♀️<strong>:</strong> The majority of build time will be spent performing the main workflow tasks called Actions. Xcode Cloud has 4 action categories — Build, Test, Analyze and Archive. We can customise the scheme, platform and action-specific settings within each category.</li><li><strong>Post-Actions</strong> 🎁<strong>:</strong> Post-Actions are either distribution actions to Testflight or Notifications. We use the output from the Archive action to deploy the app and can customise Notifications for Slack, email and build status.</li></ol><p>Let’s go through how to set up these components for a basic Pull Request (PR) workflow. 🙌</p><h3>What’s a Pull Request Workflow? 🕵️</h3><h4>Pull Request? 🤷‍♂️</h4><p>Pull Requests are a feature of version control providers such as GitHub or BitBucket. They integrate with git projects and form the backbone of <strong><em>code review</em></strong> within <strong>software development teams</strong>. Pull requests are used for apps that are pushed into production and are usually performed within the browser.</p><p><a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests">GitHub explains</a> their Pull Request as follows:</p><blockquote><em>Pull requests let you tell others about changes you’ve pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch.</em></blockquote><p><strong>PSA 🚨</strong>: git is a free and open-source distributed version control system. <em>GitHub</em> (short for GitHub, Inc.) is a provider of Internet hosting for software development and version control using Git.</p><h4>Pull Request Workflow? ☕️</h4><p>As the name suggests, the PR workflow uses GitHub / BitBucket webhooks to run Xcode Cloud on PR changes. A Pull Request workflow works well with software development teams developing production apps. Apple recommends a PR Workflow to <strong>test and analyze codebases before internal distribution</strong> (via TestFlight).</p><h3>Set up a PR Workflow 🦦</h3><p>After Apple grants you access to Xcode Cloud, we need to do 5 main steps to get started:</p><ol><li>Set up <strong>automatic</strong> code-signing. Xcode Cloud does not currently work with manually signed apps.</li><li>Set up a <strong>new remote</strong> for the repository on your own GitHub account.</li><li>Create a workflow for your app.</li><li>Link your hosted repository with Xcode Cloud via your VCS provider in Xcode.</li><li>Start your first build.</li></ol><p>Apple likes to make things easy, and Xcode Cloud is no exception. We’ll focus this article on implementing the PR workflow for our simple jokes app.</p><h3>Set up Code Signing ✍️</h3><p>First, we’ll need to change our bundle identifier and our code-signing configuration to use a <strong>new development team with Xcode Cloud access</strong>.</p><p>Follow the steps outlined below, as visualised in Figures 3 and 4:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ViNzkQZWyfaTQQYjFRM85A.png" /><figcaption>Figure 3: Change the bundle identifier in Xcode for CloudJokes</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*57BXGFEhBmyP9lLvmRzEJg.png" /><figcaption>Figure 4: Change the code signing configuration in Xcode for CloudJokes</figcaption></figure><ol><li>Select your root CloudJokes.xcproject file from the File Navigator</li><li>Select the CloudJokes (iOS) target as shown in Figure 3.</li><li>Change the Bundle Identifier text field to be your own Organisation Identifier followed by CloudJokes. For example, I have used com.kasprasolutions.CloudJokes but we could use com.kinandcarta.CloudJokes for a new project. We need to change the Organisation Identifier because App Store Connect prevents us from creating new app records that use the same bundle identifier as another registered app.</li><li>Select the “Signing &amp; Capabilities” tab.</li><li>Check that the “Automatically Manage Signing” checkbox is enabled.</li><li>Change the development team to your organisation / personal Apple development team that has Xcode Cloud access.</li><li>Repeat steps 3–6 for the CloudJokes (macOS), Tests iOS and Tests macOS targets as shown in Figures 3 and 4.</li><li>Resolve any organisation code signing errors and verify the project builds.</li></ol><h3>Add new Remote 📺</h3><p>Use the <a href="https://cli.github.com/">GitHub CLI</a> to push the existing repository to a new remote on your personal GitHub account.</p><p>$ cd CloudJokes &amp;&amp; gh repo create</p><p>Use the “Push an existing local repository to GitHub” option, name the new remote something different to origin, and push the commits to the new remote. Xcode Cloud requires you to have admin permissions on your repository, so we need to create a new repository with admin access.</p><p><strong>NB:</strong> I prefer using the GH CLI instead of following the website flow or forking, but YMMV.</p><h3>Create a Workflow ✨</h3><p>The next step we need to take is to Create an Xcode Cloud Workflow. Make sure the Report navigator is visible, select the Cloud tab, and then click Create Workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*59Fw-_52BlZ6KxXyMLoOhA.png" /><figcaption>Figure 5: “Create Workflow” prompt in Xcode for CloudJokes</figcaption></figure><p>Clicking this button will prompt you to select a product to configure Xcode Cloud as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ypdiADTHqBImL1nhY8TI-g.png" /><figcaption>Figure 6: “Select a Product” prompt in Xcode for CloudJokes</figcaption></figure><p>If you are part of multiple developer teams within App Store Connect you will have an additional “Team” column where you can select an Xcode Cloud eligible developer account. If you have multiple accounts with access to Xcode Cloud, try to be consistent by using the same team with Xcode Cloud that you selected previously for code signing.</p><p>Once you’ve selected a compatible product and team, the “Next” button will become clickable. Click “Next”.</p><p>You’ll now be able to review Xcode Cloud’s default Workflow. Click “Edit Workflow” to bring up the Workflow Editor.</p><h3>PR Workflow General 🏠</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KoP-hE825ssKlh_LcKxIsg.png" /><figcaption>Figure 7: “General” prompt in Xcode Cloud Workflow Editor</figcaption></figure><ol><li>Set the “Name” of your Workflow to “Pull Requests”.</li><li>Set the description to whatever you like.</li><li>Restrict Editing to Admins or App Managers only by selecting the checkbox.</li><li>Select the Primary Repository to the new CloudJokes remote you created earlier (Important!).</li><li>Select the CloudJokes.xcodeproj project.</li></ol><h3>PR Workflow Environment 🌳</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aAZiTVM2b13q6tsB4npdWA.png" /><figcaption>Figure 8: “Environment” prompt in Xcode Cloud Workflow Editor</figcaption></figure><p>Within the PR Workflow, we’ve set the Xcode and Mac environment we want our runners to use and haven’t set any environment variables. Environment variables are the same as with GitHub Actions or other CIs.</p><h4>What should we choose for the Xcode environment?</h4><p>We can stick to the Latest Release of Xcode, the Latest Beta or manually select a version. The great thing about choosing the Latest Release option is we don’t need to manually change the version as Xcode gets updated. This can also mean however that builds break over time as languages or frameworks evolve. Beta releases may enable newer language features, however may be unstable and unsuitable for legacy projects. Choosing the right Xcode is a trade-off that depends on the project.</p><p>The same considerations apply to choosing the Latest macOS version, Latest Beta macOS or a specific OS version.</p><p>For our purposes, using the Latest Release is sufficient, so we’ll stick with the default options Xcode created.</p><h4>Clean builds?</h4><p>We also need to consider the option to enable “Clean builds” in our environment. Clean builds slow down build times without using DerivedData, however, they make sense for functionality-critical workflows. For Distributing apps via Testflight, we need to enable the “clean build” setting to prevent using cached functionality that is no longer up to date for deployment.</p><p>Enable Clean Builds for CloudJokes by selecting the checkbox.</p><h4>Environment Variables (envvars)?</h4><p>The final environment option is environment variables. Environment variables are similar to fastlane + Bitrise environment variables. We can choose to make the variables secret for hiding sensitive information, like API Keys, so that they are encrypted and securely stored. We can use envvars for anything we don’t want to check into source control or to configure runtime behaviour. Environment variables are also helpful when mocking an API in UI tests for example.</p><p>Environments in the Workflow Editor don’t include scripts, these need to be added in the ci_scripts folder in the project’s root directory. We&#39;ll cover configuring CI scripts in a future article.</p><p>We won’t need any envvars for this project.</p><h3>PR Workflow Start Conditions 🎬</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fanhpNXURLVFjrmBSyqQHg.png" /><figcaption>Figure 9: “Pull Request Changes” prompt in Xcode Cloud Workflow Editor</figcaption></figure><p>When we open Xcode’s Default Workflow, we get a “Branch Changes” start condition automatically. In order to replace this start condition, let’s create a new “PR Changes” start condition.</p><ol><li>Click the + button beside the &quot;Start Conditions&quot; title in the sidebar of the Workflow editor, and select &quot;Pull Request Changes&quot;.</li><li>Select the Branch Changes Start Condition, and delete the step by clicking the 🗑 icon in the top right of the Workflow Editor.</li><li>Set up the PR Changes step as outlined in Figure 9 above.</li></ol><p>Apple has now enabled multiple start conditions in the latest beta, allowing more versatility for different stages of your development workflow. Start conditions are the conditions that trigger Workflow Actions.</p><p>We can trigger a Workflow for combinations of Any or Custom Source and Target branches for PRs. We can also further narrow the start condition to only trigger upon changes to certain files or folders in the project.</p><p>For our purposes, we will leave the defaults as above. Auto-Cancelling builds is a best practice for saving billing time since we only want to distribute the latest PR commits. Unlike Release Workflows, we don’t need the build artefacts (IPAs) of every commit, so we check Auto-cancel builds.</p><h3>PR Workflow Actions 👷‍♀️</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qeLflMoYTAlLRg5ybCTnkA.png" /><figcaption>Figure 10: “Test” Action prompt in Xcode Cloud Workflow Editor</figcaption></figure><p>For now, we can delete the “Archive — macOS” step (using the 🗑 icon as before), add the “Test — iOS” and “Analyze — iOS” step to the set of Actions. Click the + icon (as we clicked for the Start Conditions) beside the &quot;Actions&quot; tab in the sidebar, add a Test action and add an Analyze action. iOS should be the preselected platform for these actions by default</p><p>We need to further configure the Test action as shown in Figure 10:</p><ol><li>Select the “iOS” Platform.</li><li>Select the “CloudJokes (iOS)” Scheme.</li><li>Select “Required to Pass”.</li><li>Select “Use Scheme Settings”.</li><li>Click the + button just below the &quot;Destination -&gt; OS Version&quot; table. You will see that Apple&#39;s &quot;Recommended iPhones&quot; stack for tests automagically populates the table. 🪄 If you click the + button once more, you will see a stack of “Recommended iPads” as well. We will stick to iPhones only for now to streamline build times.</li></ol><p>Xcode Cloud updates a Recommended stack of iPhones and iPads to run tests on which means we don’t need to manually update workflows. This is very helpful to ensure the app is being tested across a range of screen sizes and works well on the latest devices. We don’t need to manually update and maintain this stack, which offers developers greater convenience.</p><p><strong>BONUS NOTES 🍀:</strong> Xcode Cloud enables test plans within different workflows, so we can distribute the load accordingly. In fact, this is the same setup as the Apple swift repo with separate Actions for Smoke Tests and the full suite for Release and PR workflows. This flexibility is helpful to balance CI load for large scale apps where running the whole test suite isn’t feasible on every PR but is essential for changes to production branches.</p><p>Since we haven’t created the Workflow yet, we will need to configure Post-Actions later. For now, click the “Save” button in the bottom right corner of the Workflow Editor. Xcode navigates us back to the “Review Workflow scene”, where we can now select “Next”.</p><h3>Grant Access to your Source Code 🔓</h3><p>Follow Xcode’s prompt to grant access to your Source Code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*12S4GiCpW0peuq-2zVFOzQ.png" /><figcaption>Figure 11: “Grant Access to Your Source Code” prompt in Xcode Cloud</figcaption></figure><p>After you’ve granted Xcode Cloud access, you’ll be navigated back into Xcode. Click “Next”.</p><h3>Create App on App Store Connect 🔗</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XVoYWSfbJCzWphofQYs56Q.png" /><figcaption>Figure 12: “Create App on App Store Connect” prompt in Xcode</figcaption></figure><p>Confirm the details are all correct and click “Complete” to create an App Store Connect record for CloudJokes. If all went well, you should see the success screen 🎉:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uCZg2EcPBazMsagzmL39Mg.png" /><figcaption>Figure 13: “CloudJokes is now configured” prompt in Xcode</figcaption></figure><p>Since we haven’t fully configured the Workflow yet, click “Close”.</p><h3>PR Workflow Post-Actions 🎁</h3><p>We now have a template Pull Requests workflow in our Report Navigator on the left side of Xcode’s editor. Right-click on the “Pull Requests” section and select “Edit Workflow”. You should now see the same Workflow Editor as before but with more options.</p><ol><li>Select “Testflight (Internal Testing Only)” for the Deployment Preparation section within the Archive action.</li><li>Add a new Post-Action “Testflight Internal Distribution” for an internal App Store Connect group (set this up on the App Store Connect web portal if you don’t have one already).</li><li>Add a Notify Post-Action adding your email address as a subscriber.</li><li>Save your changes.</li></ol><p>Post Actions are additional actions that use the outputs from the Action stages to either deploy builds or send notifications. We can enable Notifications via Slack or Emails and can customise them for successes only, failures only or all outcomes. Unfortunately, deployment options are currently only limited to Testflight or App Store Connect within Xcode Cloud.</p><p>You can now trigger a test build, by right-clicking on the “Pull Requests” section and selecting the “Start Build” option for your “main” branch. 🛠</p><p>You should now be able to track your build status within Xcode by selecting Build 1 in the Report Navigator. 🎊🎉 The build <strong>should succeed</strong> but may not at the moment because Xcode Cloud is going through some teething issues on the server-side.</p><p>If you want to test out your workflow more thoroughly, try creating a new branch and PR on GitHub to trigger the workflow automatically.</p><p>Thanks for reading! If you enjoyed this article and want to hear more from me, please follow me on <a href="https://twitter.com/spidey_vitamins">Twitter</a>. Happy coding! 👨‍💻</p><p><em>Special thanks to </em><a href="https://medium.com/@felipericieri"><em>Felipe Ricieri</em></a><em> for providing feedback.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce02bb83f9e5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kinandcartacreated/getting-started-with-xcode-cloud-pull-request-pr-workflow-ce02bb83f9e5">Getting started with Xcode Cloud: Pull Request (PR) Workflow</a> was originally published in <a href="https://medium.com/kinandcartacreated">Kin + Carta Created</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The missing handbook for Continuous Integration & Continuous Deployment (start here)]]></title>
            <link>https://medium.com/kinandcartacreated/the-missing-handbook-for-continuous-integration-continuous-deployment-start-here-a859f595793b?source=rss-59ed2ec3be22------2</link>
            <guid isPermaLink="false">https://medium.com/p/a859f595793b</guid>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Pranav Kasetti]]></dc:creator>
            <pubDate>Tue, 08 Mar 2022 11:28:47 GMT</pubDate>
            <atom:updated>2022-05-20T15:37:21.045Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Image of a typical Software Development Workplace." src="https://cdn-images-1.medium.com/max/1024/1*eZV1U2lJ9RONTdqfANPrqA.jpeg" /><figcaption>Fig 1: Software Development Workplace (taken from <a href="https://unsplash.com/photos/FSFfEQkd1sc">Unsplash</a>)</figcaption></figure><p><strong>Continuous Integration (CI)</strong> and <strong>Continuous Delivery (CD)</strong> are industry buzzwords these days for software developers. The industry is moving at a rapid pace, so it can be hard to keep up with new initiatives like the <strong>DevOps movement</strong>. This article aims to fill the gaps left by other articles in the space by speaking from a mobile developer&#39;s perspective rather than from the business/product point of view.</p><p>This article is an introductory, general article about CI and CD. I will bring you up to speed on CI and CD, their benefits and how to use them on projects. I don’t assume any previous experience and aim to make the ecosystem more digestible for beginners. While my experience is in mobile development, the benefits apply across development stacks.</p><h3>Article Agenda</h3><ol><li>What are <a href="#e06c">CI</a> and <a href="#3593">CD</a>?</li><li><a href="#f483">Where do they fit into DevOps?</a></li><li><a href="#88d1">How do CI and CD workflows help developers?</a></li><li><a href="#7e9e">Automation ⚙️</a></li><li><a href="#0dbf">Configuration 📝</a></li><li><a href="#5108">Metrics 📊</a></li><li><a href="#75aa">Where can I implement CI?</a></li><li><a href="#30bb">Final thoughts 📚</a></li></ol><figure><img alt="XKCD 1319 sketch shows the reality of automation in practice." src="https://cdn-images-1.medium.com/max/807/1*J7PyO7KLGbUg6jHr6SQXkg.png" /><figcaption>Fig 2: XKCD 1319 on Automation (taken from <a href="https://xkcd.com/1319/">https://xkcd.com/1319/</a>)</figcaption></figure><h3>What is CI? 🤓</h3><p>CI stands for Continuous Integration. According to <a href="https://martinfowler.com/articles/continuousIntegration.html#BenefitsOfContinuousIntegration">Martin Fowler</a>:</p><blockquote>Continuous Integration is a software development practice where members of a team integrate their work frequently.</blockquote><p>Continuous Integration usually means the automation of codebase builds and tests continuously during the development lifecycle, rather than <em>deferring </em>to integrate different features before delivery.</p><p>Continuous Integration helps development teams to identify bugs quickly, what parts work and what parts are broken. CI thus increases the visibility of project health through automation.</p><h3>What is CD? 🚚</h3><p>The “CD” in CI/CD can refer to continuous delivery and/or continuous deployment in different contexts. The concepts are similar and sometimes get used interchangeably. I am a fan of Martin Fowler&#39;s <a href="https://martinfowler.com/bliki/ContinuousDelivery.html">blog</a>, so will be quoting him again:</p><blockquote>Continuous Delivery is a software development discipline where you build software in such a way that the software can be released to production at any time.</blockquote><p>Continuous Delivery complements CI, which is why they are often mentioned together. CD ensures that features are regularly deployed because, at any point, the current development version of the app could be deployed to production. Continuous Delivery automates the testing of code changes before they are merged into a repository, increasing the visibility of metrics with business teams. We still need to <em>deploy</em> the code to a production environment after Continuous Delivery.</p><p>Continuous Deployment (also CD!) is similar to Continuous Delivery, where every change goes through the deployment pipeline and is pushed into production. Continuously Delivered projects can often be changed to Continuously Deployed projects very easily, but aren’t because the company prefers following the Agile Scrum framework instead of Kanban, for example. Continuous Deployment automates the next stage of the pipeline after Continuous Delivery and reduces the workload of operations teams by automating an otherwise manual process.</p><p>CI and CD form the backbone of DevOps, which has grown so much in popularity in recent years that it’s become a movement. CI and CD <a href="https://www.microsoft.com/insidetrack/blog/how-microsoft-is-delivering-smart-building-experiences-with-ci-cd-for-azure-digital-twins/">have been tried and tested at scale</a> in the real world with great results. A wide variety of companies (including Microsoft) champion CI and CD workflows because they have seen radical benefits in their own projects. We will cover the benefits of such tooling in this article.</p><h3>DevOps Practices (context)</h3><ul><li>Continuous Integration, Continuous Delivery and Continuous Deployment (CI/CD)</li><li>Version control</li><li>Agile software development</li><li>Infrastructure as code</li><li>Configuration management</li><li>Continuous monitoring</li></ul><p>We can incorporate CI or CD workflows within the company as a self-hosted environment, or leverage the infrastructure of large providers. Most projects use a self-hosted or hosted CI/CD provider such as Bitrise, CircleCI, TeamCity, GitHub Actions, AppCenter, or Xcode Cloud (beta).</p><h3>How do CI and CD help a team? 👫</h3><p>We can group the benefits of CI and CD for software development teams into 3 broad categories:</p><ol><li>Automation (Convenience)</li><li>Configuration (Project Flexibility)</li><li>Metrics (Transparency)</li></ol><h3>Automation ⚙️</h3><p>CI and CD are essentially forms of developer automation. CI is usually triggered by Git webhooks on changes to Pull Requests, Branches, Tags, or time so we don’t need to think about it. CI provides automation, and the main theme for automation benefits is <em>convenience.</em></p><h4>Time-Saving</h4><p>Automation of small tasks <strong>saves lots of time</strong> in the long run through compounding. We can often save 30 minutes from running a test suite on large projects with CI, and this time compounds to 100s of hours in a year (equivalent to another 2-week release!). CI + CD can increase the capacity of a development team because every developer on the team is more productive.</p><h4>Automate Testing</h4><p>CI + CD <strong>automates best practices</strong> such as testing. CI + CD tests can <strong>test across a wider range of target devices</strong> (Macs, iOS device screen sizes, Apple Watches), OS versions and Development Environments (Xcode versions), making the QA process <strong>easier, and much more rigorous</strong>. Automated Unit, UI and Snapshot Testing<strong> also reduce the load</strong> on dedicated QA teams.</p><h4>Integrate Stability into VCS</h4><p>CI testing <strong>bakes stability into a development workflow</strong> because CI tests can catch bugs in a code review that developers may miss. We can implement a process that prevents merging PRs that fail automated test suites because CI + CD can be <strong>integrated into source control providers</strong>.</p><h4>Write Better Software</h4><p>Automation with CI and CD can lead to a better software team by implementing <strong>3.5/12 steps of </strong><a href="https://www.joelonsoftware.com/2000/08/09/the-joel-test-12-steps-to-better-code/"><strong>the Joel Test</strong></a><strong> 🧪</strong>: Use Version Control, Make a build in one step, Make daily builds, and Use the best tools money can buy. CI and CD tools are generally powerful, high-quality tools, however, they are only part of a development toolkit, which is why they only tick 0.5 of that step.</p><h4>Improve Developer Experience</h4><p>Automation improves the <strong>developer experience</strong> because we don’t have to think as much during everyday development. While it’s always good to thoroughly test our app locally, we no longer have to worry if we forgot to.</p><h4>Improve Developer Culture</h4><p>Automation is a process improvement that can have knock-on effects to <strong>improve developer culture</strong>. Paying attention to seemingly unimportant processes like CI encourages the team to <strong>pay attention more</strong> generally <strong>to details</strong>. Attention to detail is crucial for building quality software, so it can encourage a culture of <strong>software craftsmanship.</strong></p><p>Further, <strong>CI shifts blame</strong> from the commit author <strong>to the CI system</strong> for failing builds. CIs automate some of the tedious code review checks like tests, indentation, whitespace or general styling through linters and PR integration.</p><p>Rather than git blame causing arguments and friction, we can blame the process, and improve it. Ps. I would prefer if git blame was git author.</p><blockquote>Small changes make a big difference. 🙌</blockquote><h4>Improve Developer Focus</h4><p>A simple git push triggers a suite of tests automatically and also <strong>handles deployment</strong> to Testflight, AppCenter, TeamCity or the App Store. Developers need to focus on <strong>solving real engineering challenges</strong>, not manually distributing apps on AppCenter. Developers get more time delivering app features rather than manually deploying apps with a stable CD setup. The end result of stable Continuous Delivery is a <strong>higher team velocity</strong>.</p><h4>Automate Complex, Precise Tasks like Code Signing (iOS)</h4><p>CI automation can <strong>prevent code-signing ✍️ bugs</strong>. Managing manual code-signing configurations is a real pain point in iOS development because App Store Connect has a complex, unintuitive UX. These <strong>bugs can be almost entirely avoided by delegating code signing tasks to CI / CD</strong>. <strong>CI + CD manage the complexity</strong> of manual code-signing automatically with encoded, definite steps.</p><p>For those of you who are not iOS/macOS developers, code signing is a necessary step to deploy apps on the App Store. Code signing has lots of aspects: certificates, app IDs, provisioning profiles, and registered device lists for each target platform and target type. Example code-signing issues could include:</p><ol><li>We can avoid accidentally <strong>using the wrong certificate</strong> when opening the project on a new machine. Development and Distribution certificates can be confusing for project beginners, and we may break configurations to build the app locally.</li><li>We can prevent <strong>creating extra provisioning profiles</strong> for an existing project. Instead of importing the missing profiles through Xcode, we may end up creating additional profiles by mistake.</li><li>The precious attention of more senior team members can be saved from cleaning up a cluttered developer portal after <strong>accidentally triggering automatic code-signing</strong> for a manually code-signed project.</li></ol><p>Automation of complex steps is especially helpful for teams who are onboarding junior developers or recently joined developers but <strong>anybody can make these mistakes</strong>. Automation of complex tasks <strong>improves project stability</strong>.</p><p><strong>NOTE: CI + CD systems are generally cross-platform</strong> so deployment configuration improvements outside the Apple ecosystem are also possible.</p><h4>Notify Teams Immediately</h4><p>CI + CD can also automate the delivery of <strong>notifications</strong> with Twitter, Email or Slack. By automating notifications, the productivity of a team improves because the team can respond <strong>immediately after an issue has been identified. </strong>Notifications are crucial in time-critical hotfixes but improve the response time of the team in general.</p><h4>Collect App Artefacts by Default</h4><p>CI + CD also <strong>automates</strong> the collection and <strong>storage of</strong> <strong>app artefacts</strong>, including IPAs, dSyms or logs. This can be convenient for debugging crash reports in production, running the app for a particular version or re-distributing failed deployments. The alternative of manually distributing or debugging apps can be time-consuming because we may not check artefacts into source control at the same time. CI + CD <strong>prevents</strong> this <strong>human error</strong> and makes <strong>artefacts more widely available</strong> (improved transparency).</p><h3>Configuration 📝</h3><p>CI and CD tooling need to be configured on a per-project basis. I’ve outlined the advantages of having a configurable CI and CD environment below.</p><h4>Configuration as code</h4><p>CI + CD can be <strong>configured as code</strong> for most tools. Committing configuration as code means we have a <strong>single source of truth</strong> for the configuration that is backed up to the cloud. This ensures stability and scalability. <strong>We prevent unexpected changes</strong> to the workflow without notifying the team more widely by restricting edit access to team leads. Version Control enables us to <strong>track changes</strong> in configuration and to <strong>roll back or diagnose breaking changes</strong>.</p><p>Furthermore, we can scale a performant, stable workflow between projects by sharing the <strong>self-documenting config</strong>. Configuration as code <strong>speeds up onboarding </strong>because developers don’t need to ask for documentation to understand a workflow if they understand the configuration files.</p><h4>Customisable Notifications</h4><p><strong>Notifications</strong> can be comprehensively <strong>configured for the project needs</strong>. We can notify the team for every build, only build successes, only build failures, and similarly for tests. This makes CI and CD very helpful in multiple scenarios. Notifying only on build failures helps teams who build regularly and want to <strong>prevent spamming communication channels</strong>. Notifying every build status <strong>raises more awareness of project health</strong>. Notifications raise awareness of the project state <strong>even with non-technical team members</strong> and <strong>help to diagnose errors faster</strong>.</p><h4>Optimisation of workflows</h4><p>Documenting previous CI + CD workflows means that we can also <strong>compare the performance and stability of different setups</strong>. CI + CD build times for a workflow can vary depending on numerous settings, such as clean builds, target platforms and deployment methods.</p><p>The best workflow for a given project varies depending on numerous factors such as project size, impending deadlines, code coverage and dependency stacks. As such, configuration as code helps us find the optimal workflow that balances velocity, stability and maintenance.</p><h4>Reduce team friction</h4><p>Configuration as code <strong>reduces friction</strong> as the team grows. We can restrict access for editing workflows to team leads only, and coordinate workflows easily even as the team grows.</p><h4>Cross-Platform Configuration</h4><p>CI and CD are powerful, flexible tools that can <em>usually</em> be configured <strong>across multiple development ecosystems</strong>. GitHub Actions is a popular solution these days that can automate workflows on iOS, Android, Web and Desktop projects with one subscription. Not every CI and CD tool is cross-platform, but <strong>we can choose a solution that provides good value for money.</strong></p><h3>Metrics 📊</h3><blockquote>“What gets measured, gets done.” — Peter Drucker</blockquote><h4>Increase Visibility of Issues</h4><p>CI + CD can be used to increase the visibility of key project metrics such as code coverage. Tracking project metrics <strong>increases the visibility of potential issues</strong> before they become unmanageable e.g. code coverage. Tracking project metrics helps make a more compelling case to stakeholders for refactoring or improving code coverage.</p><h4>Clear Overview of <strong>System under Test (</strong>SuT)</h4><p>CI saves time during feature development, that can be used to pay attention to <strong>wider project issues</strong>. Metrics like <strong>app launch times</strong>, the hang rate, memory usage, energy use, scrolling performance and networking load can be tracked through automated UI performance tests. We can quickly identify regressions, and improve them with a <strong>clearer overview of the whole System under Test (SuT)</strong>. It’s very hard for bugs to hide with comprehensive metrics.</p><h4>Track and Quantify Process Improvement Impacts</h4><p>Even though the initial costs of setting up CI + CD can be quite high, CI + CD saves more time for developers in the long run. We can <strong>track the amount of time saved</strong> with CI + CD over a project’s lifetime. A 10% improvement in build time, results in +99% time savings over 100 builds. Tracking time savings is easy with CI, and leverages the power of compounding. No wonder Joel says buy the best tools money can buy 😅.</p><h4>Correlate CI Metrics with wider Team Metrics</h4><p>We can even <strong>correlate CI metrics</strong> with other metrics like <strong>Agile team velocity</strong>. PMs can visualise key datasets to make faster, and <strong>better project decisions</strong>. A faster decision-making process helps to manage project complexity. For example, we can know when would be the best time to start spikes, respond quickly to changes of App Store guidelines and schedule backlog tasks by priority.</p><h4>Track Technical Debt through Code Coverage</h4><p>We can <strong>track changes to code coverage</strong> with third-party integrations. Code coverage reports can be reviewed to highlight files that need to be tested. <strong>CI helps us to refactor </strong>because we need to ensure the codebase is covered by <strong>tests before refactoring technical debt</strong>. As the project develops, we can also <strong>compare this to crash rate metrics</strong> to quantify the effect of better testing processes.</p><h3>Can CI + CD ever be a problem? ❌</h3><p>CI and CD are powerful tools, however, don’t use a hammer to crack an egg. Consider carefully how best to implement CI and CD on your project, and consider it as a long-term investment.</p><h4>Long-Term Projects Only</h4><p>CI + CD is only worth the effort setting up if the project is going to be distributed and maintained long-term. The effort to set CI up won’t be paid back over time for prototype apps. CI and CD are tempting tools to use because of their convenience, but we need to <strong>use the right tool for the job</strong>.</p><h4>Essential Processes Only</h4><p><strong>Automate only the essential processes</strong> like testing, static analysis, and deployment. Automating everything under the sun is a recipe for hopelessly <strong>long build times</strong>. If builds are taking too long, CI is no longer convenient or helpful. You may need to add codebase security scanning for the client but <strong>streamline your workflow</strong> as much as possible. Furthermore, a configuration with <strong>CI but no CD</strong> makes more sense for some projects.</p><h4>Do Not Over-Optimise</h4><p>While it’s super gratifying to view a dashboard of project metrics, it’s important to only track the <strong>key project metrics. Don’t try to over-optimise</strong> everything under the sun. Balancing resource allocation with the frequency of CI jobs offers only marginal cost-saving compared to the amount of effort. There’s a <strong>sweet spot between configuration effort and business value</strong> that we need to get right on a per-project balance. Otherwise, CI no longer provides value for the business cost.</p><p>I believe <strong>deciding what metrics</strong> to track should be a <strong>group decision</strong> based on business <em>and </em>developer feedback. SonarQube code quality metrics are another example that may be important to developers but do not make sense to product. In these cases, it’s important for the team to <strong>communicate openly</strong> and reach an agreement. Ps. <a href="https://blog.codinghorror.com/paying-down-your-technical-debt/"><strong>managing technical debt makes business sense too</strong></a>.</p><h4>Track Effort Required for Maintenance</h4><p>CI requires continuous maintenance to be effective. The cost of maintenance can be tracked over a project (e.g. the number of JIRA bugs tagged to CI configuration). CI makes metrics very clear, so we can quickly identify when tooling is <strong>not worth the maintenance</strong> <strong>effort</strong>. Maintenance effort should be much less than the setup effort, usually to respond to new announcements or APIs for less than an hour a week.</p><h4>Choose The Right Hosting</h4><p><strong>Self-hosted CI requires more maintenance</strong> than hosted CI, however is more cost-efficient. On the other hand, hosted CI solutions are convenient but more expensive. Companies can choose the solution that works best for their project because there’s a trade-off between these two solutions.</p><p><strong>In some cases, businesses won’t approve of either CI option. Hosted CI may not make financial sense</strong> for some teams, and we can’t set up <strong>Self-Hosted CI</strong> with lots of <strong>urgent deadlines</strong>.</p><p>It’s up to the development team to advocate CI makes good business sense, but management still may not agree. CI can be prioritised when the team has the capacity, but <strong>business needs</strong> often <strong>override development needs</strong>. As a developer, you can advocate for CI but often the initiative needs the buy-in from senior members.</p><h3>Final Thoughts 📚</h3><p>I hope you learnt a lot about the DevOps ecosystem for mobile apps, the benefits of CI and CD workflows and how best to implement it on your projects. CI + CD improves convenience with automation, adapts projects to change with a flexible configuration and improves transparency with metrics.</p><p>I am a big fan of automation, in fact, one of my mantras is:</p><blockquote>“If it can be automated, automate it.” — Me</blockquote><p>The best developer teams I have worked on have all had CI + CD configurations scaled for the production project size. I have never implemented CI and CD for a prototype or smaller project, unless for learning. CI + CD makes sense for production apps, especially if there’s a large backlog or development pipeline. Just bear in mind that implementing CI and CD is a long-term investment, and takes time to realise the benefits listed here.</p><figure><img alt="Graph showing the cumulative cost savings of automation over time." src="https://cdn-images-1.medium.com/max/1024/1*7lunDC8BoA7XkbP8tJVJJQ.png" /><figcaption>Fig 3: How CI and CD worked for me in practice</figcaption></figure><p>NOTE: xkcd 1319 exaggerates the pains of setup in my opinion because automation has only taken a maximum of 2 weeks in my experience. Keep an eye on setup time though! Implementing a particular CI and CD tool may no longer make sense if the setup takes too long. Self-hosted setups are generally more work to set up, however, newer hosted CI tools like Xcode Cloud may not be stable in beta or early versions. In my experience, it’s <em>unlikely</em> to take longer than 2 weeks to get a basic workflow working.</p><p>Thanks for reading! If you enjoyed this article and want to hear more from me, please follow me on <a href="https://twitter.com/spidey_vitamins">Twitter</a>. Happy coding! 👨‍💻</p><p><em>Special thanks to </em><a href="https://medium.com/@felipericieri"><em>Felipe Ricieri</em></a><em>, </em><a href="https://medium.com/@roger.tan"><em>Roger Tan</em></a><em> and </em><a href="https://medium.com/@sdods"><em>Sam Dods</em></a><em> for providing feedback.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a859f595793b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kinandcartacreated/the-missing-handbook-for-continuous-integration-continuous-deployment-start-here-a859f595793b">The missing handbook for Continuous Integration &amp; Continuous Deployment (start here)</a> was originally published in <a href="https://medium.com/kinandcartacreated">Kin + Carta Created</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>