fastlaneとBitriseで構築するiOSのCI/CDレシピ / iOS CI/CD Recipe Constructed with fastlane and Bitrise

070d33664df274636dad3da21c9b21fc?s=47 rockname
February 21, 2019

fastlaneとBitriseで構築するiOSのCI/CDレシピ / iOS CI/CD Recipe Constructed with fastlane and Bitrise

070d33664df274636dad3da21c9b21fc?s=128

rockname

February 21, 2019
Tweet

Transcript

  1. 12.

    ݱঢ়ͷmacminiͰͷϏϧυ • Test • JenkinsͰPR΁ͷίϛοτΛϑοΫ • deploygate΁ͷ഑৴ • inhouse •

    ࣾ಺഑෍༻ (Enterprise) • staging • QA༻ • AppStore΁ͷΞοϓϩʔυ(fastlane/deliver)
  2. 15.

    fastlaneͱ͸ʁ • ओʹiOS/AndroidΞϓϦͷϏϧυ, ςετ, σϓϩΠΛߦ͏ͨΊͷRuby੡λε Ϋϥϯφʔ • iOSͰ͸ • gym:

    ΞϓϦͷϏϧυ • deliver: AppStoreConnect΁ͷ
 Ξοϓϩʔυ • scan: ςετͷ࣮ߦ • …
  3. 18.
  4. 19.
  5. 20.

    inhouse/staging/release • inhouse: • deploygate΁഑৴ • ࣾ಺഑෍༻ (Enterprise) • staging:

    • Deploygate΁഑৴ • QA༻ • release • AppStoreConnect΁Ξοϓϩʔυ
  6. 21.

    Fastfile: inhouse/staging lane :inhouse do |options| gym upload_to_deploygate(config: "Inhouse") end

    lane :staging do |options| gym upload_to_deploygate(config: "Staging") end
  7. 22.

    Fastfile: inhouse/staging lane :inhouse do |options| gym upload_to_deploygate(config: "Inhouse") end

    lane :staging do |options| gym upload_to_deploygate(config: "Staging") end gymͰipaੜ੒
  8. 23.

    Fastfile: inhouse/staging lane :inhouse do |options| gym upload_to_deploygate(config: "Inhouse") end

    lane :staging do |options| gym upload_to_deploygate(config: "Staging") end private_laneͰDeploygate΁഑৴
  9. 24.

    Fastfile: release lane :release do |options| gym deliver( ipa: “Mitene.ipa",

    submit_for_review: false, force: true ) upload_to_github_release( github_api_token: ENV["GITHUB_API_TOKEN"], tag_name: options[:tag_name] ) end
  10. 25.

    Fastfile: release lane :release do |options| gym deliver( ipa: “Mitene.ipa",

    submit_for_review: false, force: true ) upload_to_github_release( github_api_token: ENV["GITHUB_API_TOKEN"], tag_name: options[:tag_name] ) end gymͰipaੜ੒
  11. 26.

    Fastfile: release lane :release do |options| gym deliver( ipa: “Mitene.ipa",

    submit_for_review: false, force: true ) upload_to_github_release( github_api_token: ENV["GITHUB_API_TOKEN"], tag_name: options[:tag_name] ) end deliverͰAppStoreConnect΁Ξοϓϩʔυ
  12. 27.

    Fastfile: release lane :release do |options| gym deliver( ipa: “Mitene.ipa",

    submit_for_review: false, force: true ) upload_to_github_release( github_api_token: ENV["GITHUB_API_TOKEN"], tag_name: options[:tag_name] ) end private_laneͰGithub ReleaseΛ࡞੒
  13. 28.

    ʲTipsʳGymfileʹfor_laneͰ
 lane͝ͱͷϏϧυύϥϝʔλΛ౉͢ for_lane :inhouse do ɾɾɾ end for_lane :staging do

    ɾɾɾ end for_lane :release do ɾɾɾ end ࢀߟIUUQTTQFBLFSEFDLDPNHJHJOFUYJBOHKJFGBTUpMF
  14. 32.

    Build Trigger API • slack͔Βhubotܦ༝ͰϏϧυΛ࣮ߦ hook_info="\"hook_info\":{ \"type\":\"bitrise\", \"build_trigger_token\":\"${BUILD_TRIGGER_TOKEN}\" }" build_params="\"build_params\":{

    \"branch\":\"${branch}\", \"workflow_id\":\"${workflow}\" }" json="{${hook_info},${build_params},\"triggered_by\":\"curl\"}" curl https://app.bitrise.io/app/${APP_SLUG}/build/start.json —data "${json}"
  15. 33.
  16. 42.

    Fastfile • ݱࡏͷϒϥϯνΛୀආ͠ɺϥΠϒϥϦΛਖ਼نදݱͰ̍ߦͣͭநग़ current_branch = git_branch outdateds.each_line do |line| if

    outdated = line.match( /^(.+?) "(.+?)\.(.+?)\.(.+?)" -> “(.+?)\.(.+?)\.(.+?)"/ ) then lib = outdated[1] old_major = outdated[2] old_minor = outdated[3] old_patch = outdated[4] new_major = outdated[5] new_minor = outdated[6] new_patch = outdated[7]
  17. 43.

    Fastfile • όʔδϣϯ͕ҧ͏ͳΒ৽͍͠branchΛ੾ͬͯ carthage update if old_major == new_major &&

    (old_minor != new_minor || old_patch ! = new_patch) then ɹɹBRANCH_NAME = ɹɹɹ“update-library-#{lib}-"+Time.now.strftime("%Y%m%d%H%M") ɹɹsh("git", "checkout", "-b", BRANCH_NAME) ɹɹcarthage( ɹɹɹcommand: "update", ɹɹɹdependencies: [lib], ɹɹɹplatform: “ios" ɹɹ) ɹɹgit_add(path: ".") ɹɹgit_commit(path: ".", message: "Update Library #{lib}.”)
  18. 44.

    Fastfile • PRͷbodyΛੜ੒ version = line.match(/"(.*?)" -> "(.*?)"/) old_version =

    version[1] new_version = version[2] diff = sh("git", "diff", "--", "../Cartfile.resolved") repo = diff.match(/-github "(.+?)"/)[1] body = "## #{repo}\n” body += "#{old_version} -> [#{new_version}] (https://github.com/#{repo}/releases/tag/#{new_version})\n" body += “[compare](https://github.com/#{repo}/compare/ #{old_version}...#{new_version})\n"
  19. 45.

    Fastfile • PRΛ࡞੒͠ɺϒϥϯνΛmasterʹ໭ͯ࣍͠ͷfor_loop΁ ɹɹsh("git", "push", "origin", BRANCH_NAME) ɹɹcreate_pull_request( ɹɹɹɹapi_token: ENV["GITHUB_API_TOKEN"],

    ɹɹɹɹrepo: "maychannel-dev/iOS", ɹɹɹɹtitle: "[Auto generated] Update library #{lib}", ɹɹɹɹbody: body ɹɹ) ɹɹsh("git", "checkout", current_branch) end
  20. 47.
  21. 49.
  22. 51.
  23. 54.
  24. 55.

    Workflow touch buildtime.txt xcodebuild \ -showBuildTimingSummary \ … \ clean

    build test | grep -E \ ’.* \| .*(seconds)$' >> buildtime.txt mv buildtime.txt $BITRISE_DEPLOY_DIR
  25. 56.
  26. 61.

    Fastfile lane :coverage do |options| scan slather( proj: "Mitene.xcodeproj", workspace:

    "Mitene.xcworkspace", scheme: “Mitene", configuration: "Testing", html: true, output_directory: ENV["BITRISE_DEPLOY_DIR"], ignore: ["Carthage/Checkouts/*", "Pods/*"] ) end
  27. 62.

    Fastfile lane :coverage do |options| scan slather( proj: "Mitene.xcodeproj", workspace:

    "Mitene.xcworkspace", scheme: “Mitene", configuration: "Testing", html: true, output_directory: ENV["BITRISE_DEPLOY_DIR"], ignore: ["Carthage/Checkouts/*", "Pods/*"] ) end ґଘϥΠϒϥϦΛignoreʹࢦఆ
  28. 63.
  29. 66.