From 8841a1df542bc5a16466114e19eea321a554abb1 Mon Sep 17 00:00:00 2001 From: Carlos Mogas da Silva Date: Thu, 5 Dec 2024 15:38:41 +0000 Subject: [PATCH] Implement working on a array of spec files Forgejo Runner doesn't support dynamic matrix jobs (where the input comes from output of another job). To work around this, accept a list of spec files to process and run the same thing over and over. Might still have to fix the output. --- action.yml | 4 +-- entrypoint.sh | 76 ++++++++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/action.yml b/action.yml index 1fc4e51..42b224f 100644 --- a/action.yml +++ b/action.yml @@ -2,8 +2,8 @@ name: "RPM Build" description: "Builds RPMs for a target system from a spec file" inputs: - spec: - description: "Path to the spec file" + specs: + description: "Paths to the spec files" required: true system: description: "System target to build the package" diff --git a/entrypoint.sh b/entrypoint.sh index d80a363..dd4efe0 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,48 +1,56 @@ #!/bin/bash -SPEC=${INPUT_SPEC} +# SPECS should be a JSON array of all the to-process spec files +# Forgejo runner doesn't support dynamic matrix jobs so, this has to be made this way +# Convert the JSON array to a bash array and iterate over it +readarray -t SPECS < <(echo ${INPUT_SPECS} | jq -c .[] | tr -d '"') +echo "::debug::specs: ${SPECS}" SYSTEM=${INPUT_SYSTEM} ARCH=${INPUT_ARCH} NOCHECK=${INPUT_NOCHECK} -SPEC_NAME=$(basename ${SPEC}) -CONFIGURATION="${SYSTEM}-${ARCH}" -echo "::debug::spec file: ${INPUT_SPEC}" -echo "::debug::target: ${INPUT_SYSTEM}-${INPUT_ARCH}" -echo "::debug::nocheck: ${INPUT_NOCHECK}" +for SPEC in ${SPECS[@]}; do + SPEC_NAME=$(basename ${SPEC}) + CONFIGURATION="${SYSTEM}-${ARCH}" -echo "Building ${SPEC_NAME} for ${CONFIGURATION}" + echo "::debug::spec file: ${INPUT_SPEC}" + echo "::debug::target: ${INPUT_SYSTEM}-${INPUT_ARCH}" + echo "::debug::nocheck: ${INPUT_NOCHECK}" -echo "::group::Building SRPM" -cd $(dirname ${SPEC}) + echo "Building ${SPEC_NAME} for ${CONFIGURATION}" -spectool -g ${SPEC} -if [ $? -ne 0 ]; then - echo "::error::Failed to download sources" - exit 1 -fi + echo "::group::Building SRPM" + cd $(dirname ${SPEC}) -mock -r "${SYSTEM}-${ARCH}" --buildsrpm --spec ${SPEC_NAME} --sources . --resultdir result -if [ $? -ne 0 ]; then - echo "::error::Failed to build SRPM" - exit 1 -fi -echo "::endgroup::" + spectool -g ${SPEC} + if [ $? -ne 0 ]; then + echo "::error::Failed to download sources" + exit 1 + fi -SRPM=$(grep Wrote result/build.log | cut -d" " -f 2) + mock -r "${SYSTEM}-${ARCH}" --buildsrpm --spec ${SPEC_NAME} --sources . --resultdir result + if [ $? -ne 0 ]; then + echo "::error::Failed to build SRPM" + exit 1 + fi + echo "::endgroup::" -echo "::group::Building RPM" -OPTS="" -if [ ${NOCHECK,,} == "true"]; then - OPTS="${OPTS} --nocheck" -fi -mock -r "${SYSTEM}-${ARCH}" --resultdir result ${OPTS} ${SRPM} -if [ $? -ne 0 ]; then - echo "::error::Failed to build RPM" - exit 1 -fi -echo "::endgroup::" + SRPM=$(grep Wrote result/build.log | cut -d" " -f 2) -RPM=i$(grep Wrote result/build.log | grep "/RPMS/" | cut -d" " -f 2) -echo "rpm=${RPM}" >> ${GITHUB_OUTPUT} + echo "::group::Building RPM" + OPTS="" + if [ ${NOCHECK,,} == "true"]; then + OPTS="${OPTS} --nocheck" + fi + mock -r "${SYSTEM}-${ARCH}" --resultdir result ${OPTS} ${SRPM} + if [ $? -ne 0 ]; then + echo "::error::Failed to build RPM" + exit 1 + fi + echo "::endgroup::" + + RPMS=i$(grep Wrote result/build.log | grep "/RPMS/" | cut -d" " -f 2) + echo "::debug::rpms: ${RPMS}" + echo "rpms=${RPMS}" >> ${GITHUB_OUTPUT} +done