Build CI packages outside target rootfs #60
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ################################################################################ | |
| # OpenHD | |
| # | |
| # Licensed under the GNU General Public License (GPL) Version 3. | |
| # | |
| # This software is provided "as-is," without warranty of any kind, express or | |
| # implied, including but not limited to the warranties of merchantability, | |
| # fitness for a particular purpose, and non-infringement. For details, see the | |
| # full license in the LICENSE file provided with this source code. | |
| # | |
| # Non-Military Use Only: | |
| # This software and its associated components are explicitly intended for | |
| # civilian and non-military purposes. Use in any military or defense | |
| # applications is strictly prohibited unless explicitly and individually | |
| # licensed otherwise by the OpenHD Team. | |
| # | |
| # Contributors: | |
| # A full list of contributors can be found at the OpenHD GitHub repository: | |
| # https://github.com/OpenHD | |
| # | |
| # © OpenHD, All Rights Reserved. | |
| ################################################################################ | |
| name: build_glide_platform_packages | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - "main" | |
| - "dev-release" | |
| - "release" | |
| - "openhd-3.0" | |
| jobs: | |
| build: | |
| runs-on: ubuntu-22.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - image_type: radxa-zero3w | |
| package_suffix: radxa-zero3w | |
| package_arch: arm64 | |
| cloudsmith_distro: debian | |
| release: bookworm | |
| require_rkmpp: "1" | |
| extra_debian_depends: "gstreamer1.0-tools, gstreamer1.0-plugins-base, gstreamer1.0-plugins-good, gstreamer1.0-plugins-bad, gstreamer1.0-plugins-ugly, gstreamer1.0-libav, gstreamer1.0-rockchip1, librockchip-mpp1, librga2" | |
| - image_type: radxa-cubie | |
| package_suffix: radxa-cubie | |
| package_arch: arm64 | |
| cloudsmith_distro: debian | |
| release: bullseye | |
| require_rkmpp: "0" | |
| extra_debian_depends: "gstreamer1.0-tools, gstreamer1.0-plugins-base, gstreamer1.0-plugins-good, gstreamer1.0-plugins-bad, gstreamer1.0-plugins-ugly, gstreamer1.0-libav" | |
| - image_type: rock5a | |
| package_suffix: rock5a | |
| package_arch: arm64 | |
| cloudsmith_distro: debian | |
| release: bookworm | |
| require_rkmpp: "1" | |
| extra_debian_depends: "gstreamer1.0-tools, gstreamer1.0-plugins-base, gstreamer1.0-plugins-good, gstreamer1.0-plugins-bad, gstreamer1.0-plugins-ugly, gstreamer1.0-libav, gstreamer1.0-rockchip1, librockchip-mpp1, librga2" | |
| - image_type: rock5b | |
| package_suffix: rock5b | |
| package_arch: arm64 | |
| cloudsmith_distro: debian | |
| release: bookworm | |
| require_rkmpp: "1" | |
| extra_debian_depends: "gstreamer1.0-tools, gstreamer1.0-plugins-base, gstreamer1.0-plugins-good, gstreamer1.0-plugins-bad, gstreamer1.0-plugins-ugly, gstreamer1.0-libav, gstreamer1.0-rockchip1, librockchip-mpp1, librga2" | |
| - image_type: radxa-cm5 | |
| package_suffix: radxa-cm5 | |
| package_arch: arm64 | |
| cloudsmith_distro: debian | |
| release: bookworm | |
| require_rkmpp: "1" | |
| extra_debian_depends: "gstreamer1.0-tools, gstreamer1.0-plugins-base, gstreamer1.0-plugins-good, gstreamer1.0-plugins-bad, gstreamer1.0-plugins-ugly, gstreamer1.0-libav, gstreamer1.0-rockchip1, librockchip-mpp1, librga2" | |
| env: | |
| CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }} | |
| API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }} | |
| steps: | |
| - name: Maximize build space | |
| uses: easimon/maximize-build-space@master | |
| with: | |
| root-reserve-mb: 512 | |
| swap-size-mb: 1024 | |
| remove-dotnet: "true" | |
| remove-android: "true" | |
| remove-haskell: "true" | |
| overprovision-lvm: "true" | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Build OpenHD-Glide in CHROOT | |
| run: | | |
| git clone https://github.com/OpenHD/OpenHD-ChrootCompiler /opt/OpenHD-ChrootCompiler | |
| mkdir -p /opt/OpenHD-ChrootCompiler/additionalFiles | |
| cp -a "$GITHUB_WORKSPACE/." /opt/OpenHD-ChrootCompiler/additionalFiles/ | |
| printf '%s\n' "$CLOUDSMITH_API_KEY" > /opt/OpenHD-ChrootCompiler/additionalFiles/cloudsmith_api_key.txt | |
| echo "standard" > /opt/OpenHD-ChrootCompiler/additionalFiles/custom.txt | |
| echo "${{ matrix.package_arch }}" > /opt/OpenHD-ChrootCompiler/additionalFiles/arch.txt | |
| echo "${{ matrix.cloudsmith_distro }}" > /opt/OpenHD-ChrootCompiler/additionalFiles/distro.txt | |
| echo "${{ matrix.release }}" > /opt/OpenHD-ChrootCompiler/additionalFiles/flavor.txt | |
| echo "${{ github.ref_name }}" > /opt/OpenHD-ChrootCompiler/additionalFiles/repo.txt | |
| cat << 'EOF' > /opt/OpenHD-ChrootCompiler/additionalFiles/build_chroot.sh | |
| #!/bin/bash | |
| set -euo pipefail | |
| chmod 1777 /tmp || true | |
| export DEBIAN_FRONTEND=noninteractive | |
| mkdir -p /out/apt-archives/partial | |
| cat >/etc/apt/apt.conf.d/99openhd-ci-cache-dir <<'APT_CONF' | |
| Dir::Cache::archives "/out/apt-archives"; | |
| APT_CONF | |
| apt-get clean | |
| if [ -d /etc/apt/sources.list.d ]; then | |
| sudo sed -i 's/^#deb /deb /' /etc/apt/sources.list.d/*.list 2>/dev/null || true | |
| fi | |
| target_release="$(cat flavor.txt 2>/dev/null || true)" | |
| if [ "${target_release}" = "bookworm" ]; then | |
| for source_file in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do | |
| [ -f "${source_file}" ] && sudo sed -i '\|radxa-repo.github.io/bullseye|d' "${source_file}" | |
| done | |
| for source_file in /etc/apt/sources.list.d/*.sources; do | |
| [ -f "${source_file}" ] && grep -q 'radxa-repo.github.io/bullseye' "${source_file}" && sudo rm -f "${source_file}" | |
| done | |
| fi | |
| apt-get update --fix-missing | |
| graphics_dev_packages=( | |
| libdrm-dev | |
| libgbm-dev | |
| libgles2-mesa-dev | |
| libegl1-mesa-dev | |
| ) | |
| graphics_runtime_packages=( | |
| libdrm2 | |
| libdrm-radeon1 | |
| libdrm-nouveau2 | |
| libdrm-amdgpu1 | |
| libgbm1 | |
| libegl-mesa0 | |
| libglapi-mesa | |
| ) | |
| if apt-cache policy libdrm2 libgbm1 | awk '/Installed:|Candidate:/ && /~bpo/ { found = 1 } END { exit(found ? 0 : 1) }'; then | |
| apt-get install -y -t bookworm-backports "${graphics_runtime_packages[@]}" | |
| apt-get install -y -t bookworm-backports "${graphics_dev_packages[@]}" | |
| else | |
| apt-get install -y "${graphics_dev_packages[@]}" | |
| fi | |
| apt-get remove -y gstreamer1.0-plugins-rtp || true | |
| install_exact_runtime_for_dev_package() { | |
| local dev_package="$1" | |
| local runtime_package="$2" | |
| local dev_version | |
| local runtime_version | |
| dev_version="$(apt-cache policy "${dev_package}" | awk '/Candidate:/ { print $2; exit }')" | |
| if [ -z "${dev_version}" ] || [ "${dev_version}" = "(none)" ]; then | |
| return 0 | |
| fi | |
| runtime_version="$( | |
| apt-cache show "${dev_package}=${dev_version}" 2>/dev/null \ | |
| | awk -v runtime="${runtime_package}" ' | |
| $1 == "Depends:" { | |
| for (i = 2; i <= NF; ++i) { | |
| if ($i == runtime && $(i + 1) == "(=") { | |
| gsub(/[),]/, "", $(i + 2)) | |
| print $(i + 2) | |
| exit | |
| } | |
| } | |
| }' | |
| )" | |
| if [ -n "${runtime_version}" ]; then | |
| apt-get install -y --allow-downgrades "${runtime_package}=${runtime_version}" | |
| fi | |
| } | |
| install_exact_runtime_for_dev_package libgstreamer1.0-dev libgstreamer1.0-0 | |
| install_exact_runtime_for_dev_package libgstreamer-plugins-base1.0-dev libgstreamer-plugins-base1.0-0 | |
| apt-get install -y \ | |
| build-essential \ | |
| ca-certificates \ | |
| git \ | |
| python3-pip \ | |
| pkg-config \ | |
| zlib1g-dev \ | |
| libfreetype-dev \ | |
| libgstreamer1.0-dev \ | |
| libgstreamer-plugins-base1.0-dev \ | |
| gstreamer1.0-tools \ | |
| gstreamer1.0-plugins-base \ | |
| gstreamer1.0-plugins-good \ | |
| gstreamer1.0-plugins-bad \ | |
| gstreamer1.0-plugins-ugly \ | |
| gstreamer1.0-libav | |
| require_rkmpp="$(cat require_rkmpp.txt)" | |
| if [ "${require_rkmpp}" = "1" ]; then | |
| apt-get install -y librockchip-mpp-dev librga-dev gstreamer1.0-rockchip1 | |
| fi | |
| apt-get install -y cmake || true | |
| cmake_ge_320() { | |
| if ! command -v cmake >/dev/null 2>&1; then | |
| return 1 | |
| fi | |
| version="$(cmake --version | awk 'NR==1{print $3}')" | |
| dpkg --compare-versions "$version" ge "3.20" | |
| } | |
| if ! cmake_ge_320; then | |
| pip3 install --upgrade cmake || pip3 install --upgrade cmake --break-system-packages | |
| fi | |
| cmake --version | |
| package_suffix="$(cat package_suffix.txt)" | |
| package_version="$(cat package_version.txt)" | |
| package_arch="$(cat package_arch.txt)" | |
| extra_debian_depends="$(cat extra_debian_depends.txt)" | |
| build_dir="/out/build-package-${package_suffix}" | |
| rm -rf "${build_dir}" | |
| build_jobs="$(nproc)" | |
| if [ "${package_suffix}" = "radxa-cubie" ]; then | |
| build_jobs=1 | |
| fi | |
| cmake_args=( | |
| -S . \ | |
| -B "${build_dir}" \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DOPENHD_GLIDE_DEVICE_KMS=ON \ | |
| -DOPENHD_GLIDE_REQUIRE_KMS_GBM=ON \ | |
| -DOPENHD_GLIDE_REQUIRE_GSTREAMER=ON \ | |
| -DOPENHD_GLIDE_PACKAGE_SUFFIX="-${package_suffix}" \ | |
| -DOPENHD_GLIDE_PACKAGE_VERSION="${package_version}" \ | |
| -DOPENHD_GLIDE_PACKAGE_ARCHITECTURE="${package_arch}" \ | |
| -DOPENHD_GLIDE_EXTRA_DEBIAN_DEPENDS="${extra_debian_depends}" | |
| ) | |
| if [ "${require_rkmpp}" = "1" ]; then | |
| cmake_args+=(-DOPENHD_GLIDE_REQUIRE_RKMPP=ON) | |
| fi | |
| cmake "${cmake_args[@]}" | |
| cmake --build "${build_dir}" -j"${build_jobs}" | |
| cmake --build "${build_dir}" --target package | |
| package_file="$(find "${build_dir}" -maxdepth 1 -name '*.deb' -print -quit)" | |
| dpkg-deb -f "${package_file}" Depends | |
| for required in \ | |
| gstreamer1.0-tools \ | |
| gstreamer1.0-plugins-base \ | |
| gstreamer1.0-plugins-good \ | |
| gstreamer1.0-plugins-bad \ | |
| gstreamer1.0-plugins-ugly \ | |
| gstreamer1.0-libav; do | |
| dpkg-deb -f "${package_file}" Depends | grep -q "${required}" | |
| done | |
| if [ "${require_rkmpp}" = "1" ]; then | |
| for required in \ | |
| gstreamer1.0-rockchip1 \ | |
| librockchip-mpp1 \ | |
| librga2; do | |
| dpkg-deb -f "${package_file}" Depends | grep -q "${required}" | |
| done | |
| fi | |
| rm -rf /out/apt-archives | |
| cp "${build_dir}"/*.deb /out/ | |
| rm -rf "${build_dir}" | |
| EOF | |
| chmod +x /opt/OpenHD-ChrootCompiler/additionalFiles/build_chroot.sh | |
| echo "${{ matrix.package_suffix }}" > /opt/OpenHD-ChrootCompiler/additionalFiles/package_suffix.txt | |
| echo "${{ matrix.package_arch }}" > /opt/OpenHD-ChrootCompiler/additionalFiles/package_arch.txt | |
| echo "${{ matrix.require_rkmpp }}" > /opt/OpenHD-ChrootCompiler/additionalFiles/require_rkmpp.txt | |
| echo "${{ matrix.extra_debian_depends }}" > /opt/OpenHD-ChrootCompiler/additionalFiles/extra_debian_depends.txt | |
| echo "0.1.0.${{ github.run_number }}" > /opt/OpenHD-ChrootCompiler/additionalFiles/package_version.txt | |
| cd /opt/OpenHD-ChrootCompiler/ | |
| sudo apt update | |
| sudo bash install_dep.sh | |
| python3 - <<'PY' | |
| import re | |
| from pathlib import Path | |
| packages_stage = Path("/opt/OpenHD-ChrootCompiler/stages/02-Packages/00-run-chroot.sh") | |
| packages_text = packages_stage.read_text() | |
| packages_marker = "remove_legacy_radxa_bullseye_sources" | |
| packages_needle = 'echo "_______________________Starting build____________________________"\n' | |
| packages_patch = ( | |
| packages_needle | |
| + "\n" | |
| + f"{packages_marker}() {{\n" | |
| + " if [[ \"${DISTRO}\" != \"bookworm\" ]]; then\n" | |
| + " return 0\n" | |
| + " fi\n" | |
| + " echo \"[apt-preflight] Normalizing Bookworm apt sources...\"\n" | |
| + " sudo rm -f /etc/apt/sources.list /etc/apt/sources.list.d/openhd-bookworm.sources /etc/apt/sources.list.d/openhd-bookworm.list\n" | |
| + " while IFS= read -r -d '' source_file; do\n" | |
| + " if grep -Eq 'archive\\.debian\\.org|deb\\.debian\\.org/debian|security\\.debian\\.org/debian-security|download\\.vscodium\\.com|radxa-repo\\.github\\.io/bullseye' \"${source_file}\"; then\n" | |
| + " sudo rm -f \"${source_file}\"\n" | |
| + " fi\n" | |
| + " done < <(find /etc/apt/sources.list.d -type f \\( -name '*.list' -o -name '*.sources' \\) -print0 2>/dev/null)\n" | |
| + " sudo tee /etc/apt/sources.list.d/openhd-bookworm.list >/dev/null <<'APT_SOURCES'\n" | |
| + "deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware\n" | |
| + "deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware\n" | |
| + "deb http://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware\n" | |
| + "deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware\n" | |
| + "APT_SOURCES\n" | |
| + " sudo tee /etc/apt/apt.conf.d/99openhd-ci-minimal-indexes >/dev/null <<'APT_CONF'\n" | |
| + "Acquire::Languages \"none\";\n" | |
| + "Acquire::IndexTargets::deb::DEP-11::DefaultEnabled \"false\";\n" | |
| + "Acquire::IndexTargets::deb::DEP-11-icons-small::DefaultEnabled \"false\";\n" | |
| + "Acquire::IndexTargets::deb::DEP-11-icons::DefaultEnabled \"false\";\n" | |
| + "APT_CONF\n" | |
| + " sudo mkdir -p /out/apt-archives/partial\n" | |
| + " sudo tee /etc/apt/apt.conf.d/99openhd-ci-cache-dir >/dev/null <<'APT_CONF'\n" | |
| + "Dir::Cache::archives \"/out/apt-archives\";\n" | |
| + "APT_CONF\n" | |
| + " sudo rm -rf /var/lib/apt/lists/*\n" | |
| + " sudo apt-get clean\n" | |
| + "}\n" | |
| + "apt() {\n" | |
| + " if [[ \"${1:-}\" == \"update\" ]]; then\n" | |
| + f" {packages_marker}\n" | |
| + " fi\n" | |
| + " command apt \"$@\"\n" | |
| + "}\n" | |
| + "apt-get() {\n" | |
| + " if [[ \"${1:-}\" == \"update\" ]]; then\n" | |
| + f" {packages_marker}\n" | |
| + " fi\n" | |
| + " command apt-get \"$@\"\n" | |
| + "}\n" | |
| + f"{packages_marker}\n" | |
| ) | |
| if packages_marker not in packages_text: | |
| if packages_needle not in packages_text: | |
| raise SystemExit("Could not find package-stage build marker in ChrootCompiler") | |
| packages_stage.write_text(packages_text.replace(packages_needle, packages_patch, 1)) | |
| packages_text = packages_stage.read_text() | |
| rock5_bookworm_guard_marker = "# openhd_glide_bookworm_guard_rock5_preflight" | |
| rock5_func_needle = " normalize_bullseye_sources() {\n" | |
| if rock5_bookworm_guard_marker not in packages_text and rock5_func_needle in packages_text: | |
| rock5_func_patch = ( | |
| f" {rock5_bookworm_guard_marker}\n" | |
| + rock5_func_needle | |
| + " if [[ \"${DISTRO}\" == \"bookworm\" ]]; then\n" | |
| + f" {packages_marker}\n" | |
| + " return 0\n" | |
| + " fi\n" | |
| ) | |
| packages_text = packages_text.replace(rock5_func_needle, rock5_func_patch, 1) | |
| packages_stage.write_text(packages_text) | |
| packages_text = packages_stage.read_text() | |
| apt_update_marker = "# openhd_glide_patch_apt_update_calls" | |
| if apt_update_marker not in packages_text: | |
| packages_text = packages_text.replace("set -e\n", f"set -e\n\n{apt_update_marker}\n", 1) | |
| apt_update_pattern = re.compile(r"^([ \t]*)((?:sudo\s+)?apt(?:-get)?\s+update(?:\s+.*)?)$", re.MULTILINE) | |
| packages_text = apt_update_pattern.sub( | |
| lambda match: f"{match.group(1)}{packages_marker}\n{match.group(1)}{match.group(2)}", | |
| packages_text, | |
| ) | |
| packages_stage.write_text(packages_text) | |
| build_sh = Path("/opt/OpenHD-ChrootCompiler/build.sh") | |
| text = build_sh.read_text() | |
| original = text | |
| imagebuilder_clone_old = "git clone https://github.com/OpenHD/OpenHD-ImageBuilder\n" | |
| imagebuilder_clone_new = "git clone --branch dev-release --single-branch https://github.com/OpenHD/OpenHD-ImageBuilder\n" | |
| if imagebuilder_clone_new not in text: | |
| if imagebuilder_clone_old not in text: | |
| raise SystemExit("Could not find ImageBuilder clone in build.sh") | |
| text = text.replace(imagebuilder_clone_old, imagebuilder_clone_new, 1) | |
| image_needle = "mv OpenHD-ImageBuilder/images .\n" | |
| image_patch = ( | |
| image_needle | |
| + "for board in radxa-zero3w radxa-cubie rock5a rock5b radxa-cm5; do\n" | |
| + " if [ ! -f \"images/${board}\" ] && [ -f \"images/${board}_base\" ]; then\n" | |
| + " cp \"images/${board}_base\" \"images/${board}\"\n" | |
| + " fi\n" | |
| + "done\n" | |
| ) | |
| if "radxa-cubie rock5a rock5b radxa-cm5" not in text: | |
| if image_needle not in text: | |
| raise SystemExit("Could not find ImageBuilder image import in build.sh") | |
| text = text.replace(image_needle, image_patch, 1) | |
| if "export BASE_IMAGE_SHA512" not in text: | |
| text = text.replace( | |
| "export BASE_IMAGE_SHA256\n", | |
| "export BASE_IMAGE_SHA256\nexport BASE_IMAGE_SHA512\n", | |
| 1, | |
| ) | |
| needle = "mv OpenHD-ImageBuilder/stages/01-Baseimage stages/\n" | |
| patch = ( | |
| needle | |
| + "python3 - <<'PATCH_IMAGE_SIZE'\n" | |
| + "from pathlib import Path\n" | |
| + "stage = Path('stages/01-Baseimage/01-run.sh')\n" | |
| + "stage_text = stage.read_text()\n" | |
| + "old = '''if [[ \"${OS}\" == radxa-debian-rock5a ]] || [[ \"${OS}\" == radxa-debian-rock5b ]];then\n" | |
| + " WANTEDSIZE=\"6800000000\"\n" | |
| + " else\n" | |
| + " WANTEDSIZE=\"${ROOT_IMAGE_SIZE_BYTES:-5632000000}\"\n" | |
| + " fi'''\n" | |
| + "new = '''if [[ \"${OS}\" == radxa-debian-rock5b ]]; then\n" | |
| + " WANTEDSIZE=\"22000000000\"\n" | |
| + " elif [[ \"${OS}\" == radxa-debian-rock5a ]]; then\n" | |
| + " WANTEDSIZE=\"15000000000\"\n" | |
| + " else\n" | |
| + " WANTEDSIZE=\"${ROOT_IMAGE_SIZE_BYTES:-5632000000}\"\n" | |
| + " fi'''\n" | |
| + "if new not in stage_text:\n" | |
| + " if old not in stage_text:\n" | |
| + " raise SystemExit('Could not find Rock5 image size block')\n" | |
| + " stage.write_text(stage_text.replace(old, new, 1))\n" | |
| + "PATCH_IMAGE_SIZE\n" | |
| ) | |
| if "PATCH_IMAGE_SIZE" not in text: | |
| if needle not in text: | |
| raise SystemExit("Could not find ImageBuilder stage import in build.sh") | |
| text = text.replace(needle, patch, 1) | |
| if text != original: | |
| build_sh.write_text(text) | |
| PY | |
| sudo bash build.sh "${{ matrix.image_type }}" "$API_KEY" debian "${{ matrix.release }}" | |
| - name: Collect artifacts | |
| run: | | |
| cp -r /opt/OpenHD-ChrootCompiler/out/* . | |
| - name: Upload to Github | |
| uses: "actions/upload-artifact@v4" | |
| with: | |
| name: "OpenHD-Glide-${{ matrix.package_suffix }}-${{ matrix.release }}-${{ matrix.package_arch }}" | |
| path: | | |
| *.deb | |
| - name: Push | |
| if: github.ref_name == 'release' || github.ref_name == 'dev-release' || github.ref_name == 'main' | |
| uses: cloudsmith-io/action@master | |
| with: | |
| api-key: ${{ secrets.CLOUDSMITH_API_KEY }} | |
| command: "push" | |
| format: "deb" | |
| owner: "openhd" | |
| repo: ${{ github.ref_name == 'main' && 'dev-release' || github.ref_name }} | |
| distro: "${{ matrix.cloudsmith_distro }}" | |
| release: "${{ matrix.release }}" | |
| republish: "true" | |
| file: "*.deb" |