fastlane-plugin-unity_exporter 1.0.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
+ SHA256:
3
+ metadata.gz: 5d8f86fa27fb63a03a99dcc669832ad4ef700f9548e36ef2e1fc797fc54aa689
4
+ data.tar.gz: '029e648522051179dab3010516cd34920b0aa22934e66f49722cc000162fd494'
5
+ SHA512:
6
+ metadata.gz: 0ea2e1fe2623d7ca96fe35fe766c530601fba3e176ffa4f9da385edb1d0d6a3dde03b8b0c1fc5b5f0414745d346bf391a3e97c4f3c9fbfd10c9e384bd4a9f2a5
7
+ data.tar.gz: f0a4509e13da5329766ca8d5a34ea56126e04bec7fa8171cafa3bcc396f5a1907885bb2744d99b3dae3afaab6ba9b7c27fc634748d10f0a0549785c947212063
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 ar:met
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,156 @@
1
+ # unity_exporter plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-unity_exporter)
4
+
5
+
6
+ ## Getting Started
7
+
8
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-unity_exporter`, add it to your project by running:
9
+
10
+ ```bash
11
+ fastlane add_plugin unity_exporter
12
+ ```
13
+
14
+
15
+ ## About unity_exporter
16
+
17
+ Plugin for _fastlane_ that defines an action to export iOS and Android projects via [_Unity3d_](https://unity.com/). This allows _Unity3d_ to more easily integrate with _fastlane_.
18
+
19
+ This action works by invoking _Unity3d_ via commandline to trigger an export of your _Unity3d_ project. [Per default _Unity3d_ supports a number of different commandline arguments.](https://docs.unity3d.com/Manual/CommandLineArguments.html) Therefore there are two ways to use the plugin: Either provide your own full list of commandline arguments or let the _fastlane plugin_ help you with some of it. This becomes clearer when looking at all [available actions](#actions).
20
+
21
+ For convenience and easier versioning, there also exists the [_Unity Build Exporter_](https://github.com/ar-met/unity-build-exporter) which can be added via the [_Unity Package Manager_](https://docs.unity3d.com/Manual/Packages.html). The _Unity Build Exporter_ provides a custom execute method that parses custom commandline arguments. See [_Unity Build Exporter_](https://github.com/ar-met/unity-build-exporter) for a more in-depth explanation of the package.
22
+
23
+ To make full use of the *unity_exporter* make sure to:
24
+ * Install the [_Unity Hub_](https://docs.unity3d.com/Manual/GettingStartedInstallingHub.html) at its default path: We use the _Unity Hub_ to get the paths of your _Unity Editor_ installations, such that we can use the _Unity Editor_ version that matches the version used by your _Unity3d_ project when exporting a build.
25
+ * Add the [_Unity Build Exporter_](https://github.com/ar-met/unity-build-exporter) to your _Unity3d_ project: We invoke a specific `executeMethod` ([see docs](https://docs.unity3d.com/Manual/CommandLineArguments.html) and the [readme of the package](https://github.com/ar-met/unity-build-exporter/blob/master/Assets/BuildExporter/README.md) what's that about) provided by the package to handle versioning. Note that the package also exposes a new menu item to your _Unity3d_ project that helps with setting up _fastlane_ and the *fastlane-plugin-unity_exporter*.
26
+
27
+
28
+ ## Getting Started with a blank _Unity3d_ project
29
+
30
+ Assuming you don't have _fastlane_ configured yet, we propose the following:
31
+ 1) Add the [_Unity Build Exporter_](https://github.com/ar-met/unity-build-exporter) via the [_Unity Package Manager_](https://docs.unity3d.com/Manual/Packages.html) to your _Unity3d_ project
32
+ 2) Open your _Unity3d_ project and find the menu items `Build Exporter / Initialize 'fastlane' directories for Android` and `Build Exporter / Initialize 'fastlane' directories for iOS`
33
+ 3) Commit the changes to your repository
34
+ 4) Navigate to `{Unity3d-project-root}/fastlane-build-exporter/iOS` and `{Unity3d-project-root}/fastlane-build-exporter/Android` and `fastlane init` respectively
35
+ 5) Commit the changes to your repository
36
+ 6) See [Getting Started](#getting-started)
37
+ 7) Use [the actions of the plugin](#actions)
38
+
39
+ We suggest you also check out the [_example Unity3d project_](https://github.com/ar-met/fastlane-plugin-unity-exporter-example-project).
40
+
41
+
42
+ ## Actions
43
+
44
+ Two actions are provided by this plugin:
45
+ * `fastlane action unity_export`
46
+ * `fastlane action unity_commit_version_bump`
47
+
48
+ ### Using `unity_export` with parameter `arguments`
49
+
50
+ Note that when writing `{path-to-unity}` we expect a path like so:
51
+ * Mac: `/Applications/Unity/Hub/Editor/<version>/Unity.app/Contents/MacOS/Unity`
52
+ * Windows: `"C:\Program Files\Unity\Hub\Editor\<version>\Editor\Unity.exe"`
53
+ * Linux: [see open issue](https://github.com/ar-met/fastlane-plugin-unity-exporter/issues/1)
54
+
55
+ ```ruby
56
+ # for a full list of commandline arguments that are available to Unity see https://docs.unity3d.com/Manual/CommandLineArguments.html
57
+ # uses the Unity Hub to resolve the path to a Unity Editor installation
58
+ unity_export(arguments: "-batchmode -nographics -quit")
59
+
60
+ # setting 'use_default_path' to 'false', will not resolve the path to a Unity Editor installation via the Unity Hub
61
+ # a path to a Unity Editor installation is expected as part of 'arguments'
62
+ unity_export(arguments: "{path-to-unity} -batchmode -nographics -quit", use_default_paths: false)
63
+ ```
64
+
65
+ ### Using `unity_export` with parameter `build_target`
66
+
67
+ ```ruby
68
+ # will export a Xcode project
69
+ unity_export(build_target: "iOS")
70
+
71
+ # will export an Android project ('Export Project' is ticked, see https://docs.unity3d.com/Manual/android-BuildProcess.html)
72
+ unity_export(build_target: "Android")
73
+
74
+ # expects a semantic version and sets this version as the new Unity3d project version
75
+ # for semantic versioning see https://semver.org/
76
+ unity_export(build_target: "...", new_version: "1.2.3")
77
+
78
+ # increments the major, minor or patch part of the existing semantic version
79
+ unity_export(build_target: "...", new_version: "major")
80
+ unity_export(build_target: "...", new_version: "minor")
81
+ unity_export(build_target: "...", new_version: "patch")
82
+
83
+ # note that the plugin will keep the version code in sync across different platforms: version code (Android) and build number (iOS) will be the same
84
+ # expects a non-negative number and sets it as version code
85
+ unity_export(build_target: "...", new_version_code: "42")
86
+
87
+ # increments the existing version code (Android) and build number (iOS)
88
+ unity_export(build_target: "...", new_version_code: "increment")
89
+
90
+ # combined usage of 'new_version' and 'new_version_code'
91
+ unity_export(build_target: "...", new_version: "2.3.4", new_version_code: "0")
92
+ ```
93
+
94
+ ### Using `unity_commit_version_bump`
95
+
96
+ Uses [shell commands to commit a version bump](https://github.com/ar-met/fastlane-plugin-unity-exporter/blob/master/lib/fastlane/plugin/unity_exporter/actions/unity_commit_version_bump.rb), if there is any.
97
+
98
+ ```ruby
99
+ # let's say we first export the Unity3d project
100
+ unity_export(build_target: "...", new_version: "3.4.5", new_version_code: "0")
101
+
102
+ # after the export is finished, we commit the version bump
103
+ unity_commit_version_bump
104
+ ```
105
+
106
+
107
+ ## Compatibility
108
+
109
+ Both this _fastlane plugin_ and the [_Unity Build Exporter_](https://github.com/ar-met/unity-build-exporter) were developed with _Unity 2020.3.13f1_. We haven't tested the plugin with any earlier versions, but we don't expect there to be any issues. If you run into trouble, regarding compatibility or anything else, [please open an issue](https://github.com/ar-met/unity-build-exporter/issues). For pull requests [see here](#pull-requests).
110
+
111
+
112
+ ## Example
113
+
114
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
115
+
116
+ Also check out the example [_Unity3d_ project](https://github.com/ar-met/fastlane-plugin-unity-exporter-example-project) to see how this plugin works. See the repositories readme for more details.
117
+
118
+
119
+ ## Pull requests
120
+
121
+ We are happy to accept [pull requests](https://github.com/ar-met/unity-build-exporter/pulls). For easier development of this plugin, we suggest you use the provided [_Unity3d_ project](https://github.com/ar-met/fastlane-plugin-unity-exporter-dev-project).
122
+
123
+
124
+ ## Run tests for this plugin
125
+
126
+ To run both the tests, and code style validation, run
127
+
128
+ ```
129
+ rake
130
+ ```
131
+
132
+ To automatically fix many of the styling issues, use
133
+ ```
134
+ rubocop -a
135
+ ```
136
+
137
+
138
+ ## Issues and Feedback
139
+
140
+ For any other issues and feedback about this plugin, please submit it to this repository.
141
+
142
+
143
+ ## Troubleshooting
144
+
145
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
146
+
147
+
148
+ ## Using _fastlane_ Plugins
149
+
150
+
151
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
152
+
153
+
154
+ ## About _fastlane_
155
+
156
+ _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/unity_exporter/version'
2
+
3
+ module Fastlane
4
+ module UnityExporter
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::UnityExporter.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,46 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/unity_editor_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class UnityCommitVersionBumpAction < Action
7
+ def self.run(params)
8
+ # TODO: improve the commit command: currently it simply commits the ProjectSettings file
9
+ # what if there are other changes in the file and you don't want these changes to be part of the commit
10
+
11
+ log_file = "unity-export-logs/#{DateTime.now.strftime('%Y-%m-%d_%H-%M-%S-%L')}_git.log"
12
+
13
+ # Thank you: https://linuxize.com/post/bash-redirect-stderr-stdout/#redirecting-stderr-to-stdout
14
+ sh("echo 'UnityCommitVersionBumpAction: created file' > #{log_file} 2>&1")
15
+ sh("git add '#{Helper::UnityEditorHelper.unity_project_path_relative_to_fastfile}ProjectSettings/ProjectSettings.asset' >> #{log_file} 2>&1")
16
+ sh("git commit -m 'Version Bump' >> #{log_file} 2>&1")
17
+ end
18
+
19
+ def self.description
20
+ "Commits a version bump, if there is any."
21
+ end
22
+
23
+ def self.authors
24
+ ["steft"]
25
+ end
26
+
27
+ def self.return_value
28
+ # If your method provides a return value, you can describe here what it does
29
+ end
30
+
31
+ def self.details
32
+ # Optional:
33
+ end
34
+
35
+ def self.available_options
36
+ end
37
+
38
+ def self.is_supported?(platform)
39
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
40
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
41
+ [:ios, :android].include?(platform)
42
+ true
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,174 @@
1
+ require 'fastlane/action'
2
+ require 'fastlane_core/configuration/config_item'
3
+ require_relative '../helper/unity_editor_helper'
4
+ require_relative '../helper/unity_hub_helper'
5
+
6
+ module Fastlane
7
+ module Actions
8
+ class UnityExportAction < Action
9
+ def self.run(params)
10
+ if params[:arguments]
11
+ if params[:use_default_paths]
12
+ invoke_unity(arguments: " #{params[:arguments]}")
13
+ else
14
+ # path to Unity is provided as part of 'arguments'
15
+ UI.important("Expecting path to Unity as part of 'arguments'.")
16
+ sh(params[:arguments])
17
+ end
18
+
19
+ elsif params[:build_target]
20
+ # following are arguments as defined in the docs: https://docs.unity3d.com/Manual/CommandLineArguments.html
21
+ headless_args = "-buildTarget #{params[:build_target]}"
22
+ headless_args << " -batchmode -nographics -quit" # some arguments that are required when running Unity in headless-mode
23
+ headless_args << " -accept-apiupdate -releaseCodeOptimization"
24
+ headless_args << " -projectPath #{Helper::UnityEditorHelper.unity_project_path_relative_to_fastfile}"
25
+ headless_args << " -logFile unity-export-logs/#{DateTime.now.strftime('%Y-%m-%d_%H-%M-%S-%L')}_#{params[:build_target]}_build.log" # logging; not specifying a path will print the log to the console
26
+
27
+ # following are custom arguments defined in 'UnityExporter.BuildUtility'
28
+ # this script is part of the 'fastlane-plugin-unity-exporter-package'
29
+ headless_args << " -executeMethod armet.BuildExporter.BuildUtility.CreateBuild"
30
+ headless_args << " -newVersion #{params[:new_version]}" if params[:new_version]
31
+ headless_args << " -newVersionCode #{params[:new_version_code]}" if params[:new_version_code]
32
+ headless_args << " -exportPath fastlane-build-exporter/#{params[:build_target]}/unity-export"
33
+
34
+ # NOTE: the different relative paths used in 'projectPath' and 'exportPath'
35
+ # while 'projectPath' is relative to the 'fastfile',
36
+ # 'exportPath' is relative to 'projectPath' aka the Unity project's root directory
37
+
38
+ invoke_unity(arguments: headless_args)
39
+
40
+ else
41
+ UI.user_error!("Either provide a 'build_target' or 'arguments'.") if !params[:build_target] && !params[:arguments]
42
+
43
+ end
44
+ end
45
+
46
+ def self.invoke_unity(params)
47
+ unless params[:arguments]
48
+ UI.error("'arguments' required")
49
+ return
50
+ end
51
+
52
+ unless Helper::UnityHubHelper.verify_default_path
53
+ return
54
+ end
55
+
56
+ unless Helper::UnityEditorHelper.verify_exporter_package
57
+ return
58
+ end
59
+
60
+ unity_path = Helper::UnityEditorHelper.unity_editor_path
61
+ if unity_path == ""
62
+ return
63
+ end
64
+
65
+ UI.message("Open 'logFile', if you want to know whats going on with your build.")
66
+ invocation = unity_path.to_s
67
+ invocation << " #{params[:arguments]}"
68
+ sh(invocation) # 'sh' will print what's passed to it
69
+ end
70
+
71
+ def self.description
72
+ "Exports a Unity project."
73
+ end
74
+
75
+ def self.authors
76
+ ["steft"]
77
+ end
78
+
79
+ def self.return_value
80
+ # If your method provides a return value, you can describe here what it does
81
+ end
82
+
83
+ def self.details
84
+ # Optional:
85
+ "Plugin for 'fastlane' that defines a pre-processing action to export iOS and Android projects via Unity3D. This allows Unity3D to more easily integrate with 'fastlane'."
86
+ end
87
+
88
+ def self.available_options
89
+ [
90
+ #
91
+ # How to start Unity via commandline?
92
+ # Want a full list of all of Unity's commandline arguments?
93
+ # See here: https://docs.unity3d.com/Manual/CommandLineArguments.html
94
+ #
95
+
96
+ FastlaneCore::ConfigItem.new(key: :arguments,
97
+ env_name: "FL_UNITY_ARGUMENTS",
98
+ description: "Use the 'arguments' parameter, if you want to specify all headless arguments yourself. See Unity docs regarding 'CommandLineArguments' for a all available arguments",
99
+ optional: true,
100
+ type: String,
101
+ conflicting_options: [:build_target]),
102
+
103
+ FastlaneCore::ConfigItem.new(key: :use_default_paths,
104
+ env_name: "FL_UNITY_USE_DEFAULT_PATHS",
105
+ description: "'true': Plugin expects Unity default paths. 'false': Custom path is provided as part of the 'arguments' parameter",
106
+ optional: true,
107
+ default_value: true,
108
+ conflicting_options: [:build_target],
109
+ verify_block: proc do |value|
110
+ unless value == true || value == false
111
+ UI.user_error!("Must be set to 'true' or 'false'.")
112
+ end
113
+ end),
114
+
115
+ FastlaneCore::ConfigItem.new(key: :build_target,
116
+ env_name: "FL_UNITY_BUILD_TARGET",
117
+ description: "The build target. Options: 'iOS' and/or 'Android' depending on your platform",
118
+ optional: true,
119
+ type: String,
120
+ conflicting_options: [:arguments],
121
+ verify_block: proc do |value|
122
+ # For now we only support iOS and Android as these platforms are supported by fastlane as well.
123
+ # TODO add support for other platforms that are also supported by both fastlane and Unity
124
+ # TODO verify if Unity's commandline param 'buildTarget' is case-sensitive
125
+ if FastlaneCore::Helper.is_mac?
126
+ unless value == "iOS" || value == "Android"
127
+ UI.user_error!("Please pass a valid build target. Mac options: 'iOS', 'Android'")
128
+ end
129
+ elsif FastlaneCore::Helper.is_windows?
130
+ unless value == "Android"
131
+ UI.user_error!("Please pass a valid build target. Windows options: 'Android'")
132
+ end
133
+ end
134
+ end),
135
+
136
+ FastlaneCore::ConfigItem.new(key: :new_version,
137
+ env_name: "FL_UNITY_NEW_VERSION",
138
+ description: "The new version. Options: 'major', 'minor', 'patch' (for bumping) and '{major}.{minor}.{patch}' (new semantic version to apply)",
139
+ optional: true,
140
+ type: String,
141
+ conflicting_options: [:arguments],
142
+ verify_block: proc do |value|
143
+ unless value == "major" || value == "minor" || value == "patch" || Gem::Version.new(value).correct?
144
+ UI.user_error!("Please pass a valid version. For options see 'fastlane action unity_exporter'")
145
+ end
146
+ end),
147
+
148
+ FastlaneCore::ConfigItem.new(key: :new_version_code,
149
+ env_name: "FL_UNITY_NEW_VERSION_CODE",
150
+ description: "The new version code. Options: 'increment' (for incrementing the current code), '{unsigned integer}' (new code to apply)",
151
+ optional: true,
152
+ type: String,
153
+ conflicting_options: [:arguments],
154
+ verify_block: proc do |value|
155
+ unless value == "increment"
156
+ # Thank you: https://stackoverflow.com/a/24980633
157
+ num = value.to_i
158
+ if num.to_s != value || num < 0
159
+ UI.user_error!("Please pass a valid version code. For options see 'fastlane action unity_exporter'")
160
+ end
161
+ end
162
+ end)
163
+ ]
164
+ end
165
+
166
+ def self.is_supported?(platform)
167
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
168
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
169
+ [:ios, :android].include?(platform)
170
+ true
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,24 @@
1
+ require 'fastlane_core/ui/ui'
2
+ require 'shellwords'
3
+
4
+ module Fastlane
5
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
6
+
7
+ module Helper
8
+ class GenericHelper
9
+ def self.shellify(path)
10
+ if FastlaneCore::Helper.is_mac?
11
+ return Shellwords.escape(path)
12
+
13
+ elsif FastlaneCore::Helper.is_windows?
14
+ return "\"#{path}\""
15
+
16
+ elsif FastlaneCore::Helper.linux?
17
+ # TODO
18
+ UI.error("Not implemented yet")
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,111 @@
1
+ require 'fastlane_core/ui/ui'
2
+ require 'shellwords'
3
+ require_relative './unity_hub_helper'
4
+ require_relative './generic_helper'
5
+
6
+ module Fastlane
7
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
8
+
9
+ module Helper
10
+ class UnityEditorHelper
11
+ def self.unity_project_path_relative_to_fastfile
12
+ # project path relative if following hierarchy is given: "root/{unity-project}/fastlane-build-exporter/{platform}-export/."
13
+ # p File.expand_path("../../")
14
+ return "../../"
15
+ end
16
+
17
+ def self.unity_editor_path
18
+ unity_binary_path = find_best_unity_editor_version
19
+ return Helper::GenericHelper.shellify(unity_binary_path)
20
+ end
21
+
22
+ def self.find_best_unity_editor_version
23
+ installed_editors = Helper::UnityHubHelper.unity_hub_installed_editors
24
+
25
+ unity_project_version = load_unity_project_version
26
+ UI.important("Unity project uses version '#{unity_project_version}'")
27
+
28
+ if installed_editors.key?(unity_project_version)
29
+ UI.important("'#{unity_project_version}' is installed!")
30
+ return installed_editors[unity_project_version][2]
31
+ end
32
+
33
+ fallback_editor_version = find_closest_unity_version(unity_project_version, installed_editors.keys)
34
+ if fallback_editor_version == ""
35
+ # TODO: offer to install appropriate editor via Hub?
36
+ UI.user_error!("'#{unity_project_version}' not installed. No appropriate fallback found. Please install ‘#{unity_project_version}‘ or the latest '#{unity_project_version_no_patch}' manually via the Unity Hub.")
37
+ return ""
38
+ end
39
+
40
+ UI.important("'#{unity_project_version}' not installed. Using '#{fallback_editor_version}' instead.")
41
+ return installed_editors[fallback_editor_version][2]
42
+ end
43
+
44
+ def self.verify_exporter_package
45
+ # verifies that the UnityExporter package has been added to the Unity project
46
+ # TODO Unity currently does not support commandline arguments for the Package Manager
47
+ exporter_package_namespace = "io.armet.unity.buildexporter"
48
+ included = load_unity_project_package_manifest.include?(exporter_package_namespace)
49
+ unless included
50
+ UI.user_error!("Package 'io.armet.unity.exporter' must be added to the Unity project.")
51
+ end
52
+
53
+ return included
54
+ end
55
+
56
+ def self.load_unity_project_package_manifest
57
+ relative_path = if FastlaneCore::Helper.is_test?
58
+ "/tmp/fastlane/tests/fixtures/unity_project"
59
+ else
60
+ unity_project_path_relative_to_fastfile
61
+ end
62
+
63
+ package_manifest_path = "#{relative_path}/Packages/manifest.json"
64
+ package_manifest_json = File.read(package_manifest_path)
65
+ return package_manifest_json
66
+ end
67
+
68
+ def self.load_unity_project_version
69
+ relative_path = if FastlaneCore::Helper.is_test?
70
+ "/tmp/fastlane/tests/fixtures/unity_project"
71
+ else
72
+ unity_project_path_relative_to_fastfile
73
+ end
74
+
75
+ project_version_txt_path = "#{relative_path}/ProjectSettings/ProjectVersion.txt"
76
+ project_version_txt = File.read(project_version_txt_path)
77
+ project_version_match = project_version_txt.scan(/.*: (\d+\.\d+\.\d+[abf]\d+).*/)
78
+ project_version = project_version_match[0][0]
79
+ return project_version
80
+ end
81
+
82
+ def self.find_closest_unity_version(unity_version, other_versions)
83
+ # finds closest version by ignoring "patch"
84
+ closest_version = ""
85
+ version_no_patch_regex = /\d+\.\d+/
86
+ unity_project_version_no_patch = unity_version.match(version_no_patch_regex)[0]
87
+ other_versions_sorted = sort_unity_versions(other_versions)
88
+
89
+ other_versions_sorted_no_patch = other_versions_sorted.map do |other_version|
90
+ m = other_version.match(version_no_patch_regex)
91
+ if m.length > 0
92
+ m[0]
93
+ end
94
+ end
95
+
96
+ other_versions_sorted_no_patch.each_with_index do |other_version_no_patch, index|
97
+ if other_version_no_patch == unity_project_version_no_patch
98
+ # since the list is sorted, we keep going to match the highest available path version
99
+ closest_version = other_versions_sorted[index]
100
+ end
101
+ end
102
+
103
+ return closest_version
104
+ end
105
+
106
+ def self.sort_unity_versions(unity_versions)
107
+ return unity_versions.sort_by { |v| Gem::Version.new(v) }
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,95 @@
1
+ require 'fastlane_core/ui/ui'
2
+ require_relative './generic_helper'
3
+
4
+ module Fastlane
5
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
6
+
7
+ module Helper
8
+ class UnityHubHelper
9
+ def self.unity_hub_path(escape_for_shell)
10
+ # https://docs.unity3d.com/Manual/GettingStartedInstallingHub.html
11
+ hub_path = ""
12
+
13
+ if FastlaneCore::Helper.is_mac?
14
+ hub_path = "/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
15
+ elsif FastlaneCore::Helper.is_windows?
16
+ hub_path = "C:\\Program Files\\Unity Hub\\Unity Hub.exe"
17
+ elsif FastlaneCore::Helper.linux?
18
+ # TODO
19
+ UI.error("Not implemented yet")
20
+ end
21
+
22
+ if escape_for_shell
23
+ return Helper::GenericHelper.shellify(hub_path)
24
+ else
25
+ return hub_path
26
+ end
27
+ end
28
+
29
+ def self.verify_default_path
30
+ # verifies that the Unity Hub exists at the default path
31
+ exists = File.file?(Helper::UnityHubHelper.unity_hub_path(false)) == true
32
+ unless exists
33
+ UI.error("Unity Hub does not exist at path '#{Helper::UnityHubHelper.unity_hub_path(false)}'")
34
+ end
35
+
36
+ return exists
37
+ end
38
+
39
+ def self.unity_hub_installed_editors
40
+ UI.message("Looking for installed Unity Editors known to the Unity Hub...")
41
+
42
+ # Unity Hub help: "./Unity\ Hub -- --headless help"
43
+ installed_editors_result = `#{unity_hub_path(true)} -- --headless editors -i`
44
+ installed_editors_list = parse_installed_editors(installed_editors_result)
45
+ installed_editors = installed_editors_list.collect do |installed_editor|
46
+ [installed_editor[0],
47
+ [
48
+ installed_editor[0],
49
+ installed_editor[1],
50
+ unity_binary_relative_to_path(installed_editor[2])
51
+ ]]
52
+ end.to_h
53
+
54
+ UI.message("Found Unity Editors: #{installed_editors.keys}")
55
+ return installed_editors
56
+ end
57
+
58
+ def self.parse_installed_editors(installed_editors_string)
59
+ installed_editors_list = []
60
+ installed_editors_string.split("\n").each do |editor_description|
61
+ next if editor_description == "" # skipping empty strings
62
+
63
+ # Mac: "2019.4.18f1 , installed at /Applications/Unity/Hub/Editor/2019.4.18f1/Unity.app"
64
+ # Windows: "2019.4.18f1 , installed at C:\Program Files\Unity\Hub\Editor\2019.4.18f1\Editor\Unity.exe"
65
+ # Linux: ?? TODO
66
+ editor_match = editor_description.scan(/((\d+\.\d+\.\d+)[abf]\d+).*installed at (.*)/)
67
+ installed_editors_list.append(
68
+ [
69
+ editor_match[0][0], # the Unity version
70
+ editor_match[0][1], # the semantic version part of the Unity version
71
+ editor_match[0][2] # the path to the Unity Editor
72
+ ]
73
+ )
74
+ end
75
+ return installed_editors_list
76
+ end
77
+
78
+ def self.unity_binary_relative_to_path(unity_path)
79
+ # https://docs.unity3d.com/Manual/GettingStartedInstallingHub.html#install
80
+
81
+ if FastlaneCore::Helper.is_mac?
82
+ # Mac example: "/Applications/Unity/Hub/Editor/<version>/Unity.app"
83
+ return "#{unity_path}/Contents/MacOS/Unity"
84
+ elsif FastlaneCore::Helper.is_windows?
85
+ # Windows example: "C:\Program Files\Unity\Hub\Editor\<version>\Editor\Unity.exe"
86
+ # path can be taken as is
87
+ return unity_path
88
+ elsif FastlaneCore::Helper.linux?
89
+ # Linux example: ?? TODO
90
+ UI.error("Not implemented yet")
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module UnityExporter
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-unity_exporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ar:met
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
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: fastlane
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.187.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.187.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
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: rake
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: rspec
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: rspec_junit_formatter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.12.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.12.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
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: rubocop-require_tools
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description:
154
+ email: office@armet.at
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - LICENSE
160
+ - README.md
161
+ - lib/fastlane/plugin/unity_exporter.rb
162
+ - lib/fastlane/plugin/unity_exporter/actions/unity_commit_version_bump.rb
163
+ - lib/fastlane/plugin/unity_exporter/actions/unity_export.rb
164
+ - lib/fastlane/plugin/unity_exporter/helper/generic_helper.rb
165
+ - lib/fastlane/plugin/unity_exporter/helper/unity_editor_helper.rb
166
+ - lib/fastlane/plugin/unity_exporter/helper/unity_hub_helper.rb
167
+ - lib/fastlane/plugin/unity_exporter/version.rb
168
+ homepage: https://github.com/ar-met/fastlane-plugin-unity-exporter
169
+ licenses:
170
+ - MIT
171
+ metadata: {}
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '2.5'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubygems_version: 3.1.6
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: Plugin for 'fastlane' that defines an action to export iOS and Android projects
191
+ via Unity3d. This allows Unity3d to more easily integrate with 'fastlane'.
192
+ test_files: []