Skip to content

Instantly share code, notes, and snippets.

@rockname
Created February 20, 2019 11:04
Show Gist options
  • Select an option

  • Save rockname/d30829947f9d00bee2b8be61ab70f6db to your computer and use it in GitHub Desktop.

Select an option

Save rockname/d30829947f9d00bee2b8be61ab70f6db to your computer and use it in GitHub Desktop.
CarthageのライブラリをアップデートしてPullRequestを作成するFastlaneのlane
lane :update_carthage_libraries do |options|
outdateds = ""
Dir.chdir ".." do
outdateds += sh("carthage", "outdated")
end
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]
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}.")
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"
sh("git", "push", "origin", BRANCH_NAME)
create_pull_request(
api_token: ENV["GITHUB_API_TOKEN"],
repo: "YOUR_REPOSITORY_NAME",
title: "[Auto generated] Update library #{lib}",
body: body
)
sh("git", "checkout", current_branch)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment