Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

rockname
February 21, 2019

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

rockname

February 21, 2019
Tweet

More Decks by rockname

Other Decks in Programming

Transcript

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

    ࣾ಺഑෍༻ (Enterprise) • staging • QA༻ • AppStore΁ͷΞοϓϩʔυ(fastlane/deliver)
  2. fastlaneͱ͸ʁ • ओʹiOS/AndroidΞϓϦͷϏϧυ, ςετ, σϓϩΠΛߦ͏ͨΊͷRuby੡λε Ϋϥϯφʔ • iOSͰ͸ • gym:

    ΞϓϦͷϏϧυ • deliver: AppStoreConnect΁ͷ
 Ξοϓϩʔυ • scan: ςετͷ࣮ߦ • …
  3. inhouse/staging/release • inhouse: • deploygate΁഑৴ • ࣾ಺഑෍༻ (Enterprise) • staging:

    • Deploygate΁഑৴ • QA༻ • release • AppStoreConnect΁Ξοϓϩʔυ
  4. 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
  5. 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ੜ੒
  6. 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΁഑৴
  7. 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
  8. 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ੜ੒
  9. 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΁Ξοϓϩʔυ
  10. 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Λ࡞੒
  11. ʲTipsʳGymfileʹfor_laneͰ
 lane͝ͱͷϏϧυύϥϝʔλΛ౉͢ for_lane :inhouse do ɾɾɾ end for_lane :staging do

    ɾɾɾ end for_lane :release do ɾɾɾ end ࢀߟIUUQTTQFBLFSEFDLDPNHJHJOFUYJBOHKJFGBTUpMF
  12. 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}"
  13. 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]
  14. 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}.”)
  15. 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"
  16. 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
  17. Workflow touch buildtime.txt xcodebuild \ -showBuildTimingSummary \ … \ clean

    build test | grep -E \ ’.* \| .*(seconds)$' >> buildtime.txt mv buildtime.txt $BITRISE_DEPLOY_DIR
  18. 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
  19. 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ʹࢦఆ