Skip to content

Commit

Permalink
feat: use actions instead of reusable WF for Mac OS packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcr99 committed Feb 6, 2025
1 parent 6d72309 commit a73512b
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Compile Linux Repository'
description: 'Set Docker architecture, tag and image name'
description: 'Compile Linux Repository'
inputs:
architecture:
description: 'Linux image architecture'
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/linux_test_package/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Package Linux Binaries'
description: 'Package Linux Binaries'
name: 'Test Linux Package'
description: 'Test Linux Package'
inputs:
system:
description: 'Package system [deb,rpm]'
Expand All @@ -17,9 +17,9 @@ runs:
pattern: '*.${{ inputs.system }}'

- name: Prepare package
shell: bash
run: |
cp wazuh-agent*/wazuh-agent* /tmp
shell: bash
- name: Test DEB package installation
uses: ./.github/actions/test-install-components
Expand Down
30 changes: 30 additions & 0 deletions .github/actions/macos_compile_repository/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'Compile Mac OS Repository'
description: 'Compile Mac OS Repository'
inputs:
architecture:
description: 'Building architecture'
required: true
gh_token:
description: 'Used token to fetch Docker images'
required: true

runs:
using: 'composite'
steps:
- name: Set up Binary caching
uses: ./.github/actions/vcpkg_related/cover_vcpkg_dependencies
with:
gh_token: ${{ inputs.gh_token }}

- name: Build repository
shell: bash
run: |
mkdir -p src/build && cd src/build && cmake .. && make -j $(sysctl -n hw.ncpu)
sudo rm -rf _deps vcpkg_installed
zip -r ${{ github.workspace }}/wazuh-agent-binaries-${{ inputs.architecture }}.zip ${{ github.workspace }}/
- name: Upload wazuh-agent-binaries.zip
uses: actions/upload-artifact@v4
with:
name: wazuh-agent-binaries-${{ inputs.architecture }}
path: ${{ github.workspace }}/wazuh-agent-binaries-${{ inputs.architecture }}.zip
52 changes: 52 additions & 0 deletions .github/actions/macos_package_binaries/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: 'Package Mac OS Binaries'
description: 'Package Mac OS Binaries'
inputs:
architecture:
description: 'Building architecture'
required: true
revision:
description: 'Package revision'
required: false
is_stage:
description: 'Stage package'
required: false
checksum:
description: 'Generate package checksum'
required: false

runs:
steps:
- 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
shell: bash
run: |
FLAGS="-a ${{ inputs.architecture }} -j $(sysctl -n hw.ncpu) -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
shell: bash
run: |
sudo unzip -o 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 }}
echo "PACKAGE_NAME=$(find /tmp -maxdepth 1 -type f -name *agent* -exec basename {} 2>/dev/null \;| grep -v -E "^(wazuh-agent-dbg|wazuh-agent-debuginfo)")" | tee -a $GITHUB_ENV
- name: Upload wazuh agent package
uses: actions/upload-artifact@v4
with:
name: ${{ env.PACKAGE_NAME }}
path: /tmp/${{ env.PACKAGE_NAME }}

- name: Upload checksums to artifact
if: ${{ inputs.checksum == 'true'}}
uses: actions/upload-artifact@v4
with:
name: ${{ env.PACKAGE_NAME }}.sha512
path: /tmp/${{ env.PACKAGE_NAME }}.sha512
59 changes: 59 additions & 0 deletions .github/actions/macos_test_package/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: 'Test Mac OS Package'
description: 'Test Mac OS Package'
inputs:
checksum:
description: 'Generate package checksum'
required: false
upload_to_s3:
description: 'Upload package to S3'
required: true

runs:
using: 'composite'
steps:
- name: Download wazuh agent package
uses: actions/download-artifact@v4
with:
pattern: '*.pkg*'

- name: Prepare package
shell: bash
run: |
cp wazuh-agent*/wazuh-agent* /tmp
- name: Test macOS package installation
shell: bash
run: |
package_name=$(find /tmp -type f -name "*agent*.pkg" -exec basename {} 2>/dev/null \;)
echo "PACKAGE_NAME=$package_name" >> $GITHUB_ENV
sudo installer -pkg /tmp/*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 == 'true' }}
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 == 'true' }}
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: "/tmp"

- name: Upload checksums to S3
if: ${{ inputs.checksum == 'true' && inputs.upload_to_s3 == 'true' }}
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: "/tmp"
6 changes: 3 additions & 3 deletions .github/workflows/linux_build_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
persist-credentials: false

- name: Compile Linux Repositorys
uses: ./.github/actions/linux_compile_repositoty
uses: ./.github/actions/linux_compile_repository
with:
architecture: ${{ inputs.architecture }}
docker_image_tag: ${{ inputs.docker_image_tag }}
Expand All @@ -143,7 +143,7 @@ jobs:
ref: ${{ inputs.source_reference }}
persist-credentials: false

- name: Compile Linux Repository
- name: Build Linux DEB Package - ${{ inputs.architecture }}
uses: ./.github/actions/linux_package_binaries
with:
architecture: ${{ inputs.architecture }}
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
ref: ${{ inputs.source_reference }}
persist-credentials: false

- name: Compile Linux Repository
- name: Build Linux RPM Package - ${{ inputs.architecture }}
uses: ./.github/actions/linux_package_binaries
with:
architecture: ${{ inputs.architecture }}
Expand Down
85 changes: 48 additions & 37 deletions .github/workflows/macos_build_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,53 +74,64 @@ on:

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 }}
runs-on: ${{ inputs.architecture == 'arm64' && 'macos-14' || 'macos-13' }}
env:
VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite'
timeout-minutes: 50
name: Build Mac OS wazuh-agent sources - ${{ inputs.architecture }}

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

- name: Compile Mac OS Repository
uses: ./.github/actions/macos_compile_repository
with:
architecture: ${{ inputs.architecture }}
gh_token: ${{ github.token }}

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' || '' }}
name: Build Mac OS wazuh-agent package - ${{ inputs.architecture }}${{ inputs.is_stage && ' - is stage' || '' }}${{ inputs.checksum && ' - checksum' || '' }}

steps:
- name: Download wazuh-agent-binaries.zip
uses: actions/download-artifact@v4
- name: Checkout the wazuh-agent repository
uses: actions/checkout@v4
with:
name: wazuh-agent-binaries-${{ inputs.architecture }}

- name: Set vars to build macOS package
run: |
FLAGS="-a ${{ inputs.architecture }} -j $(sysctl -n hw.ncpu) -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
repository: wazuh/wazuh-agent
ref: ${{ inputs.source_reference }}
persist-credentials: false

- 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: Zip package
run: |
sudo zip -r /tmp/wazuh-agent-package-${{ inputs.architecture }}.zip /tmp/*.pkg* -j
- name: Upload wazuh agent package
uses: actions/upload-artifact@v4
- name: Build Mac OS Package - ${{ inputs.architecture }}
uses: ./.github/actions/macos_package_binaries
with:
name: wazuh-agent-package-${{ inputs.architecture }}
path: /tmp/wazuh-agent-package-${{ inputs.architecture }}.zip
architecture: ${{ inputs.architecture }}
revision: ${{ inputs.revision }}
is_stage: ${{ inputs.is_stage }}
checksum: ${{ inputs.checksum }}

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 }}
runs-on: ${{ inputs.architecture == 'arm64' && 'macos-14' || 'macos-13' }}
timeout-minutes: 50
name: Test Mac OS 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: Test Mac OS Package - ${{ inputs.architecture }}
uses: ./.github/actions/macos_test_package
with:
checksum: ${{ inputs.checksum }}
upload_to_s3: 'false'

0 comments on commit a73512b

Please sign in to comment.