Skip to content

Commit

Permalink
feat: added workflows to build mac OS packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcr99 committed Jan 31, 2025
1 parent b42469c commit 547add0
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 0 deletions.
124 changes: 124 additions & 0 deletions .github/workflows/macos_build_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
run-name: Packages - Build Wazuh agent macOS packages - ${{ inputs.architecture }}${{ inputs.is_stage && ' - is stage' || '' }}${{ inputs.checksum && ' - checksum' || '' }} ${{ inputs.id }}
name: Build Wazuh agent macOS packages

on:
pull_request:
workflow_dispatch:
inputs:
architecture:
type: choice
description: Package architecture [intel64, arm64].
options:
- intel64
- arm64
required: true
revision:
type: string
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/wazuh-agent to generate packages.
required: true
id:
type: string
description: |
ID used to identify the workflow uniquely.
required: false

workflow_call:
inputs:
architecture:
type: string
required: true
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

jobs:
build-binaries-agent-macos-packages:
uses: wazuh/wazuh-agent/.github/workflows/macos_compile_repository.yml@enhancement/137-pkg-build-trigger
with:
architecture: ${{ inputs.architecture }}
source_reference: ${{ inputs.source_reference }}
id: ${{ inputs.id }}

build-package-agent-macos-packages:
needs: build-binaries-agent-macos-packages
runs-on: macos-14
timeout-minutes: 50
name: Build macOS wazuh-agent package - ${{ inputs.architecture }}${{ 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: Download wazuh-agent-binaries.zip
uses: actions/download-artifact@v4
with:
name: wazuh-agent-binaries-${{ inputs.architecture }}

- name: Set vars to build macOS package
run: |
FLAGS="-a ${{ inputs.architecture }} -j 2 -r ${{ inputs.revision }} -s /tmp --verbose "
if [ "${{ inputs.is_stage }}" == "true" ]; then FLAGS+="--is_stage "; fi
if [ "${{ inputs.checksum }}" == "true" ]; then FLAGS+="--checksum "; fi
echo "FLAGS=$FLAGS" >> $GITHUB_ENV
- name: Build macOS package
run: |
sudo unzip wazuh-agent-binaries-${{ inputs.architecture }}.zip -d /
bash packages/macos/generate_wazuh_packages.sh -i
echo 'generate_wazuh_packages.sh ${{ env.FLAGS }}
sudo bash packages/macos/generate_wazuh_packages.sh ${{ env.FLAGS }}
- name: Bring package from allocator machine
run: |
sudo zip -r /tmp/wazuh-agent-package-${{ inputs.architecture }}.zip /tmp/*.pkg* -j'
- name: Upload wazuh agent package
uses: actions/upload-artifact@v4
with:
name: wazuh-agent-package-${{ inputs.architecture }}
path: /tmp/wazuh-agent-package-${{ inputs.architecture }}.zip

test-package-agent-macos-packages:
needs: build-package-agent-macos-packages
uses: wazuh/wazuh-agent/.github/workflows/macos_test_package.yml@enhancement/137-pkg-build-trigger
with:
architecture: ${{ inputs.architecture }}
checksum: ${{ inputs.checksum }}
upload_to_s3: ${{ inputs.upload_to_s3 }}
id: ${{ inputs.id }}
97 changes: 97 additions & 0 deletions .github/workflows/macos_test_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
run-name: Packages - Test Wazuh agent macOS package - ${{ inputs.architecture }} - ${{ inputs.id }}
name: Build Wazuh agent macOS packages

on:
pull_request:
workflow_dispatch:
inputs:
architecture:
type: choice
description: Package architecture [intel64, arm64].
options:
- intel64
- arm64
required: true
checksum:
type: boolean
description: |
Generate package checksum.
Default is 'false'.
required: false
upload_to_s3:
type: boolean
description: |
Upload generated package to S3.
Default is 'false'.
default: false
required: false
id:
type: string
description: |
ID used to identify the workflow uniquely.
required: false

workflow_call:
inputs:
architecture:
type: string
required: true
checksum:
type: boolean
required: false
upload_to_s3:
type: boolean
required: false
id:
type: string
required: false

jobs:
test-package-agent-macos-packages:
runs-on: ${{ inputs.architecture == 'arm64' && 'macos-14' || 'macos-13' }}
timeout-minutes: 50
name: Test macOS wazuh-agent package - ${{ inputs.architecture }}

steps:
- name: Download wazuh agent package
uses: actions/download-artifact@v4
with:
name: wazuh-agent-package-${{ inputs.architecture }}

- name: Test macOS package installation
run: |
ls
unzip wazuh-agent-package-${{ inputs.architecture }}.zip -d .
package_name=$(find . -type f -name "*agent*.pkg" -exec basename {} 2>/dev/null \;)
echo "PACKAGE_NAME=$package_name" >> $GITHUB_ENV
sudo installer -pkg ./*agent*pkg -target / | sudo tee /tmp/installer.log
if grep -q "The install was successful" "/tmp/installer.log"; then
echo "Installation successfully."
else
echo "The installation could not be completed. The package will not be uploaded.";
exit 1;
fi
- name: Set up AWS CLI
if: ${{ inputs.upload_to_s3 }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.CI_INTERNAL_DEVELOPMENT_BUCKET_USER_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.CI_INTERNAL_DEVELOPMENT_BUCKET_USER_SECRET_KEY }}
aws-region: ${{ secrets.CI_AWS_REGION }}

- name: Upload package to S3
if: ${{ inputs.upload_to_s3 }}
uses: ./.github/actions/upload_file_to_s3
with:
s3_uri: "s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages"
uploaded_file_name: ${{ env.PACKAGE_NAME }}
uploaded_file_location: "."

- name: Upload checksums to S3
if: ${{ inputs.checksum && inputs.upload_to_s3 }}
uses: ./.github/actions/upload_file_to_s3
with:
s3_uri: "s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages"
uploaded_file_name: ${{ env.PACKAGE_NAME }}.sha512
uploaded_file_location: "."

0 comments on commit 547add0

Please sign in to comment.