Skip to content

Commit b07baab

Browse files
committed
vagrantfile adjustments-
1 parent e9d34e6 commit b07baab

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

tests/Vagrantfile

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# -*- mode: ruby -*-
22
# vi: set ft=ruby :
33

4+
# Setup a global variable to be consistent about xcopy arguments.
5+
$xcopyArgs = '/s /q /exclude:c:\\chocoroot\\.xcopyignore /i /y /h'
6+
7+
$memory = ENV['VM_MEMORY'] ? ENV['VM_MEMORY'].to_i : 4096
8+
$cpus = ENV['VM_CPU'] ? ENV['VM_CPU'].to_i : 2
9+
410
Vagrant.configure("2") do |config|
511
config.vm.box = "chocolatey/test-environment"
612
# Set Hostname to prevent error messages. https://github.com/hashicorp/vagrant/issues/12644
@@ -20,27 +26,32 @@ Vagrant.configure("2") do |config|
2026
config.winrm.retry_limit = 30
2127
config.winrm.retry_delay = 10
2228

23-
config.vm.network :forwarded_port, guest: 5985, host: 14985, id: 'winrm', auto_correct: true
24-
config.vm.network :forwarded_port, guest: 3389, host: 14389, id: 'rdp', auto_correct: true
25-
2629
config.vm.provider "virtualbox" do |vb|
2730
vb.gui = ENV['VM_GUI'] ? ENV['VM_GUI'].to_s.downcase == 'true' : true
28-
vb.memory = ENV['VM_MEMORY'] ? ENV['VM_MEMORY'].to_i : 4096
29-
vb.cpus = ENV['VM_CPU'] ? ENV['VM_CPU'].to_i : 2
31+
vb.memory = $memory
32+
vb.cpus = $cpus
3033
vb.linked_clone = true
3134
vb.customize ['modifyvm', :id, '--vram', '128']
3235
end
3336
config.vm.provider "hyperv" do |h|
34-
h.memory = ENV['VM_MEMORY'] ? ENV['VM_MEMORY'].to_i : 4096
35-
h.maxmemory = nil
36-
h.cpus = ENV['VM_CPU'] ? ENV['VM_CPU'].to_i : 2
37+
# Use Dynamic memory.
38+
h.maxmemory = $memory
39+
h.cpus = $cpus
3740
h.linked_clone = true
3841
h.enable_checkpoints = false
3942
end
4043

41-
config.vm.synced_folder '../', '/chocoRoot'
4244

43-
config.vm.provision "shell", name: "prep", inline: <<-SHELL
45+
# Disable the default vagrant share as we don't need it.
46+
config.vm.synced_folder '.', '/vagrant', disabled: true
47+
# Allow passing in the username/password through environment variables.
48+
if ENV['VM_SMB_USERNAME'].nil? || ENV['VM_SMB_PASSWORD'].nil?
49+
config.vm.synced_folder '../', '/chocoRoot'
50+
else
51+
config.vm.synced_folder '../', '/chocoRoot', type: "smb", smb_username: ENV['VM_SMB_USERNAME'], smb_password: ENV['VM_SMB_PASSWORD']
52+
end
53+
54+
config.vm.provision "shell", name: "prep", inline: <<-PREP
4455
cscript c:/windows/system32/slmgr.vbs /rearm | Out-Null
4556
Set-ExecutionPolicy Bypass -Scope Process -Force
4657
iex (irm https://community.chocolatey.org/install.ps1)
@@ -49,42 +60,48 @@ Vagrant.configure("2") do |config|
4960
choco install git pester visualstudio2022community visualstudio2022-workload-manageddesktop netfx-4.8-devpack -y --no-progress
5061
Import-Module $env:ChocolateyInstall/helpers/chocolateyProfile.psm1
5162
Update-SessionEnvironment
52-
Write-Host "($(Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss K")) Done installing software, now copying files"
53-
# If you try to build on macOS, then run this, there are attributes on some files that cause the build to fail inside of the vagrant environment.
54-
xcopy c:\\chocoroot\\* c:\\code\\choco /s /f /exclude:c:\\chocoroot\\.xcopyignore /i /y /h
55-
SHELL
56-
config.vm.provision "shell", name: "build", inline: <<-SHELL
57-
xcopy c:\\chocoroot\\* c:\\code\\choco /s /f /exclude:c:\\chocoroot\\.xcopyignore /i /y /h
63+
PREP
64+
65+
config.vm.provision "shell", name: "clear-build", inline: <<-CLEARBUILD
66+
Write-Host "($(Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss K")) Clearing the Chocolatey source directory"
67+
Remove-Item -Path C:/code/choco -Recurse -Force -ErrorAction SilentlyContinue
68+
xcopy c:\\chocoroot\\* c:\\code\\choco #{$xcopyArgs}
69+
CLEARBUILD
70+
71+
config.vm.provision "shell", name: "build", inline: <<-BUILD
72+
xcopy c:\\chocoroot\\* c:\\code\\choco #{$xcopyArgs}
5873
Push-Location c:/code/choco
5974
Write-Host "($(Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss K")) Files have been copied, beginning build process."
60-
./build.bat --verbosity=diagnostic --target=CI --testExecutionType=none --shouldRunalyze=false --shouldRunNuGet=false 2>&1 | Tee-Object CakeOutput
75+
$CakeOutput = ./build.bat --verbosity=diagnostic --target=CI --testExecutionType=none --shouldRunalyze=false --shouldRunNuGet=false 2>&1
6176
6277
if ($LastExitCode -ne 0) {
63-
Set-Content c:/vagrant/buildOutput.log -Value $CakeOutput
78+
Set-Content c:/chocoRoot/tests/buildOutput.log -Value $CakeOutput
6479
Write-Host "The build has failed. Please see the buildOutput.log file for details"
6580
exit $LastExitCode
6681
}
6782
6883
Write-Host "($(Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss K")) Build complete."
69-
SHELL
70-
config.vm.provision "shell", name: "clear-packages", inline: <<-SHELL
84+
BUILD
85+
86+
config.vm.provision "shell", name: "clear-packages", inline: <<-CLEARPACKAGES
7187
Write-Host "($(Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss K")) Clearing the packages directory"
7288
Remove-Item "$env:TEMP/chocolateyTests/packages" -Recurse -Force -ErrorAction SilentlyContinue
7389
Remove-Item "$env:TEMP/chocolateyTests/all-packages" -Recurse -Force -ErrorAction SilentlyContinue
74-
SHELL
75-
config.vm.provision "shell", name: "test", inline: <<-SHELL
76-
xcopy c:\\chocoroot\\* c:\\code\\choco /s /f /exclude:c:\\chocoroot\\.xcopyignore /i /y /h
90+
CLEARPACKAGES
91+
92+
config.vm.provision "shell", name: "test", inline: <<-TEST
93+
xcopy c:\\chocoroot\\* c:\\code\\choco #{$xcopyArgs}
7794
# Purge any tests files that have been removed.
7895
rm -re -fo c:\\code\\choco\\tests
79-
xcopy c:\\chocoroot\\tests\\* c:\\code\\choco\\tests /s /f /exclude:c:\\chocoroot\\.xcopyignore /i /y /h
96+
xcopy c:\\chocoroot\\tests\\* c:\\code\\choco\\tests #{$xcopyArgs}
8097
Write-Host "($(Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss K")) Starting Test Execution"
8198
Push-Location c:/code/choco
8299
# $env:TEST_KITCHEN = 1
83100
$env:VM_RUNNING = 1
84101
# The Invoke-Tests file will build the packages if the directory does not exist.
85102
# This will allow to rerun tests without packaging each time.
86103
./Invoke-Tests.ps1 -SkipPackaging
87-
Copy-Item $env:ALLUSERSPROFILE/chocolatey/logs/testInvocations.log C:/vagrant
88-
Copy-Item ./tests/testResults.xml C:/vagrant
89-
SHELL
104+
Copy-Item $env:ALLUSERSPROFILE/chocolatey/logs/testInvocations.log c:/chocoRoot/tests
105+
Copy-Item ./tests/testResults.xml c:/chocoRoot/tests
106+
TEST
90107
end

0 commit comments

Comments
 (0)