Skip to content

Commit

Permalink
feat: added shell definition in windows packages workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcr99 committed Feb 13, 2025
1 parent 072c908 commit 8455a06
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
79 changes: 40 additions & 39 deletions .github/workflows/packages-build-windows-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,68 +74,69 @@ jobs:
gh_token: ${{ secrets.CI_WAZUH_AGENT_PACKAGES_CLASSIC }}

- name: Set PKG_NAME
shell: bash
run: |
$VERSION = (Invoke-RestMethod -Uri "https://raw.githubusercontent.com/wazuh/wazuh-agent/${{ inputs.source_reference }}/src/VERSION") -match "([0-9]+\.[0-9]+\.[0-9]+)" ? $matches[1] : ""
$COMMIT_HASH = (Invoke-RestMethod -Uri "https://api.github.com/repos/wazuh/wazuh-agent/branches/${{ inputs.source_reference }}" | Select-String -Pattern '"sha"' | Select-Object -First 1) -match '"sha":\s*"(\w{7})"' ? $matches[1] : ""
if ("${{ inputs.is_stage }}" -eq "true") {
$PKG_NAME = "wazuh-agent-$VERSION-${{ inputs.revision }}"
} else {
$PKG_NAME = "wazuh-agent_${VERSION}-${{ inputs.revision }}_windows_${COMMIT_HASH}"
}
$BINARIES_NAME = "windows-build-${VERSION}-${{ inputs.revision }}_${COMMIT_HASH}"
echo "BINARIES_NAME=$BINARIES_NAME" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "PKG_NAME=$PKG_NAME" | Out-File -FilePath $env:GITHUB_ENV -Append
VERSION=$(curl -s "https://raw.githubusercontent.com/wazuh/wazuh-agent/${{ inputs.source_reference }}/src/VERSION" | sed 's/.*\([0-9]\.[0-9]*\.[0-9]*\).*/\1/')
COMMIT_HASH="$(curl -s "https://api.github.com/repos/wazuh/wazuh-agent/branches/${{ inputs.source_reference }}" | grep '"sha"' | head -1 | sed 's/.*: "\(.*\)",/\1/' | cut -c1-7)"
if [ "${{ inputs.is_stage }}" == "true" ]; then
echo "PKG_NAME=wazuh-agent-${VERSION}-${{ inputs.revision }}" >> $GITHUB_ENV
else
echo "PKG_NAME=wazuh-agent_${VERSION}-${{ inputs.revision }}_windows_${COMMIT_HASH}" >> $GITHUB_ENV
fi
echo "BINARIES_NAME=windows-build-${VERSION}-${{ inputs.revision }}_${COMMIT_HASH}" >> $GITHUB_ENV
- name: Build binaries for Windows package
- name: Build MSI for Windows package
run: |
./packages/windows/generate_compiled_windows_agent.ps1 -MSI_NAME ${{ env.PKG_NAME }} -CMAKE_CONFIG RelWithDebInfo -BUILD_TESTS 1
./packages/windows/generate_wazuh_msi.ps1 -MSI_NAME "${{ env.PKG_NAME }}" -CMAKE_CONFIG RelWithDebInfo -DEBUG yes | Out-File -FilePath "C:\tmp\generate_msi.log"
- name: Build MSI for Windows package
- name: Check MSI for Windows package
run: |
./wazuh-agent/packages/windows/generate_wazuh_msi.ps1 -MSI_NAME ${{ env.PKG_NAME }} -CMAKE_CONFIG RelWithDebInfo -DEBUG yes" &> /tmp/generate_msi.log
cat /tmp/generate_msi.log
if [ "$(grep -c 'SignTool Error' /tmp/generate_msi.log)" -ne "0" ] ; then
echo "The generation and sign could not be completed."
exit 1
else
echo "Package correctly generated."
cp ./packages/windows/${{ env.PKG_NAME }}.msi" /tmp/
cp ./build/RelWithDebInfo/${{ env.PKG_NAME }}-debug-symbols.zip" /tmp/
fi
Get-Content "C:\tmp\generate_msi.log"
$errorCount = (Select-String -Path "C:\tmp\generate_msi.log" -Pattern "SignTool Error").Count
if ($errorCount -ne 0) {
Write-Output "The generation and sign could not be completed."
exit 1
} else {
Write-Output "Package correctly generated."
Copy-Item ".\packages\windows\${{ env.PKG_NAME }}.msi" -Destination "C:\tmp\"
Copy-Item ".\build\RelWithDebInfo\${{ env.PKG_NAME }}-debug-symbols.zip" -Destination "C:\tmp\"
}
- name: Install Windows agent
run: |
Start-Process -FilePath './wazuh-agent/packages/windows/${{ env.PKG_NAME }}.msi' -ArgumentList '/l ./installer.log' -wait
installerfile=$("Get-Content ./installer.log")
echo $installerfile
if [[ $installerfile == *"Wazuh Agent -- Installation completed successfully"* ]]; then
echo "Installation successfully."
else
echo "The installation could not be completed. The package will not be uploaded."
exit 1
fi
Write-Output $installerfile
if ($installerfile -like "*Wazuh Agent -- Installation completed successfully*") {
Write-Output "Installation successfully."
} else {
Write-Output "The installation could not be completed. The package will not be uploaded."
exit 1
}
- name: Create checksum file
if: ${{ inputs.checksum }}
run: |
sha512sum "/tmp/${{ env.PKG_NAME }}.msi" > "/tmp/${{ env.PKG_NAME }}.msi.sha512"
if [ -s /tmp/${{ env.PKG_NAME }}.msi.sha512 ]; then
echo "Checksum file successfully created."
else
echo "Checksum file is empty or does not exist."
exit 1
fi
$msiPath = "C:\tmp\${{ env.PKG_NAME }}.msi"
$hashFile = "C:\tmp\${{ env.PKG_NAME }}.msi.sha512"
Get-FileHash -Path $msiPath -Algorithm SHA512 | Select-Object -ExpandProperty Hash | Out-File -FilePath $hashFile
if (Test-Path $hashFile -and (Get-Content $hashFile).Length -gt 0) {
Write-Output "Checksum file successfully created."
} else {
Write-Output "Checksum file is empty or does not exist."
exit 1
}
- name: Upload Windows Wazuh agent package
uses: actions/upload-artifact@v4
with:
name: ${{ env.PKG_NAME }}
path: /tmp/${{ env.PKG_NAME }}.msi
path: C:/tmp/${{ env.PKG_NAME }}.msi

- name: Upload Windows Wazuh agent package checksum
if: ${{ inputs.checksum }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.PKG_NAME }}.sha512
path: /tmp/${{ env.PKG_NAME }}.msi.sha512
path: C:/tmp/${{ env.PKG_NAME }}.msi.sha512
2 changes: 1 addition & 1 deletion packages/windows/generate_compiled_windows_agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ mkdir build -Force
$Env:CUSTOM_PACKAGE_NAME = $MSI_NAME
$Env:CUSTOM_CMAKE_CONFIG = $CMAKE_CONFIG
cmake src -B build -DBUILD_TESTS=$BUILD_TESTS -G "Visual Studio 17 2022" -A x64
cmake --build build --config $CMAKE_CONFIG
cmake --build build --config $CMAKE_CONFIG --parallel (Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors
cd $originalDir

0 comments on commit 8455a06

Please sign in to comment.