From aa810b33e8143be17b018ec58d4c5c0dd0ede17c Mon Sep 17 00:00:00 2001 From: Carlos Mogas da Silva Date: Tue, 3 Dec 2024 18:33:26 +0000 Subject: [PATCH] Initial try on an action to build RPM packages --- .forgejo/workflows/build.yml | 22 ++++++++++++++++++++ Dockerfile | 9 +++++++++ action.yml | 26 ++++++++++++++++++++++++ entrypoint.sh | 39 ++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 .forgejo/workflows/build.yml create mode 100644 Dockerfile create mode 100644 action.yml create mode 100644 entrypoint.sh diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml new file mode 100644 index 0000000..2a4bc92 --- /dev/null +++ b/.forgejo/workflows/build.yml @@ -0,0 +1,22 @@ +name: Build docker image + +on: [push] + +jobs: + build-and-publish: + runs-on: ubuntu-22.04 + + env: + DOCKER_HOST: ${{ vars.DOCKER_HOST }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build & Publish + uses: https://codeberg.org/umglurf/kaniko-action@main + with: + credentials: | + code.r3pek.org=${{ github.repository_owner }}:${{ secrets.PUBLISH_TOKEN }} + destinations: | + code.r3pek.org/${{ github.repository }}:latest + push: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e04c2dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM fedora:41 + +RUN dnf update -y && dnf upgrade -y; \ + dnf install -y mock rpmdevtools + +COPY entrypoint.sh / +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] + diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..98bedc3 --- /dev/null +++ b/action.yml @@ -0,0 +1,26 @@ +name: "RPM Build" +description: "Builds RPMs for a target system from a spec file" + +inputs: + spec: + description: "Path to the spec file" + required: true + system: + description: "System target to build the package" + required: true + arch: + description: "Target arch to build the package" + required: true + default: "x86_64" + +outputs: + rpm: + description: "Path to the generated rpm file" + +runs: + using: "docker" + image: "Dockerfile" + args: + - ${{ inputs.spec }} + - ${{ inputs.system }} + - ${{ inputs.arch }} diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..5d4b270 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +SPEC=$1 +SYSTEM=$2 +ARCH=$3 + +SPEC_NAME=$(basename ${SPEC}) +CONFIGURATION="${SYSTEM}-${ARCH}" + +echo "Building ${SPEC_NAME} for ${CONFIGURATION}" + +echo "::group::Building SRPM" +cd $(dirname ${SPEC}) + +spectool -g ${SPEC} +if [ $? -ne 0 ]; then + echo "::error Failed to download sources" + exit 1 +fi + +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::" + +SRPM=$(grep Wrote result/build.log | cut -d" " -f 2) + +echo "::group::Building RPM" +mock -r "${SYSTEM}-${ARCH}" --resultdir result ${SRPM} +if [ $? -ne 0 ]; then + echo "::error Failed to build RPM" + exit 1 +fi +echo "::endgroup::" + +RPM=i$(grep Wrote result/build.log | grep "/RPMS/" | cut -d" " -f 2) +echo "rpm=${RPM}" >> ${GITHUB_OUTPUT}