fastlane-plugin-bitrise 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05dd7bdfddd3a2cbbabf155a18a970ea0803795b
4
+ data.tar.gz: 3b0bbad433cd453fc385f4027e439fca328cdf17
5
+ SHA512:
6
+ metadata.gz: a21c4c18b846ce7b0b097e6ca57ca73d1dbeae80f7cce740cdd46e01c2aba4365ba039fa7b00cb5c792c459aef81c51a034350396f4f0a861f3390dd8ab17df9
7
+ data.tar.gz: 4e34c332ea4cf9f5dfc541fd3d8d1f46a486386fe1a49cd1f89e30029dc59b98964edcf5095c9b7488412c46772ef1faa8e108f2aa2c91cfebf24796877ac66c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Robin AUTHIAT <authiatr@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.
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # bitrise plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-bitrise)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-bitrise`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin bitrise
11
+ ```
12
+
13
+ ## About bitrise
14
+
15
+ This plugin allow you to trigger a specific Bitrise workflow with some arguments with a HTTPS POST request on the Bitrise.io API.
16
+
17
+ It also allow you to override some environments variables.
18
+
19
+ It can help you to automatically trigger a build after a bump commit for instance without have to log into bitrise.io.
20
+
21
+ ## Options
22
+
23
+ | Option | Description | Type | Requirement | Environment Variable |
24
+ | --- | --- | :---: | :---: | --- |
25
+ | `app_slug` | Bitrise application slug, avalaible on bitrise.io > your app > code | String | **Mandatory** | `BITRISE_APP_SLUG` |
26
+ | `trigger_token` | Bitrise build trigger token, avalaible on bitrise.io > your app > code | String | **Mandatory** | `BITRISE_TRIGGER_TOKEN` |
27
+ | `workflow` | Bitrise workflow to trigger, if not specified, it'll trigger the default one | String | Optional | `BITRISE_WORKFLOW` |
28
+ | `build_message` | Build message who'll appear on the Bitrise.io build | String | Optional | `BITRISE_BUILD_MESSAGE` |
29
+ | `branch` | The git branch to build | String | Optional | `BITRISE_GIT_BRANCH` |
30
+ | `commit` | The git commit hash to build | String | Optional | `BITRISE_GIT_COMMIT` |
31
+ | `tag` | The git Tag to build | String | Optional | `BITRISE_GIT_TAG` |
32
+ | `environments` | Bitrise environments to replace, it'll override the previous environment variables specified. The Hash key has to be the environment variable key (without the `$`), the Hash value has to be environment variable value | Hash | Optional | `BITRISE_ENVIRONMENTS` |
33
+
34
+ ## Return values
35
+
36
+ The `bitrise` plugin return a Hash containing the bitrise build informations return by the API.
37
+
38
+ | Hash key | Description |
39
+ | --- | --- |
40
+ | `build_number` | Bitrise build number |
41
+ | `build_url` | Bitrise build url |
42
+
43
+ If an error is return by the bitrise.io API, the plugin will **throw an exception**.
44
+
45
+ ## Examples
46
+
47
+ To trigger the default workflow set on Bitrise.io on the default git branch execute:
48
+ ```
49
+ bitrise(
50
+ "app_slug": "YOUR_APP_SLUG",
51
+ "trigger_token": "YOUR_TRIGGER_TOKEN"
52
+ )
53
+ ```
54
+
55
+ To trigger a build with a specific workflow, a specific git branch, display a build message and override some environments variables execute the following command:
56
+ ```
57
+ bitrise(
58
+ "app_slug": "YOUR_APP_SLUG",
59
+ "trigger_token": "YOUR_TRIGGER_TOKEN",
60
+ "workflow": "Beta",
61
+ "build_message": "Deploy build version 1.3.2 build number 11 to Beta test",
62
+ "branch": "release/1.3.2",
63
+ "environments": {
64
+ "BUILD_CONFIGURATION" => "Production", # Environment variable to override during Bitrise.io build
65
+ "ANOTHER_ENVIRONMENT_VARIABLE" => "123456" # Environment variable to override during Bitrise.io build
66
+ }
67
+ )
68
+ ```
69
+
70
+ ## Run tests for this plugin
71
+
72
+ To run both the tests, and code style validation, run
73
+
74
+ ```
75
+ rake
76
+ ```
77
+
78
+ To automatically fix many of the styling issues, use
79
+ ```
80
+ rubocop -a
81
+ ```
82
+
83
+ ## Issues and Feedback
84
+
85
+ For any other issues and feedback about this plugin, **please submit it to this repository**.
86
+
87
+ ## Troubleshooting
88
+
89
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
90
+
91
+ ## Using _fastlane_ Plugins
92
+
93
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
94
+
95
+ ## About _fastlane_
96
+
97
+ _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).
98
+
99
+ ## Author
100
+ Robin Authiat, [@authiat_robin](https://twitter.com/authiat_robin)
101
+
102
+ I'm available for freelance work (Fastlane Continuous Delivery, Continuous Integration and iOS development). Feel free to contact me 🚀
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/bitrise/version'
2
+
3
+ module Fastlane
4
+ module Bitrise
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::Bitrise.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,227 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/bitrise_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class BitriseAction < Action
7
+ def self.run(params)
8
+ FastlaneCore::PrintTable.print_values(config: params.values(ask: false),
9
+ hide_keys: [],
10
+ title: "Bitrise options")
11
+
12
+ json = get_post_payload(params[:trigger_token],
13
+ params[:workflow],
14
+ params[:build_message],
15
+ params[:branch],
16
+ params[:commit],
17
+ params[:tag],
18
+ params[:environments])
19
+
20
+ trigger_bitrise_build(params[:app_slug], json)
21
+ end
22
+
23
+ # Get POST payload json
24
+ #
25
+ # Parameters:
26
+ # - trigger_token: Bitrise.io trigger token
27
+ # - workflow: Bitrise.io workflow to trigger (optional)
28
+ # - build_message: Build message on Bitrise.io (optional)
29
+ # - branch: Git branch to trigger (optional)
30
+ # - commit: Git commit to trigger (optional)
31
+ # - tag: Git tag to trigger (optional)
32
+ # - environments: Environments variables hash to replace (optional)
33
+ #
34
+ # Returns the JSON post payload
35
+ def self.get_post_payload(trigger_token, workflow, build_message, branch, commit, tag, environments)
36
+ UI.message("Payload creation...")
37
+ json_curl = {}
38
+ payload = {}
39
+
40
+ hook_info = {}
41
+ hook_info["type"] = "bitrise"
42
+ hook_info["build_trigger_token"] = trigger_token
43
+ payload["hook_info"] = hook_info
44
+
45
+ build_params = {}
46
+ unless workflow.nil?
47
+ build_params["workflow_id"] = workflow
48
+ end
49
+
50
+ unless build_message.nil? || build_message.empty?
51
+ build_params["commit_message"] = build_message
52
+ end
53
+
54
+ unless branch.nil?
55
+ build_params["branch"] = branch
56
+ end
57
+
58
+ unless commit.nil?
59
+ build_params["commit_hash"] = commit
60
+ end
61
+
62
+ unless tag.nil?
63
+ build_params["tag"] = tag
64
+ end
65
+
66
+ unless environments.nil?
67
+ build_params["environments"] = get_environments_from(environments)
68
+ end
69
+ payload["build_params"] = build_params
70
+ json_curl["payload"] = payload
71
+
72
+ json_curl.to_json
73
+ end
74
+
75
+ # Transform environments variable hash into dictionary objects
76
+ #
77
+ # Parameters:
78
+ # - params: Environments hash to transform
79
+ #
80
+ # Returns the environments objects array
81
+ def self.get_environments_from(params)
82
+ environments = []
83
+
84
+ params.each do |key, value|
85
+ environment = {}
86
+ environment["mapped_to"] = key
87
+ environment["value"] = value
88
+ environment["is_expand"] = true
89
+
90
+ environments.push(environment)
91
+ end
92
+
93
+ environments
94
+ end
95
+
96
+ # Call the Bitrise.io API with a POST HTTP request with the specified payload.
97
+ # It'll throw an exception if the API return an other HTTP status code than 201.
98
+ #
99
+ # Parameters:
100
+ # - app_slug: Application slug
101
+ # - json: request payload
102
+ def self.trigger_bitrise_build(app_slug, json)
103
+ UI.command(json)
104
+
105
+ UI.message("Requesting Bitrise.io API...")
106
+ uri = URI.parse("https://app.bitrise.io/app/#{app_slug}/build/start.json")
107
+ https = Net::HTTP.new(uri.host, uri.port)
108
+ https.use_ssl = true
109
+ request = Net::HTTP::Post.new(uri.path, { 'Content-Type' => 'application/json' })
110
+ request.body = json
111
+ response = https.request(request)
112
+ json_response = JSON.parse(response.body)
113
+ FastlaneCore::PrintTable.print_values(config: json_response,
114
+ hide_keys: [],
115
+ title: "Bitrise API response")
116
+
117
+ if response.code == "201"
118
+ UI.success("Build triggered successfully on Bitrise.io 🚀")
119
+ else
120
+ if response.code == "400"
121
+ error = json_response["message"]
122
+ else
123
+ error = json_response["error_msg"]
124
+ end
125
+ UI.user_error!("Couln't trigger the build on Bitrise.io. #{error}")
126
+ end
127
+
128
+ build_infos = {}
129
+ build_infos["build_number"] = json_response["build_number"]
130
+ build_infos["build_url"] = json_response["build_url"]
131
+
132
+ build_infos
133
+ end
134
+
135
+ def self.description
136
+ "Trigger a bitrise build"
137
+ end
138
+
139
+ def self.authors
140
+ ["Robin AUTHIAT"]
141
+ end
142
+
143
+ def self.return_value
144
+ "If the build could be triggered, it returns the build informations such as the bitrise build number and the bitrise build url in a Hash"
145
+ end
146
+
147
+ def self.details
148
+ "This plugin allow you to trigger a specific Bitrise workflow with some arguments with a HTTPS POST on the Bitrise API."
149
+ end
150
+
151
+ def self.available_options
152
+ [
153
+ # App specific parameters
154
+ FastlaneCore::ConfigItem.new(key: :app_slug,
155
+ env_name: "BITRISE_APP_SLUG",
156
+ description: "Bitrise application slug, avalaible on bitrise.io > your app > code",
157
+ optional: false,
158
+ type: String,
159
+ verify_block: proc do |value|
160
+ UI.user_error!("No Bitrise app slug given, pass it using `app_slug` parameter to the bitrise plugin.") unless value && !value.empty?
161
+ end),
162
+ FastlaneCore::ConfigItem.new(key: :trigger_token,
163
+ env_name: "BITRISE_TRIGGER_TOKEN",
164
+ description: "Bitrise build trigger token, avalaible on bitrise.io > your app > code",
165
+ optional: false,
166
+ type: String,
167
+ verify_block: proc do |value|
168
+ UI.user_error!("No Bitrise trigger token given, pass it using `trigger_token` parameter to the bitrise plugin.") unless value && !value.empty?
169
+ end),
170
+ # Bitrise.io specific parameters
171
+ FastlaneCore::ConfigItem.new(key: :workflow,
172
+ env_name: "BITRISE_WORKFLOW",
173
+ description: "Bitrise workflow to trigger, if not specified, it'll trigger the default one",
174
+ optional: true,
175
+ type: String,
176
+ verify_block: proc do |value|
177
+ UI.user_error!("Empty Bitrise workflow given, pass it using `workflow` parameter to the bitrise plugin.") unless value && !value.empty?
178
+ end),
179
+ FastlaneCore::ConfigItem.new(key: :build_message,
180
+ env_name: "BITRISE_BUILD_MESSAGE",
181
+ description: "Build message who'll appear on Bitrise.io build",
182
+ optional: true,
183
+ type: String),
184
+ FastlaneCore::ConfigItem.new(key: :environments,
185
+ env_name: "BITRISE_ENVIRONMENTS",
186
+ description: "Bitrise environments to replace, it'll override the previous environment variables specified. The Hash key has to be the environment variable key (without the $), the Hash value has to be environment variable value",
187
+ optional: true,
188
+ type: Hash,
189
+ verify_block: proc do |value|
190
+ value.each do |key|
191
+ UI.user_error!("Please remove the '$' from the environment variable #{key}") if key.to_s.include?("$")
192
+ end
193
+ end),
194
+ # Git related parameters
195
+ FastlaneCore::ConfigItem.new(key: :branch,
196
+ env_name: "BITRISE_GIT_BRANCH",
197
+ description: "Git branch where to trigger bitrise workflow",
198
+ optional: true,
199
+ type: String,
200
+ verify_block: proc do |value|
201
+ UI.user_error!("Empty Bitrise git branch given, pass it using `branch` parameter to the bitrise plugin.") unless value && !value.empty?
202
+ end),
203
+ FastlaneCore::ConfigItem.new(key: :commit,
204
+ env_name: "BITRISE_GIT_COMMIT",
205
+ description: "Specific Git commit to trigger bitrise workflow",
206
+ optional: true,
207
+ type: String,
208
+ verify_block: proc do |value|
209
+ UI.user_error!("Empty Bitrise git commit given, pass it using `commit` parameter to the bitrise plugin.") unless value && !value.empty?
210
+ end),
211
+ FastlaneCore::ConfigItem.new(key: :tag,
212
+ env_name: "BITRISE_GIT_TAG",
213
+ description: "Specific Git tag to trigger bitrise workflow",
214
+ optional: true,
215
+ type: String,
216
+ verify_block: proc do |value|
217
+ UI.user_error!("Empty Bitrise git tag given, pass it using `tag` parameter to the bitrise plugin.") unless value && !value.empty?
218
+ end)
219
+ ]
220
+ end
221
+
222
+ def self.is_supported?(platform)
223
+ true
224
+ end
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,10 @@
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 BitriseHelper
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module Bitrise
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-bitrise
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robin AUTHIAT
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-31 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.112.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.112.0
139
+ description:
140
+ email: authiatr@gmail.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/fastlane/plugin/bitrise.rb
148
+ - lib/fastlane/plugin/bitrise/actions/bitrise_action.rb
149
+ - lib/fastlane/plugin/bitrise/helper/bitrise_helper.rb
150
+ - lib/fastlane/plugin/bitrise/version.rb
151
+ homepage: https://github.com/authiatr/fastlane-plugin-bitrise
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
+ rubyforge_project:
171
+ rubygems_version: 2.6.8
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Trigger a bitrise build
175
+ test_files: []