Skip to content

Instantly share code, notes, and snippets.

@jgautheron
Forked from kennydee/Fastfile
Created August 8, 2017 13:58
Show Gist options
  • Select an option

  • Save jgautheron/f6798c331449be7b6ca17e2536aee4ee to your computer and use it in GitHub Desktop.

Select an option

Save jgautheron/f6798c331449be7b6ca17e2536aee4ee to your computer and use it in GitHub Desktop.

Revisions

  1. Kenny Dits @kenny_dee revised this gist Jun 17, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Fastfile
    Original file line number Diff line number Diff line change
    @@ -109,7 +109,7 @@ platform :ios do
    url: "#{lane_context[SharedValues::APPETIZE_APP_URL]}",
    description: 'iOs build succeed'
    )
    end
    end

    error do |lane, exception|

    @@ -158,7 +158,7 @@ platform :android do
    url: "#{lane_context[SharedValues::APPETIZE_APP_URL]}",
    description: 'Android build succeed'
    )
    end
    end

    error do |lane, exception|

  2. Kenny Dits @kenny_dee revised this gist Jun 17, 2016. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Fastfile
    Original file line number Diff line number Diff line change
    @@ -65,6 +65,7 @@ platform :ios do
    desc "Deployment iOs lane"

    lane :deployAppetizeFeature do

    githubStatusUpdate(
    context: 'Appetize iOs',
    state: 'pending',
    @@ -111,6 +112,7 @@ platform :ios do
    end

    error do |lane, exception|

    case lane
    when /deployAppetizeFeature/
    githubStatusUpdate(
    @@ -128,6 +130,7 @@ platform :android do
    desc "Deployment Android lane"

    lane :deployAppetizeFeature do

    githubStatusUpdate(
    context: 'Appetize Android',
    state: 'pending',
    @@ -158,6 +161,7 @@ platform :android do
    end

    error do |lane, exception|

    case lane
    when /deployAppetizeFeature/
    githubStatusUpdate(
  3. Kenny Dits @kenny_dee revised this gist Jun 17, 2016. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions Fastfile
    Original file line number Diff line number Diff line change
    @@ -166,11 +166,6 @@ platform :android do
    url: "https://appetize.io/dashboard",
    description: 'Android build failed'
    )
    when /deployHockeyAppFeature/
    slack(
    message: exception.message,
    success: false
    )
    end
    end
    end
  4. Kenny Dits @kenny_dee created this gist Jun 17, 2016.
    176 changes: 176 additions & 0 deletions Fastfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,176 @@
    require 'httparty'

    fastlane_version "1.95.0"
    default_platform :ios

    before_all do
    # put here your token and iOs scheme app
    ENV["GITHUB_TOKEN"] = "---"
    ENV["APPETIZE_TOKEN"] = "---"
    ENV["APP_IOS_SCHEME"] = "---"

    ENV["GIT_COMMIT"] = last_git_commit[:commit_hash]

    # Use ghprbSourceBranch env variable on CI, git_branch actions elsewhere
    if !ENV["ghprbSourceBranch"]
    ENV["ghprbSourceBranch"] = git_branch
    end

    end

    # Update git status on the current commit.
    private_lane :githubStatusUpdate do |options|

    response = HTTParty.post(
    "https://<yourgithubenterprisedomain.tld>/api/v3/repos/<orga>/<repos>/statuses/#{ENV["GIT_COMMIT"]}?access_token=#{ENV["GITHUB_TOKEN"]}",
    :body => {
    :context => options[:context],
    :state => options[:state],
    :description => options[:description],
    :target_url => options[:url]
    }.to_json,
    :headers => { 'Content-Type' => 'application/json' }
    )
    end

    # get the publicKey of the appetizeApp corresponding to your git branch
    private_lane :getAppetizePublicKey do |options|
    publicKey = ""

    response = HTTParty.get("https://#{ENV["APPETIZE_TOKEN"]}@api.appetize.io/v1/apps")
    json = JSON.parse(response.body)

    # Find branch name in notes
    json["data"].each do |value|
    if value["note"] == ENV["ghprbSourceBranch"] && value["platform"] == options[:platform]
    publicKey = value["publicKey"]
    end
    end

    publicKey
    end

    # find the path of the last apk build
    private_lane :getLastAPKPath do
    apk_search_path = File.join('../android/', 'app', 'build', 'outputs', 'apk', '*.apk')
    new_apks = Dir[apk_search_path].reject { |path| path =~ /^.*-unaligned.apk$/i}
    new_apks = new_apks.map { |path| File.expand_path(path)}
    last_apk_path = new_apks.sort_by(&File.method(:mtime)).last

    last_apk_path
    end

    platform :ios do

    desc "Deployment iOs lane"

    lane :deployAppetizeFeature do
    githubStatusUpdate(
    context: 'Appetize iOs',
    state: 'pending',
    url: "https://appetize.io/dashboard",
    description: 'iOs build in progress'
    )

    Dir.chdir "../ios" do
    tmp_path = "/tmp/fastlane_build"

    #seems not possible tu use gym here because is only made to do ipa archive
    xcodebuild_configs = {
    configuration: "Release",
    sdk: "iphonesimulator",
    derivedDataPath: tmp_path,
    xcargs: "CONFIGURATION_BUILD_DIR=" + tmp_path,
    scheme: "#{ENV["APP_IOS_SCHEME"]}"
    }

    Actions::XcodebuildAction.run(xcodebuild_configs)

    app_path = Dir[File.join(tmp_path, "**", "*.app")].last

    zipped_bundle = Actions::ZipAction.run(path: app_path, output_path: File.join(tmp_path, "Result.zip"))

    Actions::AppetizeAction.run(
    path: zipped_bundle,
    api_token: "#{ENV["APPETIZE_TOKEN"]}",
    platform: "ios",
    note: "#{ENV["ghprbSourceBranch"]}",
    public_key: getAppetizePublicKey({platform: "ios"})
    )

    FileUtils.rm_rf(tmp_path)

    end

    githubStatusUpdate(
    context: 'Appetize iOs',
    state: 'success',
    url: "#{lane_context[SharedValues::APPETIZE_APP_URL]}",
    description: 'iOs build succeed'
    )
    end

    error do |lane, exception|
    case lane
    when /deployAppetizeFeature/
    githubStatusUpdate(
    context: 'Appetize iOs',
    state: 'failure',
    url: "https://appetize.io/dashboard",
    description: 'iOs build failed'
    )
    end
    end
    end

    platform :android do

    desc "Deployment Android lane"

    lane :deployAppetizeFeature do
    githubStatusUpdate(
    context: 'Appetize Android',
    state: 'pending',
    url: "https://appetize.io/dashboard",
    description: 'Android build in progress'
    )

    gradle(
    task: "assemble",
    build_type: "Release",
    project_dir: "android/"
    )

    Actions::AppetizeAction.run(
    path: getLastAPKPath,
    api_token: "#{ENV["APPETIZE_TOKEN"]}",
    platform: "android",
    note: "#{ENV["ghprbSourceBranch"]}",
    public_key: getAppetizePublicKey({platform: "android"})
    )

    githubStatusUpdate(
    context: 'Appetize Android',
    state: 'success',
    url: "#{lane_context[SharedValues::APPETIZE_APP_URL]}",
    description: 'Android build succeed'
    )
    end

    error do |lane, exception|
    case lane
    when /deployAppetizeFeature/
    githubStatusUpdate(
    context: 'Appetize Android',
    state: 'failure',
    url: "https://appetize.io/dashboard",
    description: 'Android build failed'
    )
    when /deployHockeyAppFeature/
    slack(
    message: exception.message,
    success: false
    )
    end
    end
    end