Class: Fastlane::Actions::ReleaseIosSdkAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/stream_actions/actions/release_ios_sdk.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.available_optionsObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/fastlane/plugin/stream_actions/actions/release_ios_sdk.rb', line 92

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :version,
      description: 'Release version (not required if release type is set)',
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :bump_type,
      description: 'Release type (not required if release version is set)',
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :sdk_names,
      description: 'SDK names to release',
      is_string: false,
      verify_block: proc do |sdks|
        UI.user_error!("SDK names array has to be specified") unless sdks.kind_of?(Array) && sdks.size.positive?
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :podspec_names,
      description: 'Podspec names to release',
      is_string: false,
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      env_name: 'GITHUB_REPOSITORY',
      key: :github_repo,
      description: 'Github repository name'
    ),
    FastlaneCore::ConfigItem.new(
      env_name: 'GITHUB_TOKEN',
      key: :github_token,
      description: 'GITHUB_TOKEN environment variable'
    ),
    FastlaneCore::ConfigItem.new(
      key: :skip_git_status_check,
      description: 'Skip git status check',
      is_string: false,
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :use_changelog,
      description: 'Use the changelog as a testflight instructions',
      is_string: false,
      default_value: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :changelog_path,
      env_name: 'FL_CHANGELOG_PATH',
      description: 'The path to your project CHANGELOG.md',
      is_string: true,
      default_value: './CHANGELOG.md'
    ),
    FastlaneCore::ConfigItem.new(
      key: :extra_changes,
      description: 'Lambda with extra changes to be commited to the release',
      is_string: false,
      default_value: false
    ),
    FastlaneCore::ConfigItem.new(
      key: :create_pull_request,
      description: 'Create pull request from release branch to main',
      is_string: false,
      default_value: false
    )
  ]
end

.commit_changes(version_number) ⇒ Object



78
79
80
81
82
# File 'lib/fastlane/plugin/stream_actions/actions/release_ios_sdk.rb', line 78

def self.commit_changes(version_number)
  sh("git add -A")
  sh("git commit -m 'Bump #{version_number}'")
  other_action.push_to_git_remote(tags: false)
end

.descriptionObject



88
89
90
# File 'lib/fastlane/plugin/stream_actions/actions/release_ios_sdk.rb', line 88

def self.description
  'Releases iOS SDKs'
end

.ensure_everything_is_set_up(params) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/fastlane/plugin/stream_actions/actions/release_ios_sdk.rb', line 62

def self.ensure_everything_is_set_up(params)
  other_action.ensure_git_status_clean unless params[:skip_git_status_check]

  if params[:version].nil? && !["patch", "minor", "major"].include?(params[:bump_type])
    UI.user_error!("Please use type parameter with one of the options: type:patch, type:minor, type:major")
  end
end

.ensure_release_tag_is_new(version_number) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/fastlane/plugin/stream_actions/actions/release_ios_sdk.rb', line 70

def self.ensure_release_tag_is_new(version_number)
  if other_action.git_tag_exists(tag: version_number)
    UI.user_error!("Tag for version #{version_number} already exists!")
  else
    UI.success("Ignore the red warning above. Tag for version #{version_number} is alright!")
  end
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/fastlane/plugin/stream_actions/actions/release_ios_sdk.rb', line 162

def self.is_supported?(platform)
  [:ios].include?(platform)
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fastlane/plugin/stream_actions/actions/release_ios_sdk.rb', line 4

def self.run(params)
  ensure_everything_is_set_up(params)

  version_acceptable_for_plist = other_action.core_version(version: params[:version])

  version_number = ''
  params[:sdk_names].each do |target|
    # Assigning is required because the version could have been passed via :bump_type
    version_number = other_action.increment_version_number_in_plist(
      target: target,
      version_number: version_acceptable_for_plist,
      bump_type: params[:bump_type]
    )
  end

  # Reassigning is required if the version was passed via :version to keep postfix such as "-beta" if exists
  version_number = params[:version] if params[:version]

  ensure_release_tag_is_new(version_number)

  changes =
    if params[:use_changelog]
      other_action.touch_changelog(
        release_version: version_number,
        github_repo: params[:github_repo],
        changelog_path: params[:changelog_path]
      )
    else
      "#{version_number} Release"
    end

  podspecs = params[:podspec_names]&.map { |sdk| "#{sdk}.podspec" } || []
  podspecs.each do |podspec|
    UI.user_error!("Podspec #{podspec} does not exist!") unless File.exist?(podspec)
    other_action.version_bump_podspec(path: podspec, version_number: version_number)
  end

  params[:extra_changes].call(version_number) if params[:extra_changes]

  sh("git checkout -b release/#{version_number}") if params[:create_pull_request]

  commit_changes(version_number)

  if params[:create_pull_request]
    other_action.create_pull_request(
      api_token: params[:github_token],
      repo: params[:github_repo],
      title: "#{version_number} Release",
      head: "release/#{version_number}",
      base: 'main',
      body: changes.to_s
    )
  end

  UI.success("Successfully started release #{version_number}! 🚢")
  version_number
end