Skip to content

Commit

Permalink
feat: added packages-build-windows-agent.yml workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcr99 committed Feb 12, 2025
1 parent 5165a6b commit b74785e
Showing 1 changed file with 140 additions and 0 deletions.
140 changes: 140 additions & 0 deletions .github/workflows/packages-build-windows-agent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
run-name: Packages - Build Wazuh agent Windows ${{ inputs.is_stage && ' - is stage' || '' }}${{ inputs.checksum && ' - checksum' || '' }} - ${{ inputs.id }}
name: Build Wazuh agent Windows

on:
workflow_dispatch:
inputs:
revision:
description: |
Package revision (name and metadata).
Default is '0'.
required: false
default: '0'
is_stage:
type: boolean
description: |
Set production nomenclature if true.
Default is 'false'.
required: false
checksum:
type: boolean
description: |
Generate package checksum.
Default is 'false'.
required: false
source_reference:
type: string
description: |
Branch/tag of wazuh-agent repository to generate packages.
required: true
id:
type: string
description: |
ID used to identify the workflow uniquely.
required: false

workflow_call:
inputs:
revision:
type: string
required: false
is_stage:
type: boolean
required: false
checksum:
type: boolean
required: false
source_reference:
type: string
required: true
id:
type: string
required: false

env:
VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite'

jobs:
generate-agent-windows-package:
runs-on: windows-2022
timeout-minutes: 120
name: Generate MSI Windows wazuh-agent${{ inputs.is_stage && ' - is stage' || '' }}${{ inputs.checksum && ' - checksum' || '' }}

steps:
- name: Checkout the wazuh-agent repository
uses: actions/checkout@v4
with:
repository: wazuh/wazuh-agent
ref: ${{ inputs.source_reference }}
persist-credentials: false

- name: Set up Binary caching
uses: ./.github/actions/vcpkg_related/cover_vcpkg_dependencies
with:
gh_token: ${{ secrets.CI_WAZUH_AGENT_PACKAGES_CLASSIC }}

- name: Set PKG_NAME
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 }}" >> $env:GITHUB_ENV
} else {
$PKG_NAME = "wazuh-agent_${VERSION}-${{ inputs.revision }}_windows_${COMMIT_HASH}" >> $env:GITHUB_ENV
}
$BINARIES_NAME = "windows-build-${VERSION}-${{ inputs.revision }}_${COMMIT_HASH}" >> $env:GITHUB_ENV
- name: Build binaries for Windows package
run: |
./packages/windows/generate_compiled_windows_agent.ps1 -MSI_NAME ${{ env.PKG_NAME }} -CMAKE_CONFIG RelWithDebInfo -BUILD_TESTS 1
- name: Build 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
- 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
- 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
- name: Upload Windows Wazuh agent package
uses: actions/upload-artifact@v4
with:
name: ${{ env.PKG_NAME }}
path: /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

0 comments on commit b74785e

Please sign in to comment.