8000 GitHub - ivasik-k7/Fastlane-Bitrise: This repository provides a comprehensive guide and example configurations for setting up CI/CD using Fastlane and Bitrise. Learn how to automate the build, test, and release process for your mobile applications with ease.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

This repository provides a comprehensive guide and example configurations for setting up CI/CD using Fastlane and Bitrise. Learn how to automate the build, test, and release process for your mobile applications with ease.

Notifications You must be signed in to change notification settings

ivasik-k7/Fastlane-Bitrise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Fastlane with Bitrise CI/CD

SaveLife in Ukraine
Fastlane version 2.220.0 Ruby version 3.3.0 Bitrise version 2.11.0

Introduction

Welcome to the Fastlane with Bitrise CI/CD guide! I'm Ivan Kovtun, a Senior Healthcare Mobile Software Engineer at Capgemini Engineering, with a passion for automating mobile app development workflows.

With over 6 years of experience in the software industry, I specialize in building healthcare mobile applications for both iOS and Android platforms. Throughout my career, I've been dedicated to leveraging automation tools like Fastlane and CI/CD platforms like Bitrise to streamline development processes, increase efficiency, and deliver top-notch software solutions.

As an advocate for best practices in software development, I'm excited to share my knowledge and insights in this guide. Join me as we explore the powerful capabilities of Fastlane and Bitrise, and learn how to optimize your mobile app development workflow for success.

Feel free to connect with me on GitHub and LinkedIn to stay updated on my latest projects and professional endeavors.

Let's dive into the world of automated mobile app development together!

Table of Contents

Overview

What is Fastlane?

Fastlane is an open-source automation toolset primarily used for simplifying and streamlining the development, testing, and deployment workflows of mobile applications. Developed initially by Felix Krause in 2014, Fastlane has become a widely adopted tool in the mobile app development community, offering a comprehensive suite of functionalities to developers working on iOS and Android platforms.

Benefits of Using Fastlane

  • Time-saving: Fastlane automates repetitive tasks, saving developers time and effort.

  • Error Reduction: By automating processes, Fastlane reduces the risk of human error in tasks like building, testing, and deployment.

  • Streamlined Workflow: Fastlane provides a unified interface for managing the development lifecycle of mobile apps, streamlining the workflow for developers.

  • Consistency: Fastlane ensures consistency in the build, testing, and deployment processes across different projects and environments.

Use Cases

  • Continuous Integration/Continuous Deployment (CI/CD): Fastlane is widely used in CI/CD pipelines to automate the build and deployment processes.

  • Release Management: Fastlane simplifies the release management process by automating tasks like code signing, versioning, and app distribution.

  • Testing Automation: Fastlane facilitates automated testing by integrating with testing frameworks and services, enabling comprehensive testing of mobile apps.

Glossary

  1. Code Signing: The process of digitally signing executables to confirm the software's integrity and authenticity.

  2. Provisioning Profile: A file used for iOS app distribution, containing information about the app's identity and authorized devices.

  3. Configuration Management: Managing settings for different environments (e.g., development, production) to ensure consistency.

  4. Environment Variables: Variables storing sensitive information or configuration settings accessible to software applications.

  5. CI/CD Pipeline: A series of automated steps that code changes go through from development to production deployment.

  6. Release Management: Managing the release of software applications, including versioning, code signing, and app distribution.

  7. Version Control System (VCS): A system tracking changes to files and directories over time, facilitating collaboration among developers.

Understanding Fastlane Basics

Installing Fastlane

Bundler (Recommended)

  1. Install Bundler: Begin by installing Bundler.

    #!/bin/bash
    
    gem install bundler
  2. Create Gemfile: In the root directory of your project, create a file named Gemfile. Add the following content to it:

    #!/bin/bash
    
    touch Gemfile
    source "https://rubygems.org"
    
    gem "fastlane"
  3. Install Dependencies: To install Fastlane and any other dependencies specified in your Gemfile, run the following command:

    #!/bin/bash
    
    bundle install

    Make sure to add both the Gemfile and Gemfile.lock to your version control system.

  4. Validate Fastlane: You can validate the Fastlane version by running the following bash script.

    #!/bin/bash
    
    bundle exec fastlane -v

Homebrew (macOS)

  1. Install Homebrew: If you haven't already installed Homebrew, you can do so by running the following command in your terminal:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Verify Homebrew: To verify if Homebrew is installed on your local machine, you can run the following command:

    #!/bin/bash
    
    brew --version

    If Homebrew is installed, this command will display the version of Homebrew that is installed on your system. If Homebrew is not installed, you'll receive an error message indicating that the command was not found.

  3. Install Fastlane: Once Homebrew is installed, you can install Fastlane by running:

    #!/bin/bash
    
    brew install fastlane
  4. Verifying Installation

    Regardless of the installation method you choose, you can verify that Fastlane is installed correctly by running:

    fastlane --version

Setup the project

Initializing Fastlane in your project is the first step to setting up Fastlane for automating your build, test, and deployment processes. The initialization process creates necessary configuration files and sets up the basic structure for your Fastlane project.

Steps to Initialize Fastlane

  1. Navigate to Your Project Directory: Open your terminal or command prompt and navigate to the root directory of your project where you want to set up Fastlane.

  2. Run Initialization Command: Use the following command to initialize Fastlane:

    fastlane init
  3. Follow the Prompts: Fastlane will guide you through a series of prompts to configure your project. These prompts include:

Configuring Fastlane with Bitrise

Integrating Fastlane into Bitrise Workflows

# bitrise.yml

workflow_name:
  description: "Workflow in which you have included fastlane"
  envs:
    - ANDROID_LANE_NAME: "lane_name_from_fastlane_file"
    - FASTLANE_ANDROID_DIR: android/fastlane
    - SECURE_ENV_VARIABLE_X: "NOT REALLY SECURE VARIABLE"
    - SECURE_ENV_VARIABLE_Y: $SECURE_VARIABLE_FROM_VAULT
  steps:
    # Steps ...
    - fastlane@3:
        inputs:
          - lane: $ANDROID_LANE_NAME
          - work_dir: $FASTLANE_ANDROID_DIR
    # Steps ...

Integrating Fastlane into your Bitrise workflows allows you to automate various tasks such as building, testing, and deploying your iOS and Android projects. Here's how you can integrate Fastlane into Bitrise:

  1. Create a Bitrise Workflow:

    • Log in to your Bitrise account and navigate to your project.
    • Create a new workflow or select an existing one where you want to integrate Fastlane.
  2. Add a Fastlane Step:

    • In your Bitrise workflow, add a new step for running Fastlane. You can find the Fastlane step in the workflow editor's step library.
    • Configure the Fastlane step by specifying the lane you want to execute and any additional options or parameters.
  3. Specify Fastlane Lane:

    • Define the Fastlane lane you want to execute in your Bitrise workflow. This can be a lane for building, testing, deploying, or any custom task you've defined in your Fastfile.
  4. Run Fastlane in Bitrise:

    • Save your Bitrise workflow configuration and trigger a build. Bitrise will execute the Fastlane step as part of the workflow, running the specified Fastlane lane.

Setting Up Fastfile for iOS and Android Projects

The Fastfile is where you define your Fastlane lanes, which are sequences of actions for automating tasks in your iOS and Android projects. Here's how you can set up your Fastfile:

  1. Define Lanes:

    default_platform(:ios)
    
    platform :ios do
        # Lanes ..
        # Actions ...
        # Methods ...
    end

    Depending on which platform you are implementing your Fastlane project, the structure will be slightly different.

    # Define a lane named "build"
    lane :build do
        # Add actions here to build your iOS app
    end
    • Open your Fastfile in a text editor.
    • Define lanes for common tasks such as building, testing, and deploying your iOS and Android projects.
  2. Customize Actions:

    # Define a lane named "build"
    lane :build do
        # Customizing the gym action to specify the workspace and scheme
        gym(
            workspace: "YourApp.xcworkspace",
            scheme: "YourApp"
        )
    end
    • Customize the actions within each lane to suit your project's requirements. Fastlane provides a wide range of built-in actions for common tasks such as code signing, running tests, and uploading builds to app stores.
  3. Parameterize Lanes:

    # Define a lane named "build"
    lane :build do |options|
         # Retrieve parameters from the options hash
         target = options[:target]
         version = options[:version]
    
         UI.message("Build app with version #{version}...")
         UI.message("Build app for target #{target}...")
    
        # Customizing the gym action to specify the workspace and scheme
         gym(
            workspace: "YourApp.xcworkspace",
            scheme: "YourApp"
         )
    end
    • Parameterize your lanes to make them more flexible and reusable. You can define parameters for things like app version, build configuration, and deployment targets.
  4. Use Environment Variables:

    # Define a lane named "build"
    lane :build do |options|
         # Retrieve parameters from the options hash
         target = options[:target]
         version = options[:version]
    
         SECURE_ENV_VARIABLE_X = ENV["SECURE_ENV_VARIABLE_X"]
         SECURE_ENV_VARIABLE_Y = ENV["SECURE_ENV_VARIABLE_Y"]
    
         UI.message("Build app with version #{version}...")
         UI.message("Build app for target #{target}...")
    
        # Customizing the gym action to specify the workspace and scheme
         gym(
            workspace: "YourApp.xcworkspace",
            scheme: "YourApp"
         )
    end
    • Use environment variables to manage sensitive information such as API keys, app store credentials, and other secrets. This ensures that sensitive data is not hard-coded in your Fastfile.

Managing Credentials and Secrets in Fastlane

Fastlane provides built-in tools for managing credentials and secrets securely. Here's how you can manage credentials and secrets in Fastlane:

  1. Use Fastlane's Credentials Manager:

    fastlane fastlane-credentials add --variable variable_value
    fastlane fastlane-credentials remove --variable variable_value

    Fastlane's Credentials Manager allows you to securely store and retrieve sensitive information such as API keys, app store credentials, and signing certificates.

    lane :lane_name do
        app_store_username = credentials(:app_store_username)
    
        # Content...
    end

    Use the credentials action in your Fastfile to load credentials from the Credentials Manager at runtime.

  2. Store Secrets in Environment Variables:

    • Store sensitive information in environment variables and load them into your Fastlane lanes at runtime. This allows you to keep secrets out of your Fastfile and other configuration files.

Automating Build and Deployment Processes

Automating various tasks in your development workflow can greatly improve efficiency and reliability. Fastlane is a powerful tool that allows you to automate common tasks such as building, testing, code signing, and deployment for your mobile apps. In this guide, we'll cover two key aspects of automating your build and deployment processes with Fastlane: automating app builds and code signing/distribution.

Automating App Builds with Fastlane

Automating the build process ensures that your app is consistently built with the correct configurations, dependencies, and settings. Fastlane provides tools to automate the entire build process for both iOS and Android apps. Here's how you can automate app builds with Fastlane:

  1. Define Build Configuration: Set up a Fastfile in your project directory to define lanes for different build configurations (e.g., development, staging, production). Specify tasks such as fetching dependencies, compiling code, and generating build artifacts.

    #android/fastlane/Fastlane
    
    lane :build do
     FLAVOR = "Develop"
     gradle(
            task:"assemble",
            build_type: "Release",
            flavor: FLAVOR,
     )
    end
    #ios/fastlane/Fastlane
    
    lane :build do |options|
    # You could pass that value as you may like using ENV or Credentials manager
    
     APPLICATION_IDENTIFIER = "com.company.example"
     APPLICATION_NAME = "ApplicationName"
    
     CODE_SIGNING_IDENTITY = "Apple Distribution"
     DISTRIBUTION_METHOD = "app-store"
     OUTPUTS_DIRECTORY = "outputs"
    
     SCHEME = "#{options[:scheme]}"
    
     PROFILE_NAME = ENV["Profile name"]
     TEAM_ID = ENV["TEAM_ID"]
    
     ipa_path = gym(
         scheme: SCHEME,
         output_directory: OUTPUTS_DIRECTORY,
         output_name: APPLICATION_NAME,
         silent: false,
         clean: false,
         export_options: {
             method: DISTRIBUTION_METHOD,
             export_team_id: TEAM_ID,
             signingStyle: CODE_SIGNING_IDENTITY,
             provisioningProfiles: {
                 APPLICATION_IDENTIFIER => PROFILE_NAME,
             }
         }
     )
    end
  2. Use Fastlane Actions: Fastlane provides a wide range of actions for building iOS and Android apps. Actions like gradle for Android and gym for iOS allow you to build your apps with just a few lines of code in your Fastfile.

  3. Integrate with CI/CD: Integrate Fastlane into your Continuous Integration/Continuous Deployment (CI/CD) pipeline to automate builds triggered by code changes or scheduled events. Services like Bitrise, Jenkins, and GitHub Actions support Fastlane integration out of the box.

    # bitrise.yml
    
    workflow_name:
    description: "Workflow in which you have included fastlane"
    envs:
      # Envs..
      - ANDROID_LANE_NAME: "build scheme:dev --verbose"
      # Envs..
    steps:
      # Steps ...
      - fastlane@3:
          inputs:
            - lane: $ANDROID_LANE_NAME
            # Other inputs ...
      # Steps ...

Code Signing and Distribution with Fastlane

Code signing and distribution are crucial steps in the app deployment process, especially for iOS apps. Fastlane simplifies code signing and distribution tasks by providing easy-to-use actions and tools. Here's how you can automate code signing and distribution with Fastlane:

  1. Manage Certificates and Provisioning Profiles: Use Fastlane's update_code_signing_settings action to manage code signing certificates and provisioning profiles automatically.

    lane :sign do
     CODE_SIGN_IDENTITY = "Apple Distribution"
     PROFILE_NAME = ENV["PROFILE_NAME"]
    
     update_code_signing_settings(
       use_automatic_signing: false,
       targets: ["Runner"],
       code_sign_identity: CODE_SIGN_IDENTITY,
       profile_name: PROFILE_NAME
     )
    end
  2. Automate App Distribution: Fastlane's deliver action allows you to automate the distribution of your iOS and Android apps to app stores and other distribution channels.

    lane :deploy do
      gradle(task: "assembleRelease")
      supply
    end
  3. Securely Store Credentials: Fastlane's Credentials Manager securely stores sensitive information such as app store credentials, API keys, and passwords.

  4. Streamline Beta Testing: Fastlane's screengrab and pilot actions streamline beta testing by automating the process of capturing screenshots, distributing builds to testers, and collecting feedback.

   lane :deploy do
    begin
      api_key = app_store_connect_api_key(
        key_id: ENV['IOS_KEY_ID'],
        issuer_id: ENV['ISSUER_ID_KEY'],
        key_content: ENV['KEY_CONTENT'],
        in_house: false
      )

      pilot(
        api_key: api_key,
        beta_app_description: "This is the #{SCHEME} build",
        skip_submission: true,
        skip_waiting_for_build_processing: false,
        team_id: ENV["TEAM_ID"],
      )
    rescue => exception
      UI.error "An Error while uploading #{ipa_path} to Testflight!"
      UI.abort_with_message!("Uploading exception: #{exception}")
    end
   end

By automating app builds and code signing/distribution processes with Fastlane, you can save time, reduce errors, and improve the overall efficiency of your development workflow. Fastlane's powerful automation capabilities make it an essential tool for mobile app developers looking to streamline their build and deployment processes.

Best Practices and Tips

Best Practices for Using Fastlane with Bitrise

Integrating Fastlane with Bitrise can streamline your build and deployment processes, but it's essential to follow best practices to ensure smooth automation. Here are some best practices for using Fastlane with Bitrise:

  1. Version Control Configuration: Store your Fastfile and related configuration files in your version control system (e.g., Git). This ensures consistency across team members and allows for easy tracking of changes.

    # Example Fastfile
    lane :build_ios do
      # Define iOS build lane
      ...
    end
  2. Modularization: Break down your Fastfile into modular components by defining separate lanes for different tasks (e.g., building, testing, deployment). This improves maintainability and makes it easier to debug issues.

    lane :build_ios do
      # Define iOS build lane
      ...
    end
    
    lane :test_ios do
      # Define iOS test lane
      ...
    end
    
    lane :deploy_to_app_store do
      # Define App Store deployment lane
      ...
    end
  3. Environment Variables: Use environment variables to customize Fastlane behavior based on your Bitrise workflow or specific conditions. This allows for greater flexibility and reusability of your Fastlane configuration.

    lane :deploy_to_app_store do
      # Retrieve environment-specific values
      APP_VERSION = ENV["BITRISE_GIT_TAG"]
    
      # Use environment variables in actions
      deliver(
        app_version: APP_VERSION,
        ...
      )
    end

Case Studies and Examples

Real-world Use Cases of Fastlane with Bitrise

Fastlane combined with Bitrise has been instrumental in streamlining the development and deployment processes for numerous mobile app projects. Here are some real-world use cases highlighting the benefits of using Fastlane with Bitrise:

  1. Continuous Integration and Deployment: Many development teams use Bitrise to set up CI/CD pipelines that automatically trigger builds, run tests, and deploy app updates whenever new code is pushed to the repository. Fastlane orchestrates the build and deployment process, ensuring consistency and reliability across different environments.

  2. Automated Code Signing: Fastlane simplifies the management of code signing certificates and provisioning profiles, especially for iOS apps. By integrating Fastlane's match or update_code_signing_settings action into Bitrise workflows, teams can automate the code signing process, reducing the risk of human error and ensuring that the correct signing identities are used for each build.

  3. Beta Testing and Feedback Collection: Fastlane's screengrab and pilot actions facilitate beta testing by automating the process of capturing screenshots, distributing builds to testers, and collecting feedback. Bitrise workflows can be configured to trigger these actions automatically, enabling seamless beta testing and user feedback collection.

Example Workflows and Configurations

default_platform(:ios)

platform :ios do

  before_all do |_lane, options|
    @launch_options = options
    begin
      update_fastlane
    rescue => exception
      UI.error "Update fastlane issue: #{exception}"
    end
  end

  desc "Example lane"
  lane :distribute do |options|
    APPLICATION_IDENTIFIER = "com.company.example"
    APPLICATION_NAME = "ApplicationName"

    CODE_SIGNING_IDENTITY = "Apple Distribution"
    DISTRIBUTION_METHOD = "app-store"
    OUTPUTS_DIRECTORY = "outputs"

    SCHEME = "#{options[:scheme]}"

    PROFILE_NAME = ENV["Profile name"]
    TEAM_ID = ENV["TEAM_ID"]

    CONFIG = "Release-#{SCHEME}"
    application_name = "Application_#{scheme}.ipa"

    clear_outputs

    update_code_signing_settings(
      use_automatic_signing: false,
      targets: ["Runner"],
      code_sign_identity: CODE_SIGNING_IDENTITY,
      profile_name: PROFILE_NAME
    )



    app_version = get_version_number(
      xcodeproj: XC_PROJ # Replace with the actual path to your Xcode project
    )

    api_key = app_store_connect_api_key(
      key_id: ENV['IOS_KEY_ID'],
      issuer_id: ENV['ISSUER_ID_KEY'],
      key_content: ENV['KEY_CONTENT'],
      in_house: false
    )

    puts "App Version: #{app_version}"

    latest_build_number = latest_testflight_build_number(
      version: app_version,
      app_identifier: APPLICATION_IDENTIFIER,
      initial_build_number: 0,
      api_key: api_key,
    )

    puts "NUMBER: #{latest_build_number}"

    increment_build_number(
      build_number: latest_build_number + 1
    )

    ipa_path = gym(
        scheme: SCHEME,
        output_directory: OUTPUTS_DIRECTORY,
        output_name: APPLICATION_NAME,
        silent: false,
        clean: false,
        export_options: {
            method: DISTRIBUTION_METHOD,
            export_team_id: TEAM_ID,
            signingStyle: CODE_SIGNING_IDENTITY,
            provisioningProfiles: {
                APPLICATION_IDENTIFIER => PROFILE_NAME,
            }
        }
    )

    UI.command_output("IPA path #{ipa_path}")

    UI.message "The app has been built"


    begin
      pilot(
        api_key: api_key,
        beta_app_description: "This is the #{SCHEME} build",
        skip_submission: true,
        skip_waiting_for_build_processing: false,
        team_id: TEAM_ID,
      )
    rescue => exception
      UI.error "An Error while uploading #{ipa_path} to Testflight via altool!"
      UI.abort_with_message!("Uploading exception: #{exception}")
    end
  end

  def clear_outputs
    clear_derived_data

    execute_in_root do
      sh("rm -rf DerivedData")
      sh("rm -rf #{OUTPUTS_DIRECTORY}")
    end

    UI.command("The outputs has been cleared!")
  end

  def execute_in_root
    Dir.chdir("..") do
      yield
    end
  end
end

By leveraging Fastlane with Bitrise, mobile app development teams can achieve faster delivery cycles, improved quality, and greater efficiency throughout the development and deployment process.

Conclusion

Fastlane, when integrated with Bitrise, offers a robust solution for automating various aspects of mobile app development, testing, and deployment. By leveraging Fastlane's automation capabilities and Bitrise's CI/CD platform, development teams can streamline their workflows, save time, and improve overall efficiency.

Recap of Key Points

  • Fastlane Simplifies Mobile Development: Fastlane provides a comprehensive suite of tools and actions for automating common tasks in mobile app development, including building, testing, code signing, and deployment.

  • Bitrise Enables Continuous Integration and Deployment: Bitrise is a powerful CI/CD platform that allows teams to automate build, test, and deployment processes for iOS and Android apps.

  • Integration Benefits: Integrating Fastlane with Bitrise offers several benefits, including time savings, error reduction, streamlined workflows, and consistent build and deployment processes.

  • Best Practices and Tips: Following best practices such as version controlling configuration files, modularizing Fastlane setups, using environment variables, and leveraging Fastlane's built-in actions can help maximize the benefits of the integration.

Next Steps and Further Exploration

As you continue to explore the capabilities of Fastlane and Bitrise, consider the following next steps:

  1. Experiment with Advanced Features: Explore advanced features of Fastlane such as custom actions, plugins, and integrations with other tools and services to further enhance your automation workflows.

  2. Optimize Workflows: Continuously optimize your Fastlane and Bitrise workflows based on feedback, changing requirements, and emerging best practices in mobile app development.

  3. Stay Updated: Stay informed about updates and new features released for Fastlane and Bitrise to take advantage of the latest enhancements and improvements.

  4. Community Engagement: Engage with the Fastlane and Bitrise communities through forums, user groups, and social media channels to share experiences, learn from others, and contribute to the development ecosystem.

By embracing automation and leveraging the capabilities of Fastlane and Bitrise, you can accelerate the delivery of high-quality mobile apps while minimizing manual effort and reducing the risk of errors. Happy automating!

About

This repository provides a comprehensive guide and example configurations for setting up CI/CD using Fastlane and Bitrise. Learn how to automate the build, test, and release process for your mobile applications with ease.

Resources

Stars

Watchers

Forks

0