diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e8ecca2..64e406d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,14 +6,14 @@ jobs: fail-fast: false matrix: os: [ ubuntu, macos, windows ] - ruby: [ 2.5.9, 2.6.10, 2.7.6, 3.0.4, 3.1.2 ] + ruby: [ 2.6, 2.7, 3.0.7, 3.1, 3.2, 3.3 ] # somehow github uses ruby 3.3 when specifying 3.0 runs-on: ${{ matrix.os }}-latest steps: - name: git config autocrlf run: git config --global core.autocrlf false if: matrix.os == 'windows' - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} diff --git a/.rubocop.yml b/.rubocop.yml index 7fced7b5..e9caea3c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -70,3 +70,7 @@ Lint/AmbiguousBlockAssociation: Lint/EmptyBlock: Enabled: false + +Gemspec/DevelopmentDependencies: + EnforcedStyle: gemspec + Include: [ "Gemfile", "u3d.gemspec" ] \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index abc4fa6e..e1a4cf85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,9 +110,10 @@ GEM octokit (4.22.0) faraday (>= 0.9) sawyer (~> 0.8.0, >= 0.5.3) - parallel (1.22.1) - parser (3.1.2.0) + parallel (1.24.0) + parser (3.3.5.0) ast (~> 2.4.1) + racc plist (3.7.1) protocol-hpack (1.4.2) protocol-http (0.22.6) @@ -122,9 +123,10 @@ GEM protocol-hpack (~> 1.4) protocol-http (~> 0.18) public_suffix (4.0.7) + racc (1.8.1) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.4.0) + regexp_parser (2.9.2) rexml (3.2.5) rspec (3.11.0) rspec-core (~> 3.11.0) @@ -141,20 +143,21 @@ GEM rspec-support (3.11.0) rspec_junit_formatter (0.5.1) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (1.28.2) + rubocop (1.50.2) + json (~> 2.3) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.17.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.17.0) - parser (>= 3.1.1.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) rubyzip (2.3.2) sawyer (0.8.2) @@ -176,7 +179,7 @@ GEM traces (0.4.1) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - unicode-display_width (2.1.0) + unicode-display_width (2.6.0) zeitwerk (2.5.4) PLATFORMS @@ -193,7 +196,7 @@ DEPENDENCIES rake (>= 12.3.3) rspec (~> 3.11.0) rspec_junit_formatter (~> 0.5.1) - rubocop (~> 1.27) + rubocop (~> 1.50) rubocop-rake (~> 0.6.0) u3d! diff --git a/lib/u3d/cache.rb b/lib/u3d/cache.rb index 2d6f79ce..35c8c2aa 100644 --- a/lib/u3d/cache.rb +++ b/lib/u3d/cache.rb @@ -104,9 +104,9 @@ def check_for_update(file_path, os) end def os_data_need_update?(data, os) - data[os.id2name].nil?\ - || data[os.id2name]['lastupdate'].nil?\ - || (Time.now.to_i - data[os.id2name]['lastupdate'] > CACHE_LIFE)\ + data[os.id2name].nil? \ + || data[os.id2name]['lastupdate'].nil? \ + || (Time.now.to_i - data[os.id2name]['lastupdate'] > CACHE_LIFE) \ || (data[os.id2name]['versions'] || []).empty? end diff --git a/lib/u3d/downloader.rb b/lib/u3d/downloader.rb index d74b9695..2055859b 100644 --- a/lib/u3d/downloader.rb +++ b/lib/u3d/downloader.rb @@ -31,7 +31,7 @@ module Downloader # Name of the directory for the package downloading DOWNLOAD_DIRECTORY = 'Unity_Packages' # Path to the directory for the package downloading - DOWNLOAD_PATH = "#{ENV['HOME']}/Downloads" + DOWNLOAD_PATH = "#{Dir.home}/Downloads" # Regex to get the name of a localization asset UNITY_LANGUAGE_FILE_REGEX = %r{/\d+/[0-9.]+/([\w-]+)$}.freeze # Regex to get the name of a package out of its file name diff --git a/lib/u3d/installation.rb b/lib/u3d/installation.rb index 2e440913..bfe874f3 100644 --- a/lib/u3d/installation.rb +++ b/lib/u3d/installation.rb @@ -180,7 +180,7 @@ def build_number end def default_log_file - "#{ENV['HOME']}/Library/Logs/Unity/Editor.log" + "#{Dir.home}/Library/Logs/Unity/Editor.log" end def exe_path @@ -293,7 +293,7 @@ def build_number end def default_log_file - "#{ENV['HOME']}/.config/unity3d/Editor.log" + "#{Dir.home}/.config/unity3d/Editor.log" end def exe_path diff --git a/lib/u3d/installer.rb b/lib/u3d/installer.rb index 0f2dd1f0..640f622a 100644 --- a/lib/u3d/installer.rb +++ b/lib/u3d/installer.rb @@ -424,7 +424,7 @@ def pkg_install_path(unity_root_path, pinfo_path) install_location = d.root.attributes['install-location'] raise "Not sure how to install this module with identifier #{identifier} install-location: #{install_location}" unless install_location.start_with? '/Applications/Unity/' - install_location.gsub(%(\/Applications\/Unity), "#{unity_root_path}/Editor/Data") + install_location.gsub(%(/Applications/Unity), "#{unity_root_path}/Editor/Data") end end diff --git a/lib/u3d/unity_license.rb b/lib/u3d/unity_license.rb index f297a657..67d456f5 100644 --- a/lib/u3d/unity_license.rb +++ b/lib/u3d/unity_license.rb @@ -40,13 +40,13 @@ def [](index) # petit cachotier va! def number require 'base64' - Base64.decode64(self['DeveloperData'])[4..-1] + Base64.decode64(self['DeveloperData'])[4..] end class << self LICENSES_DIR_MAC = File.join("/", "Library", "Application Support", "Unity").freeze LICENSES_DIR_WINDOWS = File.join("C:/ProgramData", "Unity").freeze - LICENSES_DIR_LINUX = File.join(ENV['HOME'], ".local", "share", "unity3d", "Unity").freeze + LICENSES_DIR_LINUX = File.join(Dir.home, ".local", "share", "unity3d", "Unity").freeze def from_path(path) doc = REXML::Document.new(File.read(path)) diff --git a/lib/u3d/unity_module.rb b/lib/u3d/unity_module.rb index b11b4003..39a1c2b4 100644 --- a/lib/u3d/unity_module.rb +++ b/lib/u3d/unity_module.rb @@ -75,21 +75,19 @@ def load_modules(version, cached_versions, os: U3dCore::Helper.operating_system, # Optimized version of load_version_modules that only makes one HTTP call def load_versions_modules(versions, cached_versions, os, offline) - ini_modules = versions - .map { |version| [version, INIModulesParser.load_ini(version, cached_versions, os: os, offline: offline)] } - .map do |version, ini_data| + ini_modules = versions.to_h do |version| + ini_data = INIModulesParser.load_ini(version, cached_versions, os: os, offline: offline) url_root = cached_versions[version] modules = ini_data.map { |k, v| module_from_ini_data(k, v, url_root, os) } [version, modules] - end.to_h + end HubModulesParser.download_modules(os: os) unless offline - hub_modules = versions - .map { |version| [version, HubModulesParser.load_modules(version, os: os, offline: true)] } - .map do |version, json_data| + hub_modules = versions.to_h do |version| + json_data = HubModulesParser.load_modules(version, os: os, offline: true) modules = json_data.map { |data| module_from_json_data(data, os) } [version, modules] - end.to_h + end return ini_modules.merge(hub_modules) do |_version, ini_version_modules, json_version_modules| (ini_version_modules + json_version_modules).uniq(&:id) diff --git a/lib/u3d/unity_versions.rb b/lib/u3d/unity_versions.rb index 15b8ab88..486c16df 100644 --- a/lib/u3d/unity_versions.rb +++ b/lib/u3d/unity_versions.rb @@ -181,9 +181,9 @@ def fetch_json(url, pattern) end def fetch_from_json(url, pattern) - fetch_json(url, pattern).map do |build| + fetch_json(url, pattern).to_h do |build| [build['version'], pattern.match(build['downloadUrl'])[1]] - end.to_h + end end def fetch_betas(url, pattern) diff --git a/lib/u3d/utils.rb b/lib/u3d/utils.rb index cff66208..c854bf18 100644 --- a/lib/u3d/utils.rb +++ b/lib/u3d/utils.rb @@ -38,6 +38,7 @@ module Utils 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0' }.freeze + # rubocop:disable Metrics/ClassLength class << self def final_url(url, redirect_limit: 10) follow_redirects(url, redirect_limit: redirect_limit, http_method: :head) do |request, _response| @@ -212,7 +213,7 @@ def print_progress_nosize(current, started_at) def parse_unity_version(version) ver = UNITY_VERSION_REGEX.match(version) if ver.nil? - raise ArgumentError, "Version (#{version}) does not match the Unity "\ + raise ArgumentError, "Version (#{version}) does not match the Unity " \ 'version format 0.0.0x0' end [ver[1], ver[2], ver[3], ver[4], ver[5]] @@ -346,6 +347,7 @@ def http_opts(opt = {}) opt end end + # rubocop:enable Metrics/ClassLength end # rubocop:enable Metrics/ModuleLength end diff --git a/lib/u3d/version.rb b/lib/u3d/version.rb index 69b8511a..ace9a5d3 100644 --- a/lib/u3d/version.rb +++ b/lib/u3d/version.rb @@ -25,9 +25,9 @@ module U3d VERSION = '1.3.4' DESCRIPTION = 'Provides numerous tools for installing, managing and running the Unity game engine from command line.' - UNITY_VERSIONS_NOTE = "Unity uses the following version formatting: 0.0.0x0. The \'x\' can takes different values:\n"\ - "\t. 'f' are the main release candidates for Unity\n"\ - "\t. 'p' are patches fixing those releases\n"\ - "\t. 'b' are the beta releases\n"\ + UNITY_VERSIONS_NOTE = "Unity uses the following version formatting: 0.0.0x0. The 'x' can takes different values:\n" \ + "\t. 'f' are the main release candidates for Unity\n" \ + "\t. 'p' are patches fixing those releases\n" \ + "\t. 'b' are the beta releases\n" \ "\t. 'a' are the alpha releases (not currently discovered)\n" end diff --git a/lib/u3d_core/command_executor.rb b/lib/u3d_core/command_executor.rb index 245d9ac7..d9de6dec 100644 --- a/lib/u3d_core/command_executor.rb +++ b/lib/u3d_core/command_executor.rb @@ -149,12 +149,12 @@ def has_admin_privileges?(retry_count: 2) def grant_admin_privileges(command) if Helper.windows? - raise CredentialsError, "The command \'#{command}\' must be run in administrative shell" unless has_admin_privileges? + raise CredentialsError, "The command '#{command}' must be run in administrative shell" unless has_admin_privileges? else env_username = ENV['USER'] unless env_username == "root" cred = U3dCore::Credentials.new(user: env_username) - raise CredentialsError, "The command \'#{command}\' must be run with admin privileges" unless has_admin_privileges? + raise CredentialsError, "The command '#{command}' must be run with admin privileges" unless has_admin_privileges? command = "sudo -k && echo #{cred.password.shellescape} | sudo -S bash -c \"#{command}\"" end diff --git a/lib/u3d_core/helper.rb b/lib/u3d_core/helper.rb index 7a1553a7..e09b4e5c 100644 --- a/lib/u3d_core/helper.rb +++ b/lib/u3d_core/helper.rb @@ -28,9 +28,9 @@ module U3dCore module Helper - DEFAULT_LINUX_PATH = File.join(ENV['HOME'], '.u3d').freeze - DEFAULT_MAC_PATH = File.join(ENV['HOME'], 'Library', 'Application Support', 'u3d').freeze - DEFAULT_WINDOWS_PATH = File.join(ENV['HOME'], 'AppData', 'Local', 'u3d').freeze + DEFAULT_LINUX_PATH = File.join(Dir.home, '.u3d').freeze + DEFAULT_MAC_PATH = File.join(Dir.home, 'Library', 'Application Support', 'u3d').freeze + DEFAULT_WINDOWS_PATH = File.join(Dir.home, 'AppData', 'Local', 'u3d').freeze def self.data_path case operating_system @@ -115,7 +115,6 @@ def self.operating_systems # the current operating system def self.operating_system - # rubocop:disable Style/GuardClause if linux? return :linux elsif mac? @@ -125,7 +124,6 @@ def self.operating_system else raise 'Could not assume what OS you\'re running, please specify it as much as possible' end - # rubocop:enable Style/GuardClause end def self.win_64? diff --git a/lib/u3d_core/update_checker/changelog.rb b/lib/u3d_core/update_checker/changelog.rb index 03e5fc32..7deac6e3 100644 --- a/lib/u3d_core/update_checker/changelog.rb +++ b/lib/u3d_core/update_checker/changelog.rb @@ -54,7 +54,7 @@ def show_changes(gem_name, current_version, update_gem_command: "bundle update") end def to_version(tag_name) - tag_name = tag_name[1..-1] if tag_name[0] == 'v' + tag_name = tag_name[1..] if tag_name[0] == 'v' tag_name end diff --git a/spec/u3d/cache_spec.rb b/spec/u3d/cache_spec.rb index f7832fca..5ff919c4 100644 --- a/spec/u3d/cache_spec.rb +++ b/spec/u3d/cache_spec.rb @@ -68,10 +68,10 @@ it 'checks if the file is up-to-date' do allow(U3d::UnityVersions).to receive(:list_available) { { 'test' => 'url' } } file = double('file') - cache = '{'\ - '"win":{"lastupdate":0,"versions":{"version": "url"}},'\ - '"mac":{"lastupdate":0,"versions":{"version": "url"}},'\ - '"linux":{"lastupdate":0,"versions":{"version": "url"}}'\ + cache = '{' \ + '"win":{"lastupdate":0,"versions":{"version": "url"}},' \ + '"mac":{"lastupdate":0,"versions":{"version": "url"}},' \ + '"linux":{"lastupdate":0,"versions":{"version": "url"}}' \ '}' allow(File).to receive(:file?) { true } allow(File).to receive(:open).with(anything, 'r').and_yield(file) @@ -85,10 +85,10 @@ context 'when cache file is outdated' do before(:each) do file = double('file') - cache = '{'\ - '"win":{"lastupdate":0,"versions":{"version": "url"}},'\ - '"mac":{"lastupdate":0,"versions":{"version": "url"}},'\ - '"linux":{"lastupdate":0,"versions":{"version": "url"}}'\ + cache = '{' \ + '"win":{"lastupdate":0,"versions":{"version": "url"}},' \ + '"mac":{"lastupdate":0,"versions":{"version": "url"}},' \ + '"linux":{"lastupdate":0,"versions":{"version": "url"}}' \ '}' allow(File).to receive(:file?) { true } allow(File).to receive(:open).with(anything, 'r').and_yield(file) @@ -115,10 +115,10 @@ context 'when cache file is fresh' do before(:each) do file = double('file') - cache = '{'\ - '"win":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"version": "url"}},'\ - '"mac":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"version": "url"}},'\ - '"linux":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"version": "url"}}'\ + cache = '{' \ + '"win":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"version": "url"}},' \ + '"mac":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"version": "url"}},' \ + '"linux":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"version": "url"}}' \ '}' allow(File).to receive(:file?) { true } allow(File).to receive(:open).with(anything, 'r').and_yield(file) @@ -151,10 +151,10 @@ before(:each) do allow(U3d::UnityVersions).to receive(:list_available) file = double('file') - cache_data = '{'\ - '"win":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"key": "url"}},'\ - '"mac":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"key": "url"}},'\ - '"linux":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"key": "url"}}'\ + cache_data = '{' \ + '"win":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"key": "url"}},' \ + '"mac":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"key": "url"}},' \ + '"linux":{"lastupdate":' + Time.now.to_i.to_s + ',"versions":{"key": "url"}}' \ '}' allow(File).to receive(:file?) { true } allow(File).to receive(:open).with(anything, 'r').and_yield(file) diff --git a/spec/u3d/downloader_spec.rb b/spec/u3d/downloader_spec.rb index 1fc59739..d8415297 100644 --- a/spec/u3d/downloader_spec.rb +++ b/spec/u3d/downloader_spec.rb @@ -409,7 +409,7 @@ 'unity', definition ) - ).to eql File.expand_path(File.join(ENV['HOME'], 'Downloads', 'Unity_Packages', '1.2.3f4', 'unity-editor-installer-1.2.3f4+20160628.sh')) + ).to eql File.expand_path(File.join(Dir.home, 'Downloads', 'Unity_Packages', '1.2.3f4', 'unity-editor-installer-1.2.3f4+20160628.sh')) end end @@ -469,7 +469,7 @@ 'package', definition ) - ).to eql File.expand_path(File.join(ENV['HOME'], 'Downloads', 'Unity_Packages', '1.2.3f4', 'Unity.pkg')) + ).to eql File.expand_path(File.join(Dir.home, 'Downloads', 'Unity_Packages', '1.2.3f4', 'Unity.pkg')) end end @@ -526,7 +526,7 @@ 'package', definition ) - ).to eql File.expand_path(File.join(ENV['HOME'], 'Downloads', 'Unity_Packages', '1.2.3f4', 'UnitySetup64.exe')) + ).to eql File.expand_path(File.join(Dir.home, 'Downloads', 'Unity_Packages', '1.2.3f4', 'UnitySetup64.exe')) end end diff --git a/spec/u3d/utils_spec.rb b/spec/u3d/utils_spec.rb index 8cbb56d0..1b372ff8 100644 --- a/spec/u3d/utils_spec.rb +++ b/spec/u3d/utils_spec.rb @@ -71,7 +71,7 @@ describe '.windows_local_appdata' do it 'runs windows_local_appdata without failure on windows', if: WINDOWS do if ENV['GITHUB_ACTION'] - expected = "#{ENV['HOME'].tr('\\', '/')}/AppData/Local" + expected = "#{Dir.home.tr('\\', '/')}/AppData/Local" expect(U3d::Utils.windows_local_appdata).to eql(expected) else puts U3d::Utils.windows_local_appdata diff --git a/u3d.gemspec b/u3d.gemspec index 119463fc..276ceb39 100644 --- a/u3d.gemspec +++ b/u3d.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |spec| spec.authors = ["Jerome Lacoste", "Paul Niezborala"] spec.email = 'jerome@wewanttoknow.com' - spec.required_ruby_version = '>= 2.5.0' + spec.required_ruby_version = '>= 2.6.0' spec.summary = "U3d" spec.description = U3d::DESCRIPTION @@ -47,7 +47,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rake", ">= 12.3.3" spec.add_development_dependency "rspec", "~> 3.11.0" spec.add_development_dependency 'rspec_junit_formatter', '~> 0.5.1' - spec.add_development_dependency 'rubocop', '~> 1.27' + spec.add_development_dependency 'rubocop', '~> 1.50' # for ruby 2.6 compatibility spec.add_development_dependency 'rubocop-rake', '~> 0.6.0' # spec.add_development_dependency 'rubocop-rspec', '~> 2.10.0' spec.metadata['rubygems_mfa_required'] = 'true'