Class: Fastlane::Actions::Unity3dAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



90
91
92
# File 'lib/fastlane/plugin/unity3d/actions/unity3d_action.rb', line 90

def self.authors
  ["fuzhongqing"]
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/unity3d/actions/unity3d_action.rb', line 103

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :executable,
                                 env_name: "FL_UNITY_EXECUTABLE",
                                 description: "Path for Unity executable",
                                 optional: true,
                                 default_value: Helper::Unity3dHelper.default_exe_path),

    FastlaneCore::ConfigItem.new(key: :project_path,
                                 env_name: "FL_UNITY_PROJECT_PATH",
                                 description: "Path for Unity project",
                                 optional: true,
                                 default_value: "#{Dir.pwd}"),

    FastlaneCore::ConfigItem.new(key: :execute_method,
                                 env_name: "FL_UNITY_EXECUTE_METHOD",
                                 description: "Method to execute",
                                 optional: true,
                                 default_value: nil),

    FastlaneCore::ConfigItem.new(key: :build_type,
                                 env_name: "FL_UNITY_BUILD_TYPE",
                                 description: "`Debug` or `Release`",
                                 optional: true,
                                 default_value: "Release"),

    FastlaneCore::ConfigItem.new(key: :nographics,
                                 env_name: "FL_UNITY_NOGRAPHICS",
                                 description: "Initialize graphics device or not",
                                 optional: true,
                                 is_string: false,
                                 default_value: true),

    FastlaneCore::ConfigItem.new(key: :logfile,
                                 env_name: "FL_UNITY_LOGFILE",
                                 description: "log file",
                                 optional: true,
                                 is_string: true,
                                 default_value: ""),

    FastlaneCore::ConfigItem.new(key: :skip_building,
                                 env_name: "FL_UNITY_SKIP_BUILDING",
                                 description: "Need skip building",
                                 optional: true,
                                 is_string: false,
                                 default_value: false),

    FastlaneCore::ConfigItem.new(key: :build_target,
                                 env_name: "FL_UNITY_BUILD_TARGET",
                                 description: "build target:  Possible options are: Standalone, Win, Win64, OSXUniversal, Linux64, iOS, Android, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, tvOS",
                                 optional: true,
                                 is_string: true,
                                 default_value: "Standalone"),
  ]
end

.categoryObject



167
168
169
# File 'lib/fastlane/plugin/unity3d/actions/unity3d_action.rb', line 167

def self.category
  :building
end

.descriptionObject



86
87
88
# File 'lib/fastlane/plugin/unity3d/actions/unity3d_action.rb', line 86

def self.description
  "fastlane plugin for unity3d engine"
end

.detailsObject



98
99
100
101
# File 'lib/fastlane/plugin/unity3d/actions/unity3d_action.rb', line 98

def self.details
  # Optional:
  "fastlane for unity3d engine"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


159
160
161
162
163
164
165
# File 'lib/fastlane/plugin/unity3d/actions/unity3d_action.rb', line 159

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.return_valueObject



94
95
96
# File 'lib/fastlane/plugin/unity3d/actions/unity3d_action.rb', line 94

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fastlane/plugin/unity3d/actions/unity3d_action.rb', line 20

def self.run(params)

  UI.error "no executable found" unless params[:executable]

  build_cmd = "#{params[:executable]}"
  build_cmd << " -projectPath '#{params[:project_path]}'"
  build_cmd << " -batchmode"
  build_cmd << " -quit"
  build_cmd << " -logfile #{params[:logfile]}"
  build_cmd << " -nographics" if params[:nographics]
  build_cmd << " -executeMethod #{params[:execute_method]}" if params[:execute_method]
  build_cmd << " -buildTarget #{params[:build_target]}" if params[:build_target]

  UI.message "\n#{
    Terminal::Table.new(
      title: "Unity".green,
      headings: ["Option", "Value"],
      rows: params.values
  )}\n"


  UI.message "Start running"

  sh build_cmd unless params[:skip_building]

  if File.exist?('.build_summary.json') then
    summary = Helper::BuildSummary.new(JSON.parse(File.read('.build_summary.json')))

    UI.message "\n#{
      Terminal::Table.new(
        title: "build summary".green,
        headings: ["Key", "Value"],
        rows: summary.kv
    )}\n"

    UI.error "build faild, check logfile" unless summary.success?

    Actions.lane_context[SharedValues::UNITY3D_BUILD_STARTED_AT] = summary.kv['buildStartedAt']
    Actions.lane_context[SharedValues::UNITY3D_PLATFORM] = summary.kv['platform']
    Actions.lane_context[SharedValues::UNITY3D_OPTIONS] = summary.kv['options']
    Actions.lane_context[SharedValues::UNITY3D_OUTPUT_PATH] = summary.kv['outputPath']
    Actions.lane_context[SharedValues::UNITY3D_TOTAL_SIZE] = summary.kv['totalSize']
    Actions.lane_context[SharedValues::UNITY3D_TOTAL_TIME] = summary.kv['totalTime']
    Actions.lane_context[SharedValues::UNITY3D_BUILD_ENDED_AT] = summary.kv['buildEndedAt']
    Actions.lane_context[SharedValues::UNITY3D_TOTAL_ERRORS] = summary.kv['totalErrors']
    Actions.lane_context[SharedValues::UNITY3D_TOTAL_TOTAL_WARNINGS] = summary.kv['totalWarnings']

    if summary.is_android? then
      build_script_file = Dir[File.join(summary.build_path, '*', 'build.gradle')].find { |path| File.exist?(path) }
      if build_script_file then
        # if export mode
        sh "gradle -p \'#{File.dirname(build_script_file)}\' wrapper"
        ENV["FL_GRADLE_PROJECT_DIR"] = File.dirname(build_script_file)
      end
    end

  else
    UI.message "file `build_summary.json` not found"
  end

end