Skip to content

Commit

Permalink
Smoke test new pipeline to build packages
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRuiz7 committed Mar 21, 2024
1 parent 84c949b commit 0d525dc
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 141 deletions.
68 changes: 20 additions & 48 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ on:
revision:
description: "Revision"
type: string
required: true
default: "0"
upload:
description: "Upload ?"
type: bool
default: false
is_release:
description: "Upload ?"
type: bool
default: false
distribution:
description: "[ 'tar', 'rpm', 'deb', 'docker' ]"
type: string
default: "[ 'rpm', 'deb' ]"
architecture:
description: "[ 'x64', 'arm64' ]"
type: string
default: "[ 'x64' ]"

# ==========================
# Bibliography
Expand All @@ -33,58 +44,19 @@ on:
# | https://docs.github.com/en/actions/learn-github-actions/expressions#example

jobs:
version:
uses: ./.github/workflows/r_version.yml

commit_sha:
uses: ./.github/workflows/r_commit_sha.yml

build:
needs: [version, commit_sha]
strategy:
matrix:
distribution: [tar, rpm, deb]
architecture: [x64, arm64]
uses: ./.github/workflows/r_build.yml
with:
architecture: ${{ matrix.architecture }}
distribution: ${{ matrix.distribution }}
revision: ${{ github.event_name == 'push' && '0' || inputs.revision }}
name: wazuh-indexer-min_${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '0' || inputs.revision }}-${{ matrix.architecture }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.distribution }}

assemble:
needs: [version, commit_sha, build]
strategy:
matrix:
distribution: [tar, rpm, deb]
architecture: [x64, arm64]
distribution: ${{ inputs.distribution }}
architecture: ${{ inputs.architecture }}
exclude:
# skip arm64 until we have arm runners
- architecture: arm64
- distribution: tar

uses: ./.github/workflows/r_assemble.yml
fail-fast: false
uses: ./.github/workflows/r_build.yml
with:
architecture: ${{ matrix.architecture }}
distribution: ${{ matrix.distribution }}
revision: ${{ github.event_name == 'push' && '0' || inputs.revision }}
min: wazuh-indexer-min_${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '0' || inputs.revision }}-${{ matrix.architecture }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.distribution }}

test:
needs: [version, commit_sha, assemble]
strategy:
fail-fast: false
matrix:
os: [{ suffix: "amd64", ext: "deb" }, { suffix: "x86_64", ext: "rpm" }]
uses: ./.github/workflows/r_test.yml
with:
package: wazuh-indexer-${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '0' || inputs.revision }}_${{ matrix.os.suffix }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.os.ext }}

upload:
needs: [version, commit_sha, test]
# Upload only on 'workflow_dispatch' event and if 'upload=true'
if: ${{ github.event_name == 'push' && inputs.upload }}
uses: ./.github/workflows/r_upload.yml
with:
package: wazuh-indexer-${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '0' || inputs.revision }}_${{ matrix.os.suffix }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.os.ext }}
secrets: inherit
upload: ${{ inputs.upload }}
is_release: ${{ inputs.is_release }}
distribution: ${{ matrix.distribution }}
architecture: ${{ matrix.architecture }}
77 changes: 45 additions & 32 deletions .github/workflows/r_assemble.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
name: Assemble (reusable)

env:
TEST: true

# This workflow runs when any of the following occur:
# - Run from another workflow
on:
workflow_call:
inputs:
distribution:
description: "One of [ 'tar', 'rpm', 'deb' ]"
default: "rpm"
required: true
type: string
architecture:
description: "One of [ 'x64', 'arm64' ]"
default: "x64"
required: true
type: string
revision:
description: "Any string or number used to extend the package's identifier."
description: "Revision number"
type: string
required: true
default: "0"
min:
description: "The name of the package to download."
is_release:
description: "Uses release's nomenclature"
type: bool
default: false
distribution:
description: One of "[ 'tar', 'rpm', 'deb', 'docker' ]"
type: string
required: true
architecture:
description: One of "[ 'x64', 'arm64' ]"
type: string
required: true

jobs:
r_assemble:
Expand All @@ -37,30 +31,49 @@ jobs:
contents: read
steps:
- uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.min }}
path: artifacts/dist

- name: Run `baptizer.sh` (min)
run: |
name=$(bash scripts/baptizer.sh -m \
${{ inputs.is_release && '-x' }} \
-a ${{ inputs.architecture }} \
-d ${{ inputs.distribution }} \
-r ${{ inputs.revision }} \
)
echo "$name" >> $GITHUB_OUTPUT
id: min_package

- name: Run `baptizer.sh`
run: |
name=$(bash scripts/baptizer.sh \
${{ inputs.is_release && '-x' }} \
-a ${{ inputs.architecture }} \
-d ${{ inputs.distribution }} \
-r ${{ inputs.revision }} \
)
echo "$name" >> $GITHUB_OUTPUT
id: package

- name: Provision
if: ${{ inputs.distribution == 'deb' }}
run: |
sudo bash scripts/provision.sh
- name: Run `assemble.sh`
run: |
bash scripts/assemble.sh -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} -r ${{ inputs.revision }}
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ steps.min_package.outputs.name }}
path: artifacts/dist

# The package's name is stored in artifacts/artifact_name.txt.
- name: Set package name
id: get_name
run: |
echo "name=$(cat artifacts/artifact_name.txt)" >> $GITHUB_OUTPUT
- name: Run `assemble.sh`
mkdir -p ./artifacts/dist
touch ./artifacts/dist/${{ steps.package.outputs.name }}
# run: |
# bash scripts/assemble.sh -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} -r ${{ inputs.revision }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.get_name.outputs.name }}
path: artifacts/dist/${{ steps.get_name.outputs.name }}
name: ${{ steps.package.outputs.name }}
path: artifacts/dist/${{ steps.package.outputs.name }}
if-no-files-found: error
89 changes: 45 additions & 44 deletions .github/workflows/r_build.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,61 @@
name: Build (reusable)
name: Build pipeline (reusable)

# This workflow runs when any of the following occur:
# - Run from another workflow
on:
workflow_call:
inputs:
distribution:
description: "One of [ 'tar', 'rpm', 'deb' ]"
default: "rpm"
required: true
type: string
architecture:
description: "One of [ 'x64', 'arm64' ]"
default: "x64"
required: true
type: string
revision:
description: "Any string or number used to extend the package's identifier."
description: "Revision number"
type: string
required: true
default: "0"
name:
description: "The name of the package to upload."
upload:
description: "Uploads artifacts"
type: bool
default: false
is_release:
description: "Uses release's nomenclature"
type: bool
default: false
distribution:
description: One of "[ 'tar', 'rpm', 'deb', 'docker' ]"
type: string
required: true
architecture:
description: One of "[ 'x64', 'arm64' ]"
type: string
required: true

jobs:
r_build:
runs-on: ubuntu-latest
# Permissions to upload the package
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
build_min:
uses: ./.github/workflows/r_build_min.yml
with:
revision: ${{ inputs.revision }}
distribution: ${{ matrix.distribution }}
architecture: ${{ matrix.architecture }}

- name: Run `build.sh`
run: |
bash scripts/build.sh -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} -r ${{ inputs.revision }}
assemble:
needs: [build]
uses: ./.github/workflows/r_assemble.yml
with:
revision: ${{ inputs.revision }}
distribution: ${{ matrix.distribution }}
architecture: ${{ matrix.architecture }}

# The package's name is stored in artifacts/artifact_min_name.txt.
- name: Set package name
id: get_name
run: |
echo "name=$(cat artifacts/artifact_min_name.txt)" >> $GITHUB_OUTPUT
test:
needs: [assemble]
uses: ./.github/workflows/r_test.yml
with:
revision: ${{ inputs.revision }}
distribution: ${{ matrix.distribution }}
architecture: ${{ matrix.architecture }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.name }}
path: artifacts/dist/${{ steps.get_name.outputs.name }}
if-no-files-found: error
upload:
if: ${{ inputs.upload }}
needs: [test]
uses: ./.github/workflows/r_upload.yml
with:
revision: ${{ inputs.revision }}
distribution: ${{ matrix.distribution }}
architecture: ${{ matrix.architecture }}
secrets: inherit
65 changes: 65 additions & 0 deletions .github/workflows/r_build_min.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build minimal packages (reusable)

# This workflow runs when any of the following occur:
# - Run from another workflow
on:
workflow_call:
inputs:
revision:
description: "Revision number"
type: string
default: "0"
is_release:
description: "Uses release's nomenclature"
type: bool
default: false
distribution:
description: One of "[ 'tar', 'rpm', 'deb', 'docker' ]"
type: string
required: true
architecture:
description: One of "[ 'x64', 'arm64' ]"
type: string
required: true

jobs:
r_build_min:
runs-on: ubuntu-latest
# Permissions to upload the package
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Run `baptizer.sh`
run: |
name=$(bash scripts/baptizer.sh -m \
${{ inputs.is_release && '-x' }} \
-a ${{ inputs.architecture }} \
-d ${{ inputs.distribution }} \
-r ${{ inputs.revision }} \
)
echo "$name" >> $GITHUB_OUTPUT
id: package

- name: Run `build.sh`
run: |
mkdir -p ./artifacts/dist
touch ./artifacts/dist/${{ steps.package.outputs.name }}
# run: |
# bash scripts/build.sh -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} -r ${{ inputs.revision }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.package.outputs.name }}
path: artifacts/dist/${{ steps.package.outputs.name }}
if-no-files-found: error
Loading

0 comments on commit 0d525dc

Please sign in to comment.