{"id":62793,"date":"2024-08-14T10:49:43","date_gmt":"2024-08-14T05:19:43","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=62793"},"modified":"2024-08-14T12:31:43","modified_gmt":"2024-08-14T07:01:43","slug":"ios-ci-cd-integration-using-gitlab-fastlane-firebase-part-1-page-1","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/ios-ci-cd-integration-using-gitlab-fastlane-firebase-part-1-page-1\/","title":{"rendered":"iOS: CI\/CD Integration via FastLane &amp; Firebase using Gitlab : Part \u2013 1"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Hello everyone, This is a blog series where we&#8217;ll touch up on how to automate our workflow with CI\/CD in iOS with the use of tech like Fastlane, Firebase, and Gitlab repository. <\/span><\/p>\n<p>This is the 1st part of the series where we&#8217;ll cover the setup of the configuration for generating automated builds using Fastlane on the local machine.<\/p>\n<h1>Introduction<\/h1>\n<p><span style=\"font-weight: 400;\">When we are working on a project and need to share the build for the testing features then there are common steps to generate a build and make an archive via Xcode to share with testers. But this is a repetition process to generate a build via Xcode and also need to manage &amp; keep upto-date the certificate and provision profile. Generally, this can be possible if a developer is available to generate the archive because they have the expertise in their domain. What will happen if a developer is not available to generate the archive then it is not possible without the help of a developer.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">After some research, I have discovered that there are some powerful tools available that can help us automate the build, test, and deployment of our app. So we can set up a GitLab repository for our app, and just install the Fastlane on our local machine and in the GitLab repository.<\/span><\/p>\n<h1><b>What is CI\/CD?<\/b><\/h1>\n<p><span style=\"font-weight: 400;\">A <\/span><a href=\"https:\/\/about.gitlab.com\/topics\/ci-cd\/cicd-pipeline\/\"><span style=\"font-weight: 400;\">CI\/CD pipeline<\/span><\/a><span style=\"font-weight: 400;\"> is an automated process utilized by software development teams to streamline the creation, testing, and deployment of applications. &#8220;CI&#8221; represents continuous integration, where developers frequently merge code changes into a central repository, allowing early detection of issues. &#8220;CD&#8221; refers to continuous deployment or continuous delivery, which automates the application&#8217;s release to its intended environment, ensuring that it is readily available to users. This pipeline is vital for teams aiming to improve software quality and speed up delivery through regular, reliable updates.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Integrating a CI\/CD pipeline into your workflow significantly reduces the risk of errors in the deployment process. Automating builds and tests ensures that bugs are caught early and fixed promptly, maintaining high-quality software.<\/span><\/p>\n<p><b>GitLab<\/b> <a href=\"https:\/\/about.gitlab.com\/stages-devops-lifecycle\/continuous-integration\/\"><span style=\"font-weight: 400;\">comes with CI built-in<\/span><\/a><span style=\"font-weight: 400;\"> for all projects, for free.<\/span><\/p>\n<p><a href=\"https:\/\/fastlane.tools\/\"><b>Fastlane<\/b><\/a><span style=\"font-weight: 400;\"> helps you to automate the most time-consuming beta distribution steps including incrementing the build version, code signing, building and uploading the app, and setting a change-log.<\/span><\/p>\n<h1><\/h1>\n<h1><b>What is Fastlane?<\/b><\/h1>\n<p><b>Fastlane <\/b><span style=\"font-weight: 400;\">is an open source suite of tools that allows you to automate your iOS or Android mobile app releases, potentially saving you hours of development time. It is powered by a Ruby configuration file called a <\/span><i><span style=\"font-weight: 400;\">Fastfile<\/span><\/i><span style=\"font-weight: 400;\">, in which you can add <\/span><i><span style=\"font-weight: 400;\">lanes<\/span><\/i><span style=\"font-weight: 400;\"> to serve different purposes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this tutorial, you\u2019ll see how to build a local fastlane pipeline that will automate the final steps of the iOS development and deployment process. You\u2019ll add lanes for signing, testing, building, and deploying a simple \u201cTodo_ios\u201d application. At the end of this tutorial, you should have everything you need to build the perfect fastlane pipeline for your next iOS app.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h1><b>Fastlane Setup\/Installation<\/b><\/h1>\n<p><span style=\"font-weight: 400;\">There are <\/span><a href=\"https:\/\/docs.fastlane.tools\/getting-started\/ios\/setup\/\"><span style=\"font-weight: 400;\">many ways to install fastlane<\/span><\/a><span style=\"font-weight: 400;\">, but we\u2019ll use Homebrew (macOS) for the task. There\u2019s also a <\/span><a href=\"https:\/\/docs.fastlane.tools\/getting-started\/ios\/fastlane-swift\/\"><span style=\"font-weight: 400;\">Swift version of fastlane<\/span><\/a><span style=\"font-weight: 400;\"> that\u2019s currently in beta.<\/span><\/p>\n<h2>Homebrew (macOS)<\/h2>\n<p>This way, you don&#8217;t have to install Ruby separately, and instead homebrew installs the adequate Ruby version for fastlane.<\/p>\n<pre><span style=\"font-weight: 400;\">\r\n<strong>$ brew install fastlane \r\n<\/strong><\/span>\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">When the installation is complete, confirm it by running the following command:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\r\n<strong>$ fastlane --version\r\n\r\n# Output:\r\nfastlane installation at path:\r\n\/usr\/local\/.rvm\/gems\/ruby-3.3.1\/gems\/fastlane-2.221.1\/bin\/fastlane\r\n-----------------------------\r\n[\u2714] \ud83d\ude80\r\nfastlane 2.221.1\r\n<\/strong><\/span>\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">Congratulations! You&#8217;re ready to use fastlane in your project.<\/span><\/p>\n<h1><strong>Configuring Fastlane for a project<\/strong><\/h1>\n<p><span style=\"font-weight: 400;\">In this tutorial, we\u2019ll use a demo app called <\/span><i><span style=\"font-weight: 400;\">Todo_ios<\/span><\/i><span style=\"font-weight: 400;\">. You can find the complete source code <\/span><a href=\"https:\/\/gitlab.com\/ios-tester\/Todo_ios\"><span style=\"font-weight: 400;\">here on Gitlab<\/span><\/a><span style=\"font-weight: 400;\"> in case you miss something. You will not required to have a paid <\/span><a href=\"https:\/\/developer.apple.com\/\"><span style=\"font-weight: 400;\">Apple Developer account<\/span><\/a><span style=\"font-weight: 400;\"> to complete this tutorial.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To get your new app started, open Xcode and create a new app.<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/07\/Screenshot-2024-07-21-at-3.03.01\u202fPM.png\" alt=\"null\" width=\"712\" height=\"507\" \/><\/p>\n<p><span style=\"font-weight: 400;\">To initialize fastlane inside the project, go to the project\u2019s root directory in your terminal and run the following:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\r\n<strong>$ fastlane init\r\n<\/strong><\/span>\r\n<\/pre>\n<p>Fastlane will prompt you to choose a single automated action to implement, Automated actions are pre-built actions that let you automate various aspects of your development and release workflow. You\u2019ll implement multiple automated actions in this tutorial, so just select manual setup by entering <strong>4 options<\/strong> for this tutorial.<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/07\/unnamed-1.png\" alt=\"null\" width=\"635\" height=\"212\" \/><\/p>\n<p>Go to the root directory of the project. We will see a new Gemfile, which includes project dependencies, and a <strong><em>.\/fastlane<\/em><\/strong> directory containing an Appfile and a Fastfile.<\/p>\n<p>After Completion Setup it your app directory looks like the below:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/07\/unnamed-2.png\" alt=\"null\" width=\"540\" height=\"121\" \/><\/p>\n<p><b>GEMFILE<\/b><\/p>\n<p><span style=\"font-weight: 400;\">If you don&#8217;t see GEMFile then create it manually by following the steps:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Create a <\/span><strong><em>.\/Gemfile<\/em><\/strong><span style=\"font-weight: 400;\"> in the root directory of your project with the content.<\/span><\/li>\n<\/ul>\n<p><a href=\"https:\/\/gitlab.com\/ios-tester\/Todo_ios\/-\/blob\/main\/Gemfile?ref_type=heads\"><img decoding=\"async\" loading=\"lazy\" class=\"alignright\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/08\/data-copy.png\" alt=\"null\" width=\"56\" height=\"56\" \/><\/a><\/p>\n<pre><span style=\"font-weight: 400;\">\r\n<strong> source <\/strong><span style=\"color: #ff0000;\">\"https:\/\/rubygems.org\"<\/span><strong>\r\n gem <\/strong><span style=\"color: #ff0000;\">\"fastlane\"\r\n<\/span><\/span>\r\n<\/pre>\n<p><a href=\"https:\/\/gitlab.com\/ios-tester\/Todo_ios\/-\/blob\/main\/fastlane\/Appfile?ref_type=heads\"><img decoding=\"async\" loading=\"lazy\" class=\"alignright\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/08\/data-copy.png\" alt=\"null\" width=\"56\" height=\"56\" \/><\/a><\/p>\n<ol>\n<li><b>Appfile<\/b><span style=\"font-weight: 400;\"> &#8211; It contains a bundle identifier and your Apple ID.<br \/>\n<\/span><\/li>\n<\/ol>\n<pre><span style=\"font-weight: 400;\">\r\n<strong> app_identifier(\"APP IDENTIFIER\") # The bundle identifier of your app\r\n apple_id(\"APPLE ID\") # Your Apple email address\r\n<\/strong><\/span>\r\n<\/pre>\n<p><b>2. <\/b><b>Gymfile<\/b> &#8211; It contains <em>gym<\/em> builds and packages for iOS apps. It will take care of all the heavy lifting and makes it super easy to generate a signed ipa or app file.<\/p>\n<p><span style=\"font-weight: 400;\">To create a gym file in your project, you\u2019ll need to run this command from your project directory in the command line.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\r\n<strong>$ fastlane gym init\r\n<\/strong><\/span>\r\n<\/pre>\n<p>Since you might want to automatically trigger a new build but don\u2019t want to specify all the parameters every time, so you can store your default values in a so-called <em><strong>Gymfile<\/strong><\/em>.<\/p>\n<p><span style=\"font-weight: 400;\">Example:<\/span><br \/>\n<a href=\"https:\/\/gitlab.com\/ios-tester\/Todo_ios\/-\/blob\/main\/fastlane\/Gymfile?ref_type=heads\"><img decoding=\"async\" loading=\"lazy\" class=\"alignright\" src=\"https:\/\/www.tothenew.com\/blog\/wp-ttn-blog\/uploads\/2024\/08\/data-copy.png\" alt=\"null\" width=\"56\" height=\"56\" \/><\/a><\/p>\n<pre class=\"oy oz pa pb pc pq ou pr ps ax pt bj\"><span id=\"bb6e\" class=\"pu nf gt ou b ii pv pw l px py\" data-selectable-paragraph=\"\"> scheme(\"SchemeName\")\r\n\r\n<\/span><span id=\"2601\" class=\"pu nf gt ou b ii pz pw l px py\" data-selectable-paragraph=\"\"> sdk(\"iphoneos15.2\")\r\n\r\n<\/span><span id=\"d854\" class=\"pu nf gt ou b ii pz pw l px py\" data-selectable-paragraph=\"\"> clean(true)\r\n\r\n<\/span><span id=\"5284\" class=\"pu nf gt ou b ii pz pw l px py\" data-selectable-paragraph=\"\"> output_directory(\".\/build\")    # store the ipa in this folder\r\n output_name(\"AppName\")           # the name of the ipa file<\/span><\/pre>\n<p><b>3. Fastfile<\/b><span style=\"font-weight: 400;\"> &#8211; It contains the fastlane.tools configuration and actions.<br \/>\n<\/span><\/p>\n<p>Fastfile defines the build steps, since we\u2019re using a lot of the built-in capability of fastlane this is really straightforward. We create a single lane that increments the build number, syncs certificates and builds, and uploads the new build to Firebase App Distribution or TestFlight\/App store. Of course, you may want to split these out into different jobs depending on your use case. Each of these steps, get_certificates, get_provisioning_profile, match, gym, and upload_to_testflight are pre-bundled actions already included with <em>fastlane<\/em>.<\/p>\n<p>Concluding we have covered the Fastlane setup\/Installation with multiple files like Appfile, Gymfile, and Fastfile in the Part 1. <a href=\"https:\/\/www.tothenew.com\/blog\/ios-ci-cd-integration-using-gitlab-fastlane-firebase-part-1-page-2\/\">In the next part of the series,<\/a> we&#8217;ll be covering how to use CI\/CD workflow via Fastlane &amp; Firebase on the local machine.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello everyone, This is a blog series where we&#8217;ll touch up on how to automate our workflow with CI\/CD in iOS with the use of tech like Fastlane, Firebase, and Gitlab repository. This is the 1st part of the series where we&#8217;ll cover the setup of the configuration for generating automated builds using Fastlane on [&hellip;]<\/p>\n","protected":false},"author":1898,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":220},"categories":[1400],"tags":[4252,6073,4848,4078],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/62793"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=62793"}],"version-history":[{"count":58,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/62793\/revisions"}],"predecessor-version":[{"id":64064,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/62793\/revisions\/64064"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=62793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=62793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=62793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}