1
1
# -*- mode: ruby -*-
2
2
# vi: set ft=ruby :
3
3
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
+
4
10
Vagrant . configure ( "2" ) do |config |
5
11
config . vm . box = "chocolatey/test-environment"
6
12
# Set Hostname to prevent error messages. https://github.com/hashicorp/vagrant/issues/12644
@@ -20,27 +26,32 @@ Vagrant.configure("2") do |config|
20
26
config . winrm . retry_limit = 30
21
27
config . winrm . retry_delay = 10
22
28
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
-
26
29
config . vm . provider "virtualbox" do |vb |
27
30
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
30
33
vb . linked_clone = true
31
34
vb . customize [ 'modifyvm' , :id , '--vram' , '128' ]
32
35
end
33
36
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
37
40
h . linked_clone = true
38
41
h . enable_checkpoints = false
39
42
end
40
43
41
- config . vm . synced_folder '../' , '/chocoRoot'
42
44
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
44
55
cscript c:/windows/system32/slmgr.vbs /rearm | Out-Null
45
56
Set-ExecutionPolicy Bypass -Scope Process -Force
46
57
iex (irm https://community.chocolatey.org/install.ps1)
@@ -49,42 +60,48 @@ Vagrant.configure("2") do |config|
49
60
choco install git pester visualstudio2022community visualstudio2022-workload-manageddesktop netfx-4.8-devpack -y --no-progress
50
61
Import-Module $env:ChocolateyInstall/helpers/chocolateyProfile.psm1
51
62
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}
58
73
Push-Location c:/code/choco
59
74
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
61
76
62
77
if ($LastExitCode -ne 0) {
63
- Set-Content c:/vagrant /buildOutput.log -Value $CakeOutput
78
+ Set-Content c:/chocoRoot/tests /buildOutput.log -Value $CakeOutput
64
79
Write-Host "The build has failed. Please see the buildOutput.log file for details"
65
80
exit $LastExitCode
66
81
}
67
82
68
83
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
71
87
Write-Host "($(Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss K")) Clearing the packages directory"
72
88
Remove-Item "$env:TEMP/chocolateyTests/packages" -Recurse -Force -ErrorAction SilentlyContinue
73
89
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}
77
94
# Purge any tests files that have been removed.
78
95
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 }
80
97
Write-Host "($(Get-Date -Format "dddd MM/dd/yyyy HH:mm:ss K")) Starting Test Execution"
81
98
Push-Location c:/code/choco
82
99
# $env:TEST_KITCHEN = 1
83
100
$env:VM_RUNNING = 1
84
101
# The Invoke-Tests file will build the packages if the directory does not exist.
85
102
# This will allow to rerun tests without packaging each time.
86
103
./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
90
107
end
0 commit comments