From 8dee622603c8aa118af573047e8bac7f055caef5 Mon Sep 17 00:00:00 2001 From: Nicu Siderias Date: Thu, 19 Mar 2026 10:09:02 +0200 Subject: [PATCH] CI: Add workflow to build debian package Add necessary config files and script to build the package Enhance README Signed-off-by: Nicu Siderias --- .github/workflows/deb_build.yml | 73 +++++++++++++++++++++++++++ packaging/README.md | 76 +++++++++++++++++++++++++++++ packaging/VERSION | 1 + packaging/build-adi-scripts-deb.sh | 60 +++++++++++++++++++++++ packaging/debian/changelog.template | 5 ++ packaging/debian/control.template | 13 +++++ packaging/debian/copyright | 34 +++++++++++++ packaging/debian/postinst | 19 ++++++++ packaging/debian/postrm | 29 +++++++++++ packaging/debian/rules | 29 +++++++++++ packaging/debian/source/format | 1 + 11 files changed, 340 insertions(+) create mode 100644 .github/workflows/deb_build.yml create mode 100644 packaging/README.md create mode 100644 packaging/VERSION create mode 100755 packaging/build-adi-scripts-deb.sh create mode 100644 packaging/debian/changelog.template create mode 100644 packaging/debian/control.template create mode 100644 packaging/debian/copyright create mode 100644 packaging/debian/postinst create mode 100644 packaging/debian/postrm create mode 100755 packaging/debian/rules create mode 100644 packaging/debian/source/format diff --git a/.github/workflows/deb_build.yml b/.github/workflows/deb_build.yml new file mode 100644 index 0000000..12f0ef6 --- /dev/null +++ b/.github/workflows/deb_build.yml @@ -0,0 +1,73 @@ +name: Build debian package for Linux ADI-scripts + +on: + push: + branches: + - kuiper2.0 + - '20[1-9][0-9]_R[1-9]' + pull_request: + branches: + - kuiper2.0 + - '20[1-9][0-9]_R[1-9]' +env: + APP_NAME: linux_image_ADI-scripts + +jobs: + build_debian_package: + runs-on: ubuntu-latest + permissions: + id-token: write + steps: + - name: Checkout code repository + uses: actions/checkout@v6 + with: + path: ${{env.APP_NAME}} + - name: Get version from file + run: | + VERSION=$(cat "${{env.APP_NAME}}/packaging/VERSION" 2>/dev/null | tr -d '[:space:]') + # Regex to match semantic versioning (from semver.org) + # Regex will match valid version number https://regex101.com/r/K8FvXg/1 + regex='^((0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?)$' + if ! [[ "$VERSION" =~ $regex ]]; then + echo "WARNING: Invalid or missing version '$VERSION', falling back to 0.0.1" + VERSION="0.0.1" + fi + echo "VERSION=$VERSION" >> "$GITHUB_ENV" + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y build-essential devscripts debhelper gettext + - name: Build debian package + run: | + "${{env.APP_NAME}}/packaging/build-adi-scripts-deb.sh" "${{github.head_ref}}" "${{env.VERSION}}" "${{env.APP_NAME}}" + - name: Upload debian artifacts to github + if: success() && env.PACKAGE_NAME != '' + uses: actions/upload-artifact@v7 + with: + name: ${{env.PACKAGE_NAME}}-${{env.VERSION}}-ubuntu + path: | + ${{env.PACKAGE_NAME}}_*.deb + ${{env.PACKAGE_NAME}}*.dsc + ${{env.PACKAGE_NAME}}*.debian.tar.xz + ${{env.PACKAGE_NAME}}*.orig.tar.gz + if-no-files-found: error + - name: Authenticate with Cloudsmith via OIDC + if: success() && github.event_name == 'push' && env.PACKAGE_NAME != '' + uses: cloudsmith-io/cloudsmith-cli-action@v2.0.2 + with: + oidc-namespace: adi + oidc-service-slug: ${{ secrets.CLOUDSMITH_SERVICE_SLUG }} + + - name: Upload debian package to Cloudsmith + if: success() && env.CLOUDSMITH_API_KEY != '' + run: | + pip install cloudsmith-cli + for f in ${{env.PACKAGE_NAME}}*.dsc ${{env.PACKAGE_NAME}}*.orig.tar.gz ${{env.PACKAGE_NAME}}*.debian.tar.xz; do + [ -f "$f" ] || continue + cloudsmith push raw -SW --republish adi/kuiper-internal "$f" + done + cloudsmith push deb -SW --republish "adi/kuiper-internal/debian/trixie" ${{env.PACKAGE_NAME}}_*.deb + + + + diff --git a/packaging/README.md b/packaging/README.md new file mode 100644 index 0000000..275f2f3 --- /dev/null +++ b/packaging/README.md @@ -0,0 +1,76 @@ +# ADI Scripts Debian Package Builder + +This directory contains the infrastructure to build Debian packages for the [linux_image_ADI-scripts](https://github.com/analogdevicesinc/linux_image_ADI-scripts) repository using debhelper. + +## Overview + +The build system: +1. Builds it using `make` +2. Creates a `.deb` package with debhelper +3. Generates source package files (`.orig.tar.gz`, `.debian.tar.xz`, `.dsc`) + +## Prerequisites + +```bash +sudo apt-get install debhelper devscripts build-essential wget gettext +git clone https://github.com/analogdevicesinc/linux_image_ADI-scripts.git +git checkout kuiper2.0 +``` + +**Note:** This package depends on the `gt` (USB Gadget Tool) package. You should build and install the gt package separately before using the USB gadget functionality. + +## Usage + +### Building the Package + +The script should be run from the parent folder of the entire git repository and call the script + +```bash +linux_image_ADI-scripts/packaging/build-adi-scripts-deb.sh [branch] [version] [clone_dir] +``` + +Parameters: +- `branch`: Branch or tag name (default: `kuiper2.0`) (used for changelog only) +- `version`: Package version (default: `1.0.0`) +- `clone_dir`: Directory where the repository is cloned (default: `linux_image_ADI-scripts`) + +### Example + +```bash +# Build from kuiper2.0 branch with default version +./build-adi-scripts-deb.sh + +# Build from specific branch with custom version +./build-adi-scripts-deb.sh main 1.5 + +# Build from specific branch with custom version and clone directory +./build-adi-scripts-deb.sh main 1.5 /path/to/linux_image_ADI-scripts +``` + +## Output Files + +The build process generates: +- `adi-scripts_.orig.tar.gz` - Upstream source tarball +- `adi-scripts_-1.debian.tar.xz` - Debian packaging files +- `adi-scripts_-1.dsc` - Debian source package descriptor +- `adi-scripts_-1_all.deb` - Binary package (architecture-independent) + +## Package Contents + +The package installs: +- Shell scripts to `/usr/bin/` +- Systemd service files to `/etc/systemd/system/` +- Python scripts to `/usr/share/systemd/` +- Configuration files for lightdm, USB gadget, etc. + +The following systemd services are enabled on installation: +- `adi-power.service` - Power management service +- `fan-control.service` - Fan control service +- `fix-display-port.service` - DisplayPort fix service + +## Notes + +- The package is architecture-independent (`all`) as it contains only shell scripts +- Uses upstream Makefile with `make install DESTDIR=... PREFIX=/usr` +- Systemd services are enabled during package installation via postinst script +- The build process creates both binary and source packages automatically diff --git a/packaging/VERSION b/packaging/VERSION new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/packaging/VERSION @@ -0,0 +1 @@ +1.0.0 diff --git a/packaging/build-adi-scripts-deb.sh b/packaging/build-adi-scripts-deb.sh new file mode 100755 index 0000000..51f3656 --- /dev/null +++ b/packaging/build-adi-scripts-deb.sh @@ -0,0 +1,60 @@ +#!/bin/bash -e + +# Script that generates ADI scripts .deb package and source files using debhelper +# As a prerequire, the repository should be checked out before running this script + + +RELEASE=${1:-kuiper2.0} # Default to kuiper2.0 branch +VERSION=${2:-1.0.0} # Default to version 1.0.0 +UPSTREAM_DIR=${3:-linux_image_ADI-scripts} # Default to linux_image_ADI-scripts + +# Package metadata +PACKAGE="adi-scripts" + +# Set variable for github workflows +[ -n "$GITHUB_ENV" ] && echo "PACKAGE_NAME=$PACKAGE" >> $GITHUB_ENV + +WORK_DIR="${PACKAGE}-${VERSION}" + +# Rename extracted directory to match Debian conventions +cp -a ${UPSTREAM_DIR} ${WORK_DIR} + +# Create the orig tarball with exclusions +echo "Creating source tarball with exclusions..." +tar czf ${PACKAGE}_${VERSION}.orig.tar.gz \ + --exclude='.git' \ + ${WORK_DIR} + +# Substitute variables in templates +cd ${WORK_DIR} + +# Copy debian directory into the extracted source tree +cp -r packaging/debian . + +# Export all variables for envsubst and debian/rules +export VERSION PACKAGE RELEASE +export DATE=$(date -R) + +# Create changelog entry +CHANGELOG_ENTRY="Build from ${RELEASE} branch" +export CHANGELOG_ENTRY + +# Substitute templates +envsubst < debian/control.template > debian/control +envsubst < debian/changelog.template > debian/changelog + +# Remove template files +rm debian/*.template + +# Build package using debhelper (builds both binary and source packages) +echo "Building packages..." +dpkg-buildpackage -us -uc + +cd .. + +echo "" +echo "Build complete! Generated files:" +echo " - ${PACKAGE}_${VERSION}.orig.tar.gz (upstream source)" +echo " - ${PACKAGE}_${VERSION}-1.debian.tar.xz (debian files)" +echo " - ${PACKAGE}_${VERSION}-1.dsc (source descriptor)" +echo " - ${PACKAGE}_${VERSION}-1_all.deb (binary package)" diff --git a/packaging/debian/changelog.template b/packaging/debian/changelog.template new file mode 100644 index 0000000..1fa7bbc --- /dev/null +++ b/packaging/debian/changelog.template @@ -0,0 +1,5 @@ +${PACKAGE} (${VERSION}-1) stable; urgency=medium + + * ${CHANGELOG_ENTRY} + + -- Engineerzone ${DATE} diff --git a/packaging/debian/control.template b/packaging/debian/control.template new file mode 100644 index 0000000..fdbaa83 --- /dev/null +++ b/packaging/debian/control.template @@ -0,0 +1,13 @@ +Source: ${PACKAGE} +Section: utils +Priority: optional +Maintainer: Engineerzone +Build-Depends: debhelper-compat (= 13) +Standards-Version: 4.6.2 +Homepage: https://github.com/analogdevicesinc/linux_image_ADI-scripts + +Package: ${PACKAGE} +Architecture: all +Depends: ${shlibs:Depends}, ${misc:Depends}, bash, wget, systemd, gt (>= 1.0) +Description: ADI Linux system configuration and test scripts + This package contains shell scripts for configuring and testing Analog Devices hardware on Linux systems, including power management, USB gadget configuration, and various device test scripts. diff --git a/packaging/debian/copyright b/packaging/debian/copyright new file mode 100644 index 0000000..b98b395 --- /dev/null +++ b/packaging/debian/copyright @@ -0,0 +1,34 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: linux_image_ADI-scripts +Upstream-Contact: Analog Devices, Inc. +Source: https://github.com/analogdevicesinc/linux_image_ADI-scripts + +Files: * +Copyright: 2018, Analog Devices Inc. +License: BSD-3-Clause + +License: BSD-3-Clause + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + . + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + . + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + . + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + . + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packaging/debian/postinst b/packaging/debian/postinst new file mode 100644 index 0000000..bfda64a --- /dev/null +++ b/packaging/debian/postinst @@ -0,0 +1,19 @@ +#!/bin/bash -e + +if [ "$1" = "configure" ]; then + if command -v systemctl >/dev/null 2>&1; then + systemctl enable adi-power.service || true + systemctl enable fan-control.service || true + systemctl enable fix-display-port.service || true + systemctl enable gt.service || true + systemctl enable gt-start.service || true + systemctl enable gt.target || true + systemctl enable iiod_ffs.service || true + systemctl enable iiod_context_attr.service || true + systemctl enable dev-iio_ffs.mount || true + + systemctl daemon-reload || true + fi +fi + +exit 0 diff --git a/packaging/debian/postrm b/packaging/debian/postrm new file mode 100644 index 0000000..621aa7a --- /dev/null +++ b/packaging/debian/postrm @@ -0,0 +1,29 @@ +#!/bin/bash -e + +if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then + if command -v systemctl >/dev/null 2>&1; then + systemctl disable adi-power.service 2>/dev/null || true + systemctl disable fan-control.service 2>/dev/null || true + systemctl disable fix-display-port.service 2>/dev/null || true + systemctl disable gt.service 2>/dev/null || true + systemctl disable gt-start.service 2>/dev/null || true + systemctl disable gt.target 2>/dev/null || true + systemctl disable iiod_ffs.service 2>/dev/null || true + systemctl disable iiod_context_attr.service 2>/dev/null || true + systemctl disable dev-iio_ffs.mount 2>/dev/null || true + + systemctl stop adi-power.service 2>/dev/null || true + systemctl stop fan-control.service 2>/dev/null || true + systemctl stop fix-display-port.service 2>/dev/null || true + systemctl stop gt.service 2>/dev/null || true + systemctl stop gt-start.service 2>/dev/null || true + systemctl stop gt.target 2>/dev/null || true + systemctl stop iiod_ffs.service 2>/dev/null || true + systemctl stop iiod_context_attr.service 2>/dev/null || true + systemctl stop dev-iio_ffs.mount 2>/dev/null || true + + systemctl daemon-reload || true + fi +fi + +exit 0 diff --git a/packaging/debian/rules b/packaging/debian/rules new file mode 100755 index 0000000..6c2388f --- /dev/null +++ b/packaging/debian/rules @@ -0,0 +1,29 @@ +#!/usr/bin/make -f + +PACKAGE ?= adi-scripts + +export DH_VERBOSE = 1 + +%: + dh $@ + +override_dh_auto_clean: + # Nothing to clean - no build artifacts + : + +override_dh_auto_configure: + # No configuration needed + : + +override_dh_auto_build: + # Nothing to build - shell scripts only + : + +override_dh_auto_install: + # Use upstream Makefile with DESTDIR and PREFIX support + # Makefile installs all files: scripts, services, USB gadget files, configs + $(MAKE) install DESTDIR=$(CURDIR)/debian/$(PACKAGE) PREFIX=/usr + +override_dh_auto_test: + # Skip tests + : diff --git a/packaging/debian/source/format b/packaging/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/packaging/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt)