Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 8b99146

Browse files
committed
Add fastlane release script
1 parent 48a1674 commit 8b99146

File tree

3 files changed

+265
-0
lines changed

3 files changed

+265
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
.DS_Store
22
xcuserdata
33
*.xccheckout
4+
fastlane/README.md
5+
fastlane/report.xml
6+
fastlane/test_output
7+
fastlane/settoken.sh

fastlane/Fastfile

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
fastlane_version "1.86.0"
2+
3+
desc "Tags a new version of R.swift.Library and releases it to cocoapods"
4+
desc " * GITHUB_API_TOKEN must be available in environment, create one on https://github.com/settings/tokens"
5+
desc "This lane should be run from your local machine, and will push a tag to the remote when finished."
6+
desc " * Verifies the git branch is clean"
7+
desc " * Ensures the lane is running on the master branch"
8+
desc " * Pulls the remote to verify the latest the branch is up to date"
9+
desc " * Asks for the new version number"
10+
desc " * Commit, tag and release library to cocoapods"
11+
desc "####Options"
12+
desc " * **`allow_dirty_branch`**: Allows the git branch to be dirty before continuing. Defaults to false"
13+
lane :release do |options|
14+
ensure_git_branch(branch: "master")
15+
16+
if options[:allow_dirty_branch] != true
17+
ensure_git_status_clean
18+
else
19+
Helper.log.info "Skipping the 'git status clean' check!".yellow
20+
end
21+
22+
git_pull
23+
24+
runalltests
25+
26+
unless is_ci
27+
notification(
28+
title: "R.swift.Library release",
29+
message: "💡 Needs your attention."
30+
)
31+
end
32+
33+
currentVersion = version_get_podspec()
34+
Helper.log.info "Current R.swift.Library podspec version is #{currentVersion}"
35+
36+
bumpType = prompt(text: "What kind of release is this? (major/minor/patch/custom)".green, boolean: false, ci_input: "")
37+
isPrerelease = false
38+
case bumpType
39+
when "major", "minor", "patch"
40+
version_bump_podspec(bump_type: bumpType)
41+
when "custom"
42+
newVersion = prompt(text: "What is the new custom version number?".green, boolean: false, ci_input: "")
43+
version_bump_podspec(version_number: newVersion)
44+
45+
isPrerelease = prompt(text: "Is this a prerelease version?".green, boolean: true, ci_input: "")
46+
else
47+
raise "Invalid release type: #{bumpType}".red
48+
end
49+
50+
changelog = prompt(text: "Please provide release notes:".green, boolean: false, ci_input: "", multi_line_end_keyword: "FIN")
51+
52+
newVersion = version_get_podspec()
53+
unless prompt(text: "#{newVersion} has been prepped for release. If you have any additional changes you would like to make, please do those before continuing. Would you like to commit, tag, push and release #{newVersion} including all uncommitted changes?".green, boolean: true, ci_input:"y")
54+
raise "Aborted by user".red
55+
end
56+
57+
git_commit(
58+
path: ".",
59+
message: "Preparing for the #{newVersion} release"
60+
)
61+
62+
push_to_git_remote
63+
64+
af_create_github_release(
65+
owner: 'mac-cain13',
66+
repository: 'r.swift.library',
67+
tag_name: 'v#{newVersion}',
68+
target_commitish: 'master',
69+
name: '#{newVersion}',
70+
body: '#{changelog}',
71+
prerelease: isPrerelease
72+
)
73+
74+
pod_push
75+
76+
unless is_ci
77+
notification(
78+
title: "R.swift.Library release",
79+
message: "🎉 Version #{newVersion} is released."
80+
)
81+
end
82+
end
83+
84+
lane :runalltests do
85+
scan(
86+
project: "R.swift.Library.xcodeproj",
87+
scheme: "Rswift-iOS",
88+
clean: true
89+
)
90+
scan(
91+
project: "R.swift.Library.xcodeproj",
92+
scheme: "Rswift-tvOS",
93+
clean: true
94+
)
95+
end
96+
97+
error do |lane, exception|
98+
unless is_ci
99+
notification(
100+
title: "R.swift.Library #{lane}",
101+
message: "❌ Failed with an exception."
102+
)
103+
end
104+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# From: https://github.com/AFNetworking/fastlane/blob/master/fastlane/actions/af_create_github_release.rb
2+
module Fastlane
3+
module Actions
4+
module SharedValues
5+
GITHUB_RELEASE_ID = :GITHUB_RELEASE_ID
6+
GITHUB_RELEASE_HTML_URL = :GITHUB_RELEASE_HTML_URL
7+
GITHUB_RELEASE_UPLOAD_URL_TEMPLATE = :GITHUB_RELEASE_UPLOAD_URL_TEMPLATE
8+
end
9+
10+
# To share this integration with the other fastlane users:
11+
# - Fork https://github.com/KrauseFx/fastlane
12+
# - Clone the forked repository
13+
# - Move this integration into lib/fastlane/actions
14+
# - Commit, push and submit the pull request
15+
16+
class AfCreateGithubReleaseAction < Action
17+
def self.run(params)
18+
require 'net/http'
19+
require 'net/https'
20+
require 'json'
21+
require 'base64'
22+
23+
begin
24+
uri = URI("https://api.github.com/repos/#{params[:owner]}/#{params[:repository]}/releases")
25+
26+
# Create client
27+
http = Net::HTTP.new(uri.host, uri.port)
28+
http.use_ssl = true
29+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
30+
31+
dict = Hash.new
32+
dict["draft"] = params[:draft]
33+
dict["prerelease"] = params[:prerelease]
34+
dict["body"] = params[:body] if params[:body]
35+
dict["tag_name"] = params[:tag_name] if params[:tag_name]
36+
dict["name"] = params[:name] if params[:name]
37+
body = JSON.dump(dict)
38+
39+
# Create Request
40+
req = Net::HTTP::Post.new(uri)
41+
# Add headers
42+
req.add_field "Content-Type", "application/json"
43+
# Add headers
44+
api_token = params[:api_token]
45+
req.add_field "Authorization", "Basic #{Base64.strict_encode64(api_token)}"
46+
# Add headers
47+
req.add_field "Accept", "application/vnd.github.v3+json"
48+
# Set header and body
49+
req.add_field "Content-Type", "application/json"
50+
req.body = body
51+
52+
# Fetch Request
53+
res = http.request(req)
54+
rescue StandardError => e
55+
Helper.log.info "HTTP Request failed (#{e.message})".red
56+
end
57+
58+
case res.code.to_i
59+
when 201
60+
json = JSON.parse(res.body)
61+
Helper.log.info "Github Release Created (#{json["id"]})".green
62+
Helper.log.info "#{json["html_url"]}".green
63+
64+
Actions.lane_context[SharedValues::GITHUB_RELEASE_ID] = json["id"]
65+
Actions.lane_context[SharedValues::GITHUB_RELEASE_HTML_URL] = json["html_url"]
66+
Actions.lane_context[SharedValues::GITHUB_RELEASE_UPLOAD_URL_TEMPLATE] = json["upload_url"]
67+
return json
68+
when 400..499
69+
json = JSON.parse(res.body)
70+
raise "Error Creating Github Release (#{res.code}): #{json}".red
71+
else
72+
Helper.log.info "Status Code: #{res.code} Body: #{res.body}"
73+
raise "Error Creating Github Release".red
74+
end
75+
end
76+
77+
#####################################################
78+
# @!group Documentation
79+
#####################################################
80+
81+
def self.description
82+
"Create a Github Release"
83+
end
84+
85+
def self.available_options
86+
[
87+
FastlaneCore::ConfigItem.new(key: :owner,
88+
env_name: "GITHUB_OWNER",
89+
description: "The Github Owner",
90+
is_string:true,
91+
optional:false),
92+
FastlaneCore::ConfigItem.new(key: :repository,
93+
env_name: "GITHUB_REPOSITORY",
94+
description: "The Github Repository",
95+
is_string:true,
96+
optional:false),
97+
FastlaneCore::ConfigItem.new(key: :api_token,
98+
env_name: "GITHUB_API_TOKEN",
99+
description: "Personal API Token for GitHub - generate one at https://github.com/settings/tokens",
100+
is_string: true,
101+
optional: false),
102+
FastlaneCore::ConfigItem.new(key: :tag_name,
103+
env_name: "GITHUB_RELEASE_TAG_NAME",
104+
description: "Pass in the tag name",
105+
is_string: true,
106+
optional: false),
107+
FastlaneCore::ConfigItem.new(key: :target_commitish,
108+
env_name: "GITHUB_TARGET_COMMITISH",
109+
description: "Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists",
110+
is_string: true,
111+
optional: true),
112+
FastlaneCore::ConfigItem.new(key: :name,
113+
env_name: "GITHUB_RELEASE_NAME",
114+
description: "The name of the release",
115+
is_string: true,
116+
optional: true),
117+
FastlaneCore::ConfigItem.new(key: :body,
118+
env_name: "GITHUB_RELEASE_BODY",
119+
description: "Text describing the contents of the tag",
120+
is_string: true,
121+
optional: true),
122+
FastlaneCore::ConfigItem.new(key: :draft,
123+
env_name: "GITHUB_RELEASE_DRAFT",
124+
description: "true to create a draft (unpublished) release, false to create a published one",
125+
is_string: false,
126+
default_value: false),
127+
FastlaneCore::ConfigItem.new(key: :prerelease,
128+
env_name: "GITHUB_RELEASE_PRERELEASE",
129+
description: "true to identify the release as a prerelease. false to identify the release as a full release",
130+
is_string: false,
131+
default_value: false),
132+
133+
]
134+
end
135+
136+
def self.output
137+
[
138+
['GITHUB_RELEASE_ID', 'The Github Release ID'],
139+
['GITHUB_RELEASE_HTML_URL', 'The Github Release URL'],
140+
['GITHUB_RELEASE_UPLOAD_URL_TEMPLATE', 'The Github Release Upload URL']
141+
]
142+
end
143+
144+
def self.return_value
145+
"The Hash representing the API response"
146+
end
147+
148+
def self.authors
149+
["kcharwood"]
150+
end
151+
152+
def self.is_supported?(platform)
153+
return true
154+
end
155+
end
156+
end
157+
end

0 commit comments

Comments
 (0)