Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save plugins and reporting repo hashes on workflow variable and updat… #502

Merged
merged 11 commits into from
Oct 31, 2024
Merged
17 changes: 17 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ jobs:
runs-on: ubuntu-latest
env:
plugin_name: wazuh-indexer-${{ matrix.plugins }}
outputs:
hash: ${{ steps.save-hash.outputs.hash }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -151,6 +153,10 @@ jobs:
- run: ls -lR build/distributions
working-directory: ./plugins/${{ matrix.plugins }}

- name: Save commit hash
id: save-hash
run: echo "hash=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
Expand All @@ -161,6 +167,8 @@ jobs:
build-reporting-plugin:
if: ${{ inputs.reporting_plugin_ref != '' }}
runs-on: ubuntu-latest
outputs:
hash: ${{ steps.save-hash.outputs.hash }}
env:
plugin_name: wazuh-indexer-reports-scheduler
steps:
Expand All @@ -186,6 +194,10 @@ jobs:

- run: ls -lR build/distributions

- name: Save commit hash
id: save-hash
run: echo "hash=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -233,17 +245,22 @@ jobs:
-a ${{ matrix.architecture }} \
-d ${{ matrix.distribution }} \
-r ${{ inputs.revision }} \
-l ${{ needs.build-wazuh-plugins.outputs.hash }} \
-e ${{ needs.build-reporting-plugin.outputs.hash }} \
${{ inputs.is_stage && '-x' || '' }} \
)
echo "name=$name" >> $GITHUB_OUTPUT
id: min_package

- name: Run `baptizer.sh`
# As parameters
run: |
name=$(bash build-scripts/baptizer.sh \
-a ${{ matrix.architecture }} \
-d ${{ matrix.distribution }} \
-r ${{ inputs.revision }} \
-l ${{ needs.build-wazuh-plugins.outputs.hash }} \
-e ${{ needs.build-reporting-plugin.outputs.hash }} \
${{ inputs.is_stage && '-x' || '' }} \
)
echo "name=$name" >> $GITHUB_OUTPUT
Expand Down
8 changes: 5 additions & 3 deletions build-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> [!CAUTION]
>
> Be aware that there might be some problems while following the steps in this guide due to outdated information.
> Be aware that there might be some problems while following the steps in this guide due to outdated information.
> This document is pending a review. Let us know if you find any issues.

The packages' generation process consists on 2 steps:
Expand Down Expand Up @@ -235,7 +235,7 @@ them, as well as their inputs and outputs.
scripts:
- file: build.sh
description: |
generates a distribution package by running the appropiate Gradle task
generates a distribution package by running the appropiate Gradle task
depending on the parameters.
inputs:
architecture: [x64, arm64] # Note: we only build x86_64 packages
Expand All @@ -246,7 +246,7 @@ scripts:

- file: assemble.sh
description: |
bundles the wazuh-indexer package generated in by build.sh with plugins,
bundles the wazuh-indexer package generated in by build.sh with plugins,
configuration files and demo certificates (certificates yet to come).
inputs:
architecture: [x64, arm64] # Note: we only build x86_64 packages
Expand All @@ -264,6 +264,8 @@ scripts:
architecture: [x64, arm64] # Note: we only build x86_64 packages
distribution: [tar, deb, rpm]
revision: revision number. 0 by default.
plugins_hash: Commit hash of the `wazuh-indexer-plugins` repository.
reporting_hash: Commit hash of the `wazuh-indexer-reporting` repository.
is_release: if set, uses release naming convention.
is_min: if set, the package name will start by `wazuh-indexer-min`. Used on the build stage.
outputs:
Expand Down
22 changes: 18 additions & 4 deletions build-scripts/baptizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function usage() {
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, default is 'uname -m'."
echo -e "-d DISTRIBUTION\t[Optional] Distribution, default is 'tar'."
echo -e "-r REVISION\t[Optional] Package revision, default is '0'."
echo -e "-l PLUGINS_HASH\t[Optional] Commit hash from the wazuh-indexer-plugins repository"
echo -e "-e REPORTING_HASH\t[Optional] Commit hash from the wazuh-indexer-reporting repository"
echo -e "-m MIN\t[Optional] Use naming convention for minimal packages, default is 'false'."
echo -e "-x RELEASE\t[Optional] Use release naming convention, default is 'false'."
echo -e "-h help"
Expand All @@ -20,7 +22,7 @@ function usage() {
# ====
function parse_args() {

while getopts ":h:p:a:d:r:mx" arg; do
while getopts ":h:p:a:d:r:l:e:mx" arg; do
case $arg in
h)
usage
Expand All @@ -38,6 +40,12 @@ function parse_args() {
r)
REVISION=$OPTARG
;;
l)
PLUGINS_HASH=$OPTARG
;;
e)
REPORTING_HASH=$OPTARG
;;
m)
IS_MIN=true
;;
Expand Down Expand Up @@ -122,11 +130,17 @@ function get_release_name() {
# Naming convention for pre-release packages
# ====
function get_devel_name() {
PREFIX=wazuh-indexer
COMMIT_HASH=$GIT_COMMIT
# Add -min to the prefix if corresponds
if "$IS_MIN"; then
PACKAGE_NAME=wazuh-indexer-min_"$VERSION"-"$REVISION"_"$SUFFIX"_"$GIT_COMMIT"."$EXT"
else
PACKAGE_NAME=wazuh-indexer_"$VERSION"-"$REVISION"_"$SUFFIX"_"$GIT_COMMIT"."$EXT"
PREFIX="$PREFIX"-min
fi
# Generate composed commit hash
if [ -n "$PLUGINS_HASH" ] && [ -n "$REPORTING_HASH" ]; then
COMMIT_HASH="$GIT_COMMIT"-"$PLUGINS_HASH"-"$REPORTING_HASH"
fi
PACKAGE_NAME="$PREFIX"_"$VERSION"-"$REVISION"_"$SUFFIX"_"$COMMIT_HASH"."$EXT"
}

# ====
Expand Down