Skip to content

Commit

Permalink
Merge branch 'release/v2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alesete committed Sep 27, 2019
2 parents f4bdcfa + 4b20032 commit a994a90
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 68 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ lane :applivery_ios do
scheme: "YOUR_APP_SCHEME", # Your App Scheme
export_method: 'enterprise') # Choose between: enterprise or ad-hoc
applivery(
app_token: "YOUR_APP_TOKEN" # Your Applivery App Token
)
app_token: "YOUR_APP_TOKEN") # Your Applivery App Token
end
```

Expand All @@ -49,8 +48,7 @@ Next you'll find a `lane` with two steps: `gradle()` that will build the Android
lane :applivery_android do
gradle(task: "assembleRelease")
applivery(
appToken: "YOUR_APP_TOKEN" # Your Applivery App Token
)
appToken: "YOUR_APP_TOKEN") # Your Applivery App Token
end
```

Expand All @@ -70,6 +68,28 @@ The above examples are the most simple configuration you can have but you can ad
| `tags` | Tags to identify the build | NO | string -> comma separated. i.e.: "RC1, QA" |
| `build_path` | Build path to the APK / IPA file | NO | string -> by default it takes the IPA/APK build path |

## Shared Value
Once your build is uploaded successfuly, the new generated build ID is provided by a Shared Value `APPLIVERY_BUILD_ID` that can be accesed in your lane with `lane_context[SharedValues::APPLIVERY_BUILD_ID]`

Example:

```ruby
lane :applivery_ios do
gym(
scheme: "YOUR_APP_SCHEME", # Your App Scheme
export_method: 'enterprise') # Choose between: enterprise or ad-hoc
applivery(
app_token: "YOUR_APP_TOKEN" # Your Applivery App Token)
puts "BUILD ID: #{lane_context[SharedValues::APPLIVERY_BUILD_ID]}"
end
```

You could use this id to open your build information in applivery like:

```
https://dashboard.applivery.io/apps/apps/{YOUR_APP_SLUG}/builds?id={THIS_BUILD_ID}
```

## Run tests for this plugin

To run both the tests, and code style validation, run
Expand Down
89 changes: 65 additions & 24 deletions lib/fastlane/plugin/applivery/actions/applivery_action.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,67 @@
require 'faraday'

module Fastlane
module Actions

module SharedValues
APPLIVERY_BUILD_ID = :APPLIVERY_BUILD_ID
end

class AppliveryAction < Action

def self.run(params)
app_token = params[:app_token]
name = params[:name]
changelog = Helper::AppliveryHelper.escape(params[:changelog])
notify_message = Helper::AppliveryHelper.escape(params[:notify_message])
tags = params[:tags]
build_path = params[:build_path]
notify_collaborators = params[:notify_collaborators]
notify_employees = params[:notify_employees]

command = "curl \"https://api.applivery.io/v1/integrations/builds\""
command += " -H \"Authorization: bearer #{app_token}\""
command += " -F versionName=\"#{name}\""
command += " -F changelog=\"#{changelog}\""
command += " -F notifyCollaborators=#{notify_collaborators}"
command += " -F notifyEmployees=#{notify_employees}"
command += " -F tags=\"#{tags}\""
command += " -F notifyMessage=\"#{notify_message}\""
command += " -F build=@\"#{build_path}\""
command += " -F deployer.name=fastlane"
command += Helper::AppliveryHelper.add_integration_number
command += Helper::AppliveryHelper.add_git_params

Actions.sh(command)
build = Faraday::UploadIO.new(build_path, 'application/octet-stream') if build_path && File.exist?(build_path)

conn = Faraday.new(url: 'https://api.applivery.io') do |faraday|
faraday.request :multipart
faraday.request :url_encoded
# faraday.response :logger
faraday.use FaradayMiddleware::ParseJson
faraday.adapter :net_http
end

response = conn.post do |req|
req.url '/v1/integrations/builds'
req.headers['Content-Type'] = 'multipart/form-data'
req.headers['Accept'] = 'application/json'
req.headers['Authorization'] = "bearer #{params[:app_token]}"
request_body = {
changelog: params[:changelog],
notifyCollaborators: params[:notify_collaborators],
notifyEmployees: params[:notify_employees],
notifyMessage: params[:notify_message],
build: build,
deployer: {
name: "fastlane",
info: {
buildNumber: Helper::AppliveryHelper.get_integration_number,
branch: Helper::AppliveryHelper.git_branch,
commit: Helper::AppliveryHelper.git_commit,
commitMessage: Helper::AppliveryHelper.git_message,
repositoryUrl: Helper::AppliveryHelper.add_git_remote,
tag: Helper::AppliveryHelper.git_tag,
triggerTimestamp: Time.now.getutc.to_i
}
}
}
request_body[:versionName] = params[:name] if !params[:name].nil?
request_body[:tags] = params[:tags] if !params[:tags].nil?

req.body = request_body
UI.message "Uploading to Applivery... 🛫"
UI.verbose("Request Body: #{req.body}")
end
UI.verbose "Response Body: #{response.body}"
status = response.body["status"]
Actions.lane_context[SharedValues::APPLIVERY_BUILD_ID] = response.body["data"]["id"]
if status
UI.success "Build uploaded succesfully! 💪"
else
UI.error "Oops! Something went wrong.... 🔥"
Helper::AppliveryHelper.parse_error(response.error)
end

end

def self.build_path
Expand Down Expand Up @@ -104,6 +140,12 @@ def self.available_options
]
end

def self.output
[
['APPLIVERY_BUILD_ID', 'The id for the new build generated. You can open your build in https://dashboard.applivery.io/apps/apps/<YOUR_APP_SLUG>/builds?id=${APPLIVERY_BUILD_ID}']
]
end

def self.is_supported?(platform)
# Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
# See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
Expand All @@ -118,8 +160,7 @@ def self.category

def self.example_code
[
'applivery(
app_token: "YOUR_APP_TOKEN")'
'applivery(app_token: "YOUR_APP_TOKEN")'
]
end

Expand Down
82 changes: 43 additions & 39 deletions lib/fastlane/plugin/applivery/helper/applivery_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def self.show_message
UI.message("Hello from the applivery plugin helper!")
end

def self.escape(string)
return URI.encode(string.sub(/@/, '\@'))
end

def self.platform
platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
if platform == :ios or platform.nil?
Expand All @@ -21,69 +17,77 @@ def self.platform
end
end

def self.add_integration_number
def self.get_integration_number
xcodeIntegrationNumber = ENV["XCS_INTEGRATION_NUMBER"] # XCode Server
jenkinsIntegrationNumber = ENV["BUILD_NUMBER"] # Jenkins
travisIntegrationNumber = ENV["TRAVIS_BUILD_NUMBER"] # Travis
command = ""
integrationNumber = ""

if !xcodeIntegrationNumber.nil?
command += " -F deployer.info.buildNumber=\"#{xcodeIntegrationNumber}\""
integrationNumber += xcodeIntegrationNumber
elsif !jenkinsIntegrationNumber.nil?
command += " -F deployer.info.buildNumber=\"#{jenkinsIntegrationNumber}\""
integrationNumber += jenkinsIntegrationNumber
elsif !travisIntegrationNumber.nil?
command += " -F deployer.info.buildNumber=\"#{travisIntegrationNumber}\""
integrationNumber += travisIntegrationNumber
end

return command
return integrationNumber
end


### GIT Methods ###

def self.is_git?
Actions.sh('git rev-parse HEAD')
return true
def self.git_branch
return Actions.git_branch
rescue
return false
return ""
end

def self.add_git_params
command = ""
if self.is_git?
UI.message "Detected repo: git"
gitBranch = Actions.git_branch
gitCommit = Actions.sh('git rev-parse --short HEAD')
gitMessage = Actions.last_git_commit_message

command += " -F deployer.info.branch=\"#{gitBranch}\""
command += " -F deployer.info.commit=\"#{gitCommit}\""
command += " -F deployer.info.commitMessage=\"#{self.escape(gitMessage)}\""
command += self.add_git_remote
command += self.add_git_tag
end
return command
def self.git_commit
return `git rev-parse --short HEAD`
rescue
return ""
end

def self.add_git_tag
gitTag = Actions.sh('git describe --abbrev=0 --tags')
gitTagCommit = Actions.sh("git rev-list -n 1 --abbrev-commit #{gitTag}")
gitCommit = Actions.sh('git rev-parse --short HEAD')
if gitTagCommit == gitCommit
return " -F deployer.info.tag=\"#{gitTag}\""
end
return ""
def self.git_message
return Actions.last_git_commit_message
rescue
return ""
end

def self.add_git_remote
gitRepositoryURL = Actions.sh('git config --get remote.origin.url')
return " -F deployer.info.repositoryUrl=\"#{gitRepositoryURL}\""
return `git config --get remote.origin.url`
rescue
return ""
end

def self.git_tag
gitTag = `git describe --abbrev=0 --tags`
gitTagCommit = `git rev-list -n 1 --abbrev-commit #{gitTag}`
gitCommit = `git rev-parse --short HEAD`
return gitTag if gitTagCommit == gitCommit
return ""
rescue
return ""
end

def self.parse_error(error)
if error
case error["code"]
when 5006
UI.user_error! "Upload fail. The build path seems to be wrong or file is invalid"
when 4004
UI.user_error! "The app_token is not valid. Please, go to your app settings and doble-check the integration tokens"
when 4002
UI.user_error! "The app_token is empty. Please, go to your app Settings->Integrations to generate a token"
else
UI.user_error! "Upload fail. [#{error["code"]}]: #{error["message"]}"
end
else
UI.crash! "Upload fails unexpectedly. [#{response.status}]"
end
end

end
end
end
2 changes: 1 addition & 1 deletion lib/fastlane/plugin/applivery/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Fastlane
module Applivery
VERSION = "2.0.0"
VERSION = "2.1.0"
end
end

0 comments on commit a994a90

Please sign in to comment.