diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 29e0354004077..785c0ee626ad0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,15 +4,35 @@ name: Build packages # - Run manually on: workflow_dispatch: + # TODO dynamic matrix or filtering complete matrix based on inputs + # inputs: + # distribution: + # description: 'One of [ "tar", "rpm", "deb", "all" ]' + # default: 'all' + # required: false + # type: string + # architecture: + # description: 'One of [ "x64", "arm64", "all" ]' + # default: 'x64' + # required: true + # type: string + +# TODO para que esto funcione con reusable workflows hay que moverlos a variables +# TODO para pasar el nombre del paquete del stage build al stage assemble hay que usar outputs + +# ========================== +# Bibliography +# ========================== +# +# * Reusable workflows: limitations +# | https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations +# * Using matrix in reusable workflows: +# | https://docs.github.com/en/actions/using-workflows/reusing-workflows#using-a-matrix-strategy-with-a-reusable-workflow +# * Reading input from the called workflow +# | https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_callinputs -# Used to run locally using https://github.com/nektos/act env: - ACT: - VERSION: 2.11.0 - SNAPSHOT: false - PLATFORM: linux - BUILD: bash scripts/build.sh - ASSEMBLE: bash scripts/assemble.sh + ACT: # Used to run locally using https://github.com/nektos/act jobs: build: @@ -31,10 +51,10 @@ jobs: DISTRIBUTION: [tar, rpm, deb] ARCHITECTURE: [x64, arm64] outputs: - package_name: ${{ steps.get_package_name.outputs.package_name }} + package: ${{ steps.r_build.outputs.package }} steps: - uses: actions/checkout@v4 - - uses: actions/setup-java@v3 + - uses: actions/setup-java@v4 with: distribution: temurin java-version: 11 @@ -43,23 +63,19 @@ jobs: uses: gradle/gradle-build-action@v2.9.0 - name: Run `build.sh` - run: | - $BUILD -v $VERSION -s $SNAPSHOT -p $PLATFORM -a ${{ matrix.ARCHITECTURE }} -d ${{ matrix.DISTRIBUTION }} - - # The package name is stored in the artifacts/artifact_name.txt file - - name: Read package name - id: get_package_name - run: | - echo $(ls -la) - echo "package_name=$(cat artifacts/artifact_name.txt)" >> $GITHUB_OUTPUT - echo "$(cat artifacts/artifact_name.txt)" - - - name: Upload artifact - uses: actions/upload-artifact@v3 + id: r_build + uses: ./.github/workflows/r_build.yml + with: + architecture: ${{ matrix.ARCHITECTURE }} + distribution: ${{ matrix.DISTRIBUTION }} + + - name: Run `assemble.sh` + uses: ./.github/workflows/r_assemble.yml with: - name: ${{ steps.get_package_name.outputs.package_name }} - path: artifacts/dist/${{ steps.get_package_name.outputs.package_name }} - if-no-files-found: error + architecture: ${{ matrix.ARCHITECTURE }} + distribution: ${{ matrix.DISTRIBUTION }} + package: ${{ needs.build.outputs.package }} + # TODO comprobar si usa la misma máquina y hay acceso a ./artifacts/dist # assemble: # # needs: [build] @@ -79,7 +95,7 @@ jobs: # # ARCHITECTURE: [ x64, arm64 ] # steps: # - name: Download artifact - # uses: actions/download-artifact@v3 + # uses: actions/download-artifact@v4 # with: # name: wazuh-indexer-*${{ matrix.ARCHITECTURE }}*${{ matrix.DISTRIBUTION }} # # name: ${{ needs.build.outputs.package_name }} diff --git a/.github/workflows/r_assemble.yml b/.github/workflows/r_assemble.yml new file mode 100644 index 0000000000000..7136e683eaa1b --- /dev/null +++ b/.github/workflows/r_assemble.yml @@ -0,0 +1,69 @@ +name: Assemble (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: false + type: string + architecture: + description: 'One of [ "x64", "arm64" ]' + default: 'x64' + required: false + type: string + package: + required: true + type: string + # outputs: + # package: + # description: "The package's name" + # value: ${{ jobs.build.outputs.package }} + + +jobs: + build: + # runs-on: ${{ inputs.architecture }} + runs-on: ubuntu-latest + # Permissions to upload the package + permissions: + packages: write + contents: read + # outputs: + # package: ${{ steps.get_name.outputs.name }} + steps: + - name: Read artifacts + run: | + ls -l ./artifacts/dist + + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.package }} + path: ${{ inputs.architecture }}/${{ inputs.distribution }} + + # - name: Run `assemble.sh` + # run: | + # bash scripts/assemble.sh -v ${{ vars.OPENSEARCH_VERSION }} -p linux -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} + + # # The package name is stored in the artifacts/artifact_name.txt file. + # # The variable name is generated dynamically: rpm_x64 + # - name: Set package name + # id: get_name + # run: | + # echo $(ls -la) + # # ${{ inputs.distribution }}_${{ inputs.architecture }} + # echo "name=$(cat artifacts/artifact_name.txt)" >> $GITHUB_OUTPUT + # echo "$(cat artifacts/artifact_name.txt)" + + # - name: Upload artifact + # uses: actions/upload-artifact@v4 + # with: + # name: ${{ steps.get_name.outputs.name }} + # path: ${{ inputs.architecture }}/${{ inputs.distribution }} + # if-no-files-found: error + + diff --git a/.github/workflows/r_build.yml b/.github/workflows/r_build.yml new file mode 100644 index 0000000000000..9aa964ce7a595 --- /dev/null +++ b/.github/workflows/r_build.yml @@ -0,0 +1,65 @@ +name: Build (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: false + type: string + architecture: + description: 'One of [ "x64", "arm64" ]' + default: 'x64' + required: false + type: string + outputs: + package: + description: "The package's name" + value: ${{ jobs.build.outputs.package }} + +# TODO version must to be read from the VERSION file +# TODO revision must be an input +env: + version: 4.9.0 + revision: 1 + +jobs: + build: + # runs-on: ${{ inputs.architecture }} + runs-on: ubuntu-latest + # Permissions to upload the package + permissions: + packages: write + contents: read + outputs: + package: ${{ steps.get_name.outputs.name }} + steps: + - name: Run `build.sh` + run: | + bash scripts/build.sh -v ${{ vars.OPENSEARCH_VERSION }} -s false -p linux -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} + + # The package name is stored in the artifacts/artifact_name.txt file. + # The variable name is generated dynamically: rpm_x64 + - name: Set package name + id: get_name + run: | + echo $(ls -la) + # ${{ inputs.distribution }}_${{ inputs.architecture }} + echo "name=$(cat artifacts/artifact_name.txt)" >> $GITHUB_OUTPUT + echo "$(cat artifacts/artifact_name.txt)" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + # name: wazuh-indexer-min_${{ env.version }}-${{ env.revision }}_${{ inputs.architecture }}_${{ github.sha }}.${{ inputs.distribution }} + # example: x64/deb/wazuh-indexer_4.8.0-rc1_x64_ff98475f.deb + # TODO x64 -> deb: amd64, rpm: x86_64 + name: ${{ steps.get_name.outputs.name }} + path: ${{ inputs.architecture }}/${{ inputs.distribution }} + if-no-files-found: error + + + diff --git a/scripts/assemble.sh b/scripts/assemble.sh index 0e2772fc96f63..68c5551da06a5 100755 --- a/scripts/assemble.sh +++ b/scripts/assemble.sh @@ -262,10 +262,12 @@ function assemble_rpm() { # Move the root folder, copy the package and clean. cd ../../.. - cp "${TMP_DIR}/RPMS/${SUFFIX}/wazuh-indexer-${version}-1.${SUFFIX}.${EXT}" "${OUTPUT}/dist/" + package_name="wazuh-indexer-${version}-1.${SUFFIX}.${EXT}" + cp "${TMP_DIR}/RPMS/${SUFFIX}/${package_name}" "${OUTPUT}/dist/" echo "Cleaning temporary ${TMP_DIR} folder" rm -r "${TMP_DIR}" echo "After execution, shell path is $(pwd)" + echo "${package_name}" > "${OUTPUT}/artifact_name.txt" } case $SUFFIX.$EXT in