Skip to content

Commit

Permalink
windows-agent-compile.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed Jul 22, 2024
1 parent a340ef1 commit 9d86fbb
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
56 changes: 56 additions & 0 deletions .github/scripts/windows-agent-compile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#first install vcpkg in collect directory
Set-PSDebug -Trace 2

Write-Host "Work in" $pwd.ToString()

[System.Environment]::SetEnvironmentVariable("VCPKG_BINARY_SOURCES", "clear;files," + $pwd.ToString() + "\vcpkg\vcpkg-binary-cache,readwrite")
[System.Environment]::SetEnvironmentVariable("VCPKG_ROOT",$pwd.ToString()+"\vcpkg")
[System.Environment]::SetEnvironmentVariable("PATH",$pwd.ToString()+"\vcpkg:" + $env:PATH)
[System.Environment]::SetEnvironmentVariable("AWS_EC2_METADATA_DISABLED","true")

Write-Host $env:VCPKG_BINARY_SOURCES

$current_dir = $pwd.ToString()

git clone --depth 1 --single-branch --no-tags https://github.com/microsoft/vcpkg vcpkg
cd vcpkg
bootstrap-vcpkg.bat
cd $current_dir

#get cache from s3
$files_to_hash= "vcpkg.json", "custom-triplets\x64-windows.cmake", "CMakeLists.txt", "CMakeListsWindows.txt"
$files_content= Get-Content -Path $files_to_hash -Raw
$stringAsStream = [System.IO.MemoryStream]::new()
$writer = [System.IO.StreamWriter]::new($stringAsStream)
$writer.write($files_content -join " ")
$writer.Flush()
$stringAsStream.Position = 0
$vcpkg_hash=Get-FileHash -InputStream $stringAsStream -Algorithm SHA256 | Select-Object Hash
$file_name = "windows-agent-binary-cache-" + $vcpkg_hash.Hash
$file_name_extension = "${file_name}.7z"

aws --quiet s3 cp s3://centreon-collect-robot-report/$file_name_extension $file_name_extension
if ( $? -ne 0 ) {
Write-Host "#######################################################################################################################"
Write-Host "binary cache unavailable for this version we will need to build it, it will take a long time"
Write-Host "#######################################################################################################################"
Write-Host "Create cmake files before upload binary-cache"
cmake --preset=release

Write-Host "Compress binary archive"
7z a $file_name_extension vcpkg\vcpkg-binary-cache
Write-Host "Upload binary archive"
aws s3 cp $file_name_extension s3://centreon-collect-robot-report/$file_name_extension
}
else {
7z x $file_name_extension

Write-Host "Create cmake files from binary-cache downloaded"
cmake --preset=release-ci-use-binary-cache

}


Write-Host "build agent and tests"
cmake --build build_windows

12 changes: 7 additions & 5 deletions .github/workflows/windows-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,26 @@ jobs:
- name: Checkout sources
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- uses: ./.github/actions/compile-windows-agent
- name: Compile Agent
run: .github/scripts/windows-agent-compile.ps1
shell: powershell

- name: common test
- name: Common test
run: |
cd build_windows
tests/ut_common
- name: agent test
- name: Agent test
run: |
cd build_windows
tests/ut_agent
- name: zip agent
- name: Zip agent
run: |
$files_to_compress = ".\agent\conf\centagent.reg", "build_windows\agent\centagent.exe"
Compress-Archive -Path $files_to_compress -DestinationPath centreon-monitoring-agent.zip
- name: save agent package in cache
- name: Save agent package in cache
uses: actions/cache/save@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
with:
path: centreon-monitoring-agent.zip
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
},
{
"name": "release-ci",
"name": "release-ci-use-binary-cache",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build_windows",
"cacheVariables": {
Expand Down

0 comments on commit 9d86fbb

Please sign in to comment.