cem_win_spec 0.1.19 → 0.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/cem-win-spec +2 -2
- data/lib/cem_win_spec/test_runner.rb +96 -1
- data/lib/cem_win_spec/version.rb +1 -1
- data/lib/cem_win_spec/win_exec/cmd/base_cmd.rb +23 -5
- data/lib/cem_win_spec.rb +22 -17
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: efd3d9ac13844df9283ce7419eea9b8610bd6be5cf847d476e901013184e6766
|
|
4
|
+
data.tar.gz: 3ce28460af05c2ed44125fc1b6b3546e29ac16dd6ac48e2b89a61c09d85adc7d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e27a9e63a5b75da679c1708bddcb34593bb4e4995fe94d009261652fa63ac5a0117988aa4568ab2d2d55cce40e42c1960a72255c8c858abbf18e377765e9c36
|
|
7
|
+
data.tar.gz: 3f344fe737234a8c2fb4b6eb4fc4f09393c6cd6d6f90322df5abdc1fbdafa64d1c53842cc09318d515c76fc2255a06d6dbe92b2a95f515e7a3f07da57231b543
|
data/exe/cem-win-spec
CHANGED
|
@@ -39,8 +39,8 @@ parser = OptionParser.new do |opts|
|
|
|
39
39
|
options[:ruby_version] = version
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
opts.on('-o', '--operation [OPERATION]', 'Operation to perform (spec, clean_fixture_cache)') do |operation|
|
|
43
|
-
unless %w[spec clean_fixture_cache].include?(operation)
|
|
42
|
+
opts.on('-o', '--operation [OPERATION]', 'Operation to perform (spec, install_ruby, clean_fixture_cache)') do |operation|
|
|
43
|
+
unless %w[spec install_ruby clean_fixture_cache].include?(operation)
|
|
44
44
|
warn "Unknown operation: #{operation}"
|
|
45
45
|
puts opts
|
|
46
46
|
exit 1
|
|
@@ -79,7 +79,102 @@ module CemWinSpec
|
|
|
79
79
|
]
|
|
80
80
|
if installer_url
|
|
81
81
|
installer_filename = File.basename(installer_url)
|
|
82
|
-
cmds <<
|
|
82
|
+
cmds << <<~PWSH
|
|
83
|
+
if (-not (Test-Path "$rubyBin")) {
|
|
84
|
+
$ErrorActionPreference = 'Stop'
|
|
85
|
+
try {
|
|
86
|
+
& {
|
|
87
|
+
$ErrorActionPreference = 'Continue'
|
|
88
|
+
Get-Process -Name 'rubyinstaller-*' -ErrorAction SilentlyContinue | ForEach-Object {
|
|
89
|
+
Write-Host "===== install_ruby: killing lingering process $($_.Name) (PID $($_.Id)) and children ====="
|
|
90
|
+
& taskkill.exe /F /T /PID $_.Id 2>&1 | Out-Null
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
Start-Sleep -Seconds 2
|
|
94
|
+
$tmp = "$env:TEMP\\rubyinstaller-#{ruby_ver}.download"
|
|
95
|
+
$inst = "$env:TEMP\\#{installer_filename}"
|
|
96
|
+
$log = "$env:TEMP\\rubyinstaller-#{ruby_ver}.log"
|
|
97
|
+
if (Test-Path $tmp) { Remove-Item $tmp -Force }
|
|
98
|
+
if (Test-Path $inst) { Remove-Item $inst -Force }
|
|
99
|
+
$downloaded = $false
|
|
100
|
+
if (Get-Command curl.exe -ErrorAction SilentlyContinue) {
|
|
101
|
+
Write-Host "===== install_ruby: downloading via curl.exe -> $tmp ====="
|
|
102
|
+
curl.exe -sSL --retry 3 --max-time 300 -o $tmp '#{installer_url}'
|
|
103
|
+
if ($LASTEXITCODE -eq 0) {
|
|
104
|
+
$downloaded = $true
|
|
105
|
+
} else {
|
|
106
|
+
Write-Host "===== install_ruby: curl.exe failed (exit $LASTEXITCODE), falling back to Invoke-WebRequest ====="
|
|
107
|
+
if (Test-Path $tmp) { Remove-Item $tmp -Force }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (-not $downloaded) {
|
|
111
|
+
Write-Host "===== install_ruby: downloading via Invoke-WebRequest -> $tmp ====="
|
|
112
|
+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
113
|
+
Invoke-WebRequest -Uri '#{installer_url}' -OutFile $tmp -UseBasicParsing -TimeoutSec 300
|
|
114
|
+
}
|
|
115
|
+
if (Test-Path $log) { Remove-Item $log -Force }
|
|
116
|
+
Move-Item $tmp $inst -Force
|
|
117
|
+
Write-Host "===== install_ruby: download complete ($((Get-Item $inst).Length) bytes) ====="
|
|
118
|
+
|
|
119
|
+
# WinRM sessions run with a UAC-filtered token even for local
|
|
120
|
+
# admins, so a silent installer that requires admin hangs
|
|
121
|
+
# invisibly on the UAC consent dialog. Run the installer via a
|
|
122
|
+
# scheduled task as SYSTEM to bypass UAC entirely.
|
|
123
|
+
$taskName = 'CemInstallRuby'
|
|
124
|
+
& {
|
|
125
|
+
$ErrorActionPreference = 'Continue'
|
|
126
|
+
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
|
|
127
|
+
}
|
|
128
|
+
$installArgs = '/verysilent /suppressmsgboxes /dir=#{tool_dir} /tasks="" /norestart /log="' + $log + '"'
|
|
129
|
+
Write-Host "===== install_ruby: registering scheduled task '$taskName' as SYSTEM ====="
|
|
130
|
+
Write-Host " Execute: $inst"
|
|
131
|
+
Write-Host " Argument: $installArgs"
|
|
132
|
+
$action = New-ScheduledTaskAction -Execute $inst -Argument $installArgs
|
|
133
|
+
$principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest
|
|
134
|
+
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -ExecutionTimeLimit (New-TimeSpan -Minutes 15)
|
|
135
|
+
Register-ScheduledTask -TaskName $taskName -Action $action -Principal $principal -Settings $settings -Force | Out-Null
|
|
136
|
+
|
|
137
|
+
Write-Host "===== install_ruby: starting task (600s wall-clock timeout, log: $log) ====="
|
|
138
|
+
Start-ScheduledTask -TaskName $taskName
|
|
139
|
+
$deadline = (Get-Date).AddSeconds(600)
|
|
140
|
+
$state = 'Running'
|
|
141
|
+
while ($state -eq 'Running' -and (Get-Date) -lt $deadline) {
|
|
142
|
+
Start-Sleep -Seconds 5
|
|
143
|
+
$state = (Get-ScheduledTask -TaskName $taskName).State
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if ($state -eq 'Running') {
|
|
147
|
+
Write-Host "===== install_ruby: TIMEOUT after 600s — stopping task and reaping installer ====="
|
|
148
|
+
& {
|
|
149
|
+
$ErrorActionPreference = 'Continue'
|
|
150
|
+
Stop-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue | Out-Null
|
|
151
|
+
Get-Process -Name 'rubyinstaller-*' -ErrorAction SilentlyContinue | ForEach-Object {
|
|
152
|
+
& taskkill.exe /F /T /PID $_.Id 2>&1 | Out-Null
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (Test-Path $log) { Write-Host "----- log tail ($log):"; Get-Content $log -Tail 100 | Out-Host } else { Write-Host " (log file $log does not exist)" }
|
|
156
|
+
& { $ErrorActionPreference = 'Continue'; Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue | Out-Null }
|
|
157
|
+
throw "Ruby installer timed out after 600s"
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
$exitCode = (Get-ScheduledTaskInfo -TaskName $taskName).LastTaskResult
|
|
161
|
+
Write-Host "===== install_ruby: task finished (state=$state, LastTaskResult=$exitCode) ====="
|
|
162
|
+
& { $ErrorActionPreference = 'Continue'; Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue | Out-Null }
|
|
163
|
+
if ($exitCode -ne 0) {
|
|
164
|
+
if (Test-Path $log) { Write-Host "----- log:"; Get-Content $log | Out-Host } else { Write-Host " (log file $log does not exist)" }
|
|
165
|
+
throw "Ruby installer failed with LastTaskResult=$exitCode"
|
|
166
|
+
}
|
|
167
|
+
Remove-Item $inst -Force
|
|
168
|
+
} catch {
|
|
169
|
+
Write-Host "===== install_ruby: FATAL — $_ ====="
|
|
170
|
+
exit 1
|
|
171
|
+
} finally {
|
|
172
|
+
$ErrorActionPreference = 'Continue'
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
Write-Host "===== install_ruby: Ruby already present at $rubyBin — skipping ====="
|
|
176
|
+
}
|
|
177
|
+
PWSH
|
|
83
178
|
end
|
|
84
179
|
cmds << "if ($uList -notmatch '#{ruby_ver}') { uru admin add \"$rubyBin\" }"
|
|
85
180
|
|
data/lib/cem_win_spec/version.rb
CHANGED
|
@@ -49,6 +49,20 @@ module CemWinSpec
|
|
|
49
49
|
@puppet_version = ver
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
FORWARDED_ENV_VARS = %w[
|
|
53
|
+
FORGE_API_KEY
|
|
54
|
+
SCE_COVERAGE
|
|
55
|
+
COVERAGE
|
|
56
|
+
PUPPET_AUTH_TOKEN
|
|
57
|
+
].freeze
|
|
58
|
+
|
|
59
|
+
REDACTED_ENV_VARS = %w[
|
|
60
|
+
password
|
|
61
|
+
FORGE_API_KEY
|
|
62
|
+
PUPPET_AUTH_TOKEN
|
|
63
|
+
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM
|
|
64
|
+
].freeze
|
|
65
|
+
|
|
52
66
|
# Sets the environment variables that will be used to execute the command
|
|
53
67
|
# @param value [Hash] the environment variables
|
|
54
68
|
def env_vars=(value)
|
|
@@ -56,9 +70,10 @@ module CemWinSpec
|
|
|
56
70
|
|
|
57
71
|
value['PUPPET_GEM_VERSION'] = "~> #{puppet_version}" if puppet_version
|
|
58
72
|
value['FACTER_GEM_VERSION'] = 'https://github.com/puppetlabs/facter#main' if puppet_version
|
|
59
|
-
value[
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
FORWARDED_ENV_VARS.each { |k| value[k] = ENV[k] if ENV[k] }
|
|
74
|
+
if ENV['PUPPET_AUTH_TOKEN'] && !ENV['BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM']
|
|
75
|
+
value['BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM'] = "forge-key:#{ENV['PUPPET_AUTH_TOKEN']}"
|
|
76
|
+
end
|
|
62
77
|
value.delete('password') if value.key?('password')
|
|
63
78
|
@env_vars = value
|
|
64
79
|
end
|
|
@@ -111,8 +126,11 @@ module CemWinSpec
|
|
|
111
126
|
private
|
|
112
127
|
|
|
113
128
|
def log_command(cmd)
|
|
114
|
-
|
|
115
|
-
|
|
129
|
+
redacted = cmd.dup
|
|
130
|
+
REDACTED_ENV_VARS.each do |key|
|
|
131
|
+
redacted.gsub!(/\$env:#{Regexp.escape(key)} = "[^"]+"/, %($env:#{key} = [REDACTED]))
|
|
132
|
+
end
|
|
133
|
+
logger.debug "Executing command:\n#{redacted.split(%r{\n|\r\n|;\s*}).map { |c| " #> #{c}" }.join("\n")}"
|
|
116
134
|
end
|
|
117
135
|
|
|
118
136
|
# Commands that, when ran, will change the ruby version. This will also set the local bundle config path
|
data/lib/cem_win_spec.rb
CHANGED
|
@@ -48,25 +48,30 @@ module CemWinSpec
|
|
|
48
48
|
logger.debug 'Set up signal handler'
|
|
49
49
|
working_dir = nil
|
|
50
50
|
begin
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
logger.debug "Working dir: #{working_dir}"
|
|
54
|
-
install_ruby(runner, **options)
|
|
55
|
-
upload_out = upload_module(runner, working_dir)
|
|
56
|
-
module_dir = upload_out.stdout.chomp
|
|
57
|
-
logger.debug "Module dir: #{module_dir}"
|
|
58
|
-
setup_remote_ruby(runner, module_dir, **options)
|
|
59
|
-
case operation
|
|
60
|
-
when :spec
|
|
61
|
-
run_spec(runner, module_dir, **options)
|
|
62
|
-
# We set this to 0 if the tests pass because this can be set to 1 earlier by commands that fail and retry.
|
|
63
|
-
self.exit_code = 0
|
|
64
|
-
when :clean_fixture_cache
|
|
65
|
-
clean_fixture_cache(runner, module_dir, **options)
|
|
66
|
-
# We set this to 0 if the tests pass because this can be set to 1 earlier by commands that fail and retry.
|
|
51
|
+
if operation == :install_ruby
|
|
52
|
+
install_ruby(runner, **options)
|
|
67
53
|
self.exit_code = 0
|
|
68
54
|
else
|
|
69
|
-
|
|
55
|
+
sre_out = setup_remote_environment(runner)
|
|
56
|
+
working_dir = sre_out.stdout.chomp
|
|
57
|
+
logger.debug "Working dir: #{working_dir}"
|
|
58
|
+
install_ruby(runner, **options)
|
|
59
|
+
upload_out = upload_module(runner, working_dir)
|
|
60
|
+
module_dir = upload_out.stdout.chomp
|
|
61
|
+
logger.debug "Module dir: #{module_dir}"
|
|
62
|
+
setup_remote_ruby(runner, module_dir, **options)
|
|
63
|
+
case operation
|
|
64
|
+
when :spec
|
|
65
|
+
run_spec(runner, module_dir, **options)
|
|
66
|
+
# We set this to 0 if the tests pass because this can be set to 1 earlier by commands that fail and retry.
|
|
67
|
+
self.exit_code = 0
|
|
68
|
+
when :clean_fixture_cache
|
|
69
|
+
clean_fixture_cache(runner, module_dir, **options)
|
|
70
|
+
# We set this to 0 if the tests pass because this can be set to 1 earlier by commands that fail and retry.
|
|
71
|
+
self.exit_code = 0
|
|
72
|
+
else
|
|
73
|
+
raise ArgumentError, "Unknown operation: #{operation}"
|
|
74
|
+
end
|
|
70
75
|
end
|
|
71
76
|
rescue StandardError => e
|
|
72
77
|
if operation == :spec && runner.retry?
|