fastlane-plugin-codemagic 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d9b819c659bcf16f152f9c90d0b71ddbac1e120202e72c78e67dcd3e9044ea6c
4
+ data.tar.gz: d660c712ffb099c5e7fc84a2338e914836803b96ecd06c0f9f690344166d801c
5
+ SHA512:
6
+ metadata.gz: 60d68646a122d16a90b7d059624f8fb3a6385c9d70108511ca11cc8039e0b2ae502272a11853117237614d6acf833f59c5ef9b6f9a5e505c15fd6c0ef2b3f442
7
+ data.tar.gz: 94a4ef6e78c9df6286b24aff137c120472cc691d0d591ffb7ce82bac595269f814d85ba2200c211f8ef04516c2f09f925ce80c056741733d6aa1fd2e8b179234
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Mikhail Matsera <mmatsera@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,88 @@
1
+ # codemagic plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-codemagic)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-codemagic`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin codemagic
11
+ ```
12
+
13
+ ## About codemagic
14
+
15
+ Fastlane plugin to trigger a Codemagic build with some options
16
+
17
+ **Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
18
+
19
+ ## Options
20
+
21
+ | Option | Description | Type | Requirement | Environment Variable |
22
+ | --- | --- | :---: | :---: | --- |
23
+ | `auth_token` | Codemagic API access token is available via UI in User settings > Integrations > Codemagic API > Show | String | **Required** | `CODEMAGIC_AUTH_TOKEN` |
24
+ | `app_id` | Codemagic application identifier. | String | **Required** | `CODEMAGIC_APP_ID` |
25
+ | `workflow_id` | Codemagic workflow identifier as specified in YAML file. | String | **Required** | `CODEMAGIC_WORKFLOW_ID` |
26
+ | `branch` | Git branch name | String | **Required** | `CODEMAGIC_BRANCH` |
27
+ | `download` | Artefacts downloading options | Object | Optional | **none** |
28
+ | `environment` | Codemagic specify environment variables and software versions to override values defined in workflow settings. | Object | Optional | **none** |
29
+
30
+ ## Return values
31
+
32
+ If an error is return by the codemagic.io API, the plugin will **throw an exception**.
33
+
34
+ ## Examples
35
+
36
+ ```
37
+ codemagic(
38
+ workflow_id: "YOUR_WORKFLOW_ID",
39
+ app_id: "YOUR_APP_ID",
40
+ branch: "release/4.1.2",
41
+ auth_token: "82Kf0RHv8MWS7VctoFHxGtW-wIWEkPUI0-E8DkJ4HaY",
42
+ download: {
43
+ artefacts: ["ipa"],
44
+ build_path: "./build/"
45
+ },
46
+ environment: {
47
+ variables: {
48
+ "ENV": "production",
49
+ "YET_ANOTHER_ENVIRONMENT_VARIABLE" => "123456"
50
+ },
51
+ softwareVersions: {
52
+ flutter: stable
53
+ xcode: latest
54
+ cocoapods: default
55
+ }
56
+ }
57
+ )
58
+ ```
59
+ **Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
60
+
61
+ ## Run tests for this plugin
62
+
63
+ To run both the tests, and code style validation, run
64
+
65
+ ```
66
+ rake
67
+ ```
68
+
69
+ To automatically fix many of the styling issues, use
70
+ ```
71
+ rubocop -a
72
+ ```
73
+
74
+ ## Issues and Feedback
75
+
76
+ For any other issues and feedback about this plugin, please submit it to this repository.
77
+
78
+ ## Troubleshooting
79
+
80
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
81
+
82
+ ## Using _fastlane_ Plugins
83
+
84
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
85
+
86
+ ## About _fastlane_
87
+
88
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/codemagic/version'
2
+
3
+ module Fastlane
4
+ module Codemagic
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::Codemagic.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,266 @@
1
+ module Fastlane
2
+ module Actions
3
+ class CodemagicAction < Action
4
+ def self.run(params)
5
+ UI.message("The codemagic plugin is working!")
6
+
7
+ FastlaneCore::PrintTable.print_values(config: params.values(ask: false),
8
+ hide_keys: [],
9
+ title: "Codemagic options")
10
+
11
+ json = get_post_payload(params[:app_id],
12
+ params[:workflow_id],
13
+ params[:branch],
14
+ params[:environment])
15
+
16
+ params[:download] ||= {}
17
+ params[:download][:artefacts] ||= []
18
+ params[:download][:build_path] ||= nil
19
+
20
+ build_path = params[:download][:build_path]
21
+ download_artefacts = params[:download][:artefacts]
22
+
23
+ trigger_codemagic_build(params[:auth_token], json)
24
+
25
+ last_build_id = get_last_build_id(params[:auth_token], params[:app_id])
26
+
27
+ build = check_building_status(params[:auth_token], last_build_id)
28
+
29
+ if build_path != nil
30
+ download_artefacts(download_artefacts, build, build_path)
31
+ end
32
+ end
33
+
34
+ def self.get_post_payload(app_id, workflow_id, branch, environment)
35
+ UI.message("Payload creation...")
36
+ payload = {}
37
+
38
+ unless app_id.nil?
39
+ payload["appId"] = app_id
40
+ end
41
+
42
+ unless workflow_id.nil?
43
+ payload["workflowId"] = workflow_id
44
+ end
45
+
46
+ unless branch.nil?
47
+ payload["branch"] = branch
48
+ end
49
+
50
+ unless environment.nil?
51
+ payload["environment"] = environment
52
+ end
53
+
54
+ payload.to_json
55
+ end
56
+
57
+ def self.trigger_codemagic_build(auth_token, json)
58
+ UI.message("Requesting codemagic.io API...")
59
+ uri = URI.parse("https://api.codemagic.io/builds")
60
+ https = Net::HTTP.new(uri.host, uri.port)
61
+ https.use_ssl = true
62
+ request = Net::HTTP::Post.new(uri.path)
63
+
64
+ request["X-Auth-Token"] = auth_token
65
+ request["Content-Type"] = "application/json"
66
+
67
+ request.body = json
68
+ response = https.request(request)
69
+
70
+ json_response = JSON.parse(response.body)
71
+
72
+ if response.code == "200"
73
+ UI.success("Build triggered successfully on Codemagic.io 🚀 [#{json_response}]")
74
+ else
75
+ UI.user_error!("Couln't trigger the build on Codemagic.io.")
76
+ FastlaneCore::PrintTable.print_values(config: json_response,
77
+ hide_keys: [],
78
+ title: "Codemagic API response")
79
+ end
80
+
81
+ end
82
+
83
+ def self.get_last_build_id(auth_token, app_id)
84
+ UI.message("Requesting codemagic.io API...")
85
+ uri = URI.parse("https://api.codemagic.io/apps/#{app_id}")
86
+ https = Net::HTTP.new(uri.host, uri.port)
87
+ https.use_ssl = true
88
+ request = Net::HTTP::Get.new(uri.path)
89
+
90
+ request["X-Auth-Token"] = auth_token
91
+ request["Content-Type"] = "application/json"
92
+
93
+ response = https.request(request)
94
+ json_response = JSON.parse(response.body)
95
+
96
+ if response.code == "200"
97
+ last_build_id = json_response["application"]["lastBuildId"]
98
+ UI.success("Get last build ID on Codemagic.io 🚀 [#{last_build_id}]")
99
+ last_build_id
100
+ else
101
+ UI.user_error!("Couln't trigger the build on Codemagic.io.")
102
+ FastlaneCore::PrintTable.print_values(config: json_response,
103
+ hide_keys: [],
104
+ title: "Codemagic API response")
105
+ end
106
+
107
+ end
108
+
109
+ def self.check_building_status(auth_token, build_id)
110
+ while true do
111
+ build = get_build(auth_token, build_id)
112
+ build_status = build["status"]
113
+
114
+ case build_status
115
+ when "failed"
116
+ UI.abort_with_message!(build["message"])
117
+ when "success"
118
+ when "finished"
119
+ UI.success("Success")
120
+ else
121
+ UI.message(build_status)
122
+ sleep 10
123
+ next
124
+ end
125
+ build
126
+ break
127
+ end
128
+ end
129
+
130
+ def self.get_build(auth_token, build_id)
131
+ UI.message("Requesting codemagic.io API...")
132
+ uri = URI.parse("https://api.codemagic.io/builds/#{build_id}")
133
+ https = Net::HTTP.new(uri.host, uri.port)
134
+ https.use_ssl = true
135
+ request = Net::HTTP::Get.new(uri.path)
136
+
137
+ request["X-Auth-Token"] = auth_token
138
+ request["Content-Type"] = "application/json"
139
+
140
+ response = https.request(request)
141
+
142
+ json_response = JSON.parse(response.body)
143
+
144
+ if response.code == "200"
145
+
146
+ UI.success("Build triggered successfully on Codemagic.io 🚀")
147
+ FastlaneCore::PrintTable.print_values(config: json_response["build"],
148
+ hide_keys: [],
149
+ title: "Build")
150
+ json_response["build"]
151
+ else
152
+ UI.user_error!("Couln't trigger the build on Codemagic.io.")
153
+ FastlaneCore::PrintTable.print_values(config: json_response,
154
+ hide_keys: [],
155
+ title: "Codemagic API response")
156
+ end
157
+ end
158
+
159
+ def self.download_artefacts(download_artefacts, build, build_path)
160
+ UI.message("Download artefacts codemagic.io API...")
161
+ artefacts = build["artefacts"]
162
+
163
+ Dir.chdir("#{Dir.pwd}/fastlane")
164
+
165
+ real_build_dir = File.expand_path("#{build_path}")
166
+
167
+ if Dir.exist?(real_build_dir)
168
+
169
+ artefacts.map do |artefact|
170
+
171
+ if download_artefacts.include?(artefact["type"])
172
+
173
+ FastlaneCore::PrintTable.print_values(config: artefact,
174
+ hide_keys: [])
175
+
176
+ real_build_path = File.expand_path("#{build_path}#{artefact["name"]}")
177
+
178
+ open(real_build_path, 'wb') do |file|
179
+ file << open(artefact["url"]).read
180
+ end
181
+
182
+ end
183
+ end
184
+ else
185
+ UI.build_failure!("Directory not exists [#{real_build_dir}]")
186
+ end
187
+ end
188
+
189
+ def self.description
190
+ "Fastlane plugin to trigger a Codemagic build with some options"
191
+ end
192
+
193
+ def self.authors
194
+ ["Mikhail Matsera"]
195
+ end
196
+
197
+ def self.return_value
198
+ # If your method provides a return value, you can describe here what it does
199
+ end
200
+
201
+ def self.details
202
+ # Optional:
203
+ ""
204
+ end
205
+
206
+ def self.available_options
207
+ [
208
+ FastlaneCore::ConfigItem.new(key: :app_id,
209
+ env_name: "CODEMAGIC_APP_ID",
210
+ description: "Codemagic application identifier",
211
+ optional: false,
212
+ type: String,
213
+ verify_block: proc do |value|
214
+ UI.user_error!("No Codemagic application ID given, pass it using `app_id` parameter to the Codemagic plugin.") unless value && !value.empty?
215
+ end),
216
+
217
+ FastlaneCore::ConfigItem.new(key: :workflow_id,
218
+ env_name: "CODEMAGIC_WORKFLOW_ID",
219
+ description: "Codemagic workflow identifier as specified in YAML file",
220
+ optional: false,
221
+ type: String,
222
+ verify_block: proc do |value|
223
+ UI.user_error!("No Codemagic workflow ID given, pass it using `workflow_id` parameter to the Codemagic plugin.") unless value && !value.empty?
224
+ end),
225
+
226
+ FastlaneCore::ConfigItem.new(key: :auth_token,
227
+ env_name: "CODEMAGIC_AUTH_TOKEN",
228
+ description: "Codemagic Auth Token",
229
+ optional: false,
230
+ type: String,
231
+ verify_block: proc do |value|
232
+ UI.user_error!("No Codemagic auth token given, pass it using `auth_token` parameter to the Codemagic plugin.") unless value && !value.empty?
233
+ end),
234
+
235
+ FastlaneCore::ConfigItem.new(key: :branch,
236
+ env_name: "CODEMAGIC_BRANCH",
237
+ description: "Codemagic branch name",
238
+ optional: false,
239
+ type: String,
240
+ verify_block: proc do |value|
241
+ UI.user_error!("No Codemagic branch given, pass it using `branch` parameter to the Codemagic plugin.") unless value && !value.empty?
242
+ end),
243
+
244
+ FastlaneCore::ConfigItem.new(key: :download,
245
+ description: "Download Codemagic artefacts",
246
+ optional: true,
247
+ type: Object),
248
+
249
+ FastlaneCore::ConfigItem.new(key: :environment,
250
+ description: "Codemagic Specify environment variables and software versions to override values defined in workflow settings",
251
+ optional: true,
252
+ type: Object)
253
+ ]
254
+ end
255
+
256
+
257
+ def self.is_supported?(platform)
258
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
259
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
260
+ #
261
+ # [:ios, :mac, :android].include?(platform)
262
+ true
263
+ end
264
+ end
265
+ end
266
+ end
@@ -0,0 +1,16 @@
1
+ require 'fastlane_core/ui/ui'
2
+
3
+ module Fastlane
4
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
5
+
6
+ module Helper
7
+ class CodemagicHelper
8
+ # class methods that you define here become available in your action
9
+ # as `Helper::CodemagicHelper.your_method`
10
+ #
11
+ def self.show_message
12
+ UI.message("Hello from the codemagic plugin helper!")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module Codemagic
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-codemagic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mikhail Matsera
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.49.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.49.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-require_tools
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fastlane
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 2.154.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 2.154.0
139
+ description:
140
+ email: mmatsera@gmail.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/fastlane/plugin/codemagic.rb
148
+ - lib/fastlane/plugin/codemagic/actions/codemagic_action.rb
149
+ - lib/fastlane/plugin/codemagic/helper/codemagic_helper.rb
150
+ - lib/fastlane/plugin/codemagic/version.rb
151
+ homepage: https://github.com/jetcore/fastlane-plugin-codemagic
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubygems_version: 3.1.2
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Fastlane plugin to trigger a Codemagic build with some options
174
+ test_files: []