Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop ruby 2.5, support 3.2 and 3.3. Adjust dependencies, improve rubocop support and adjust CI on github. #445

Merged
merged 10 commits into from
Oct 29, 2024
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ Lint/AmbiguousBlockAssociation:

Lint/EmptyBlock:
Enabled: false

Gemspec/DevelopmentDependencies:
EnforcedStyle: gemspec
Include: [ "Gemfile", "u3d.gemspec" ]
29 changes: 16 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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!

Expand Down
6 changes: 3 additions & 3 deletions lib/u3d/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/u3d/downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/u3d/installation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/u3d/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/u3d/unity_license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 6 additions & 8 deletions lib/u3d/unity_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/u3d/unity_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion lib/u3d/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -346,6 +347,7 @@ def http_opts(opt = {})
opt
end
end
# rubocop:enable Metrics/ClassLength
end
# rubocop:enable Metrics/ModuleLength
end
8 changes: 4 additions & 4 deletions lib/u3d/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/u3d_core/command_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions lib/u3d_core/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/u3d_core/update_checker/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 16 additions & 16 deletions spec/u3d/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions spec/u3d/downloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/u3d/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading