Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIC-3082: ci: github: Build in all branches #50

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/build-rootfs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# YAML -*- mode: yaml; tab-width: 2; indent-tabs-mode: nil; coding: utf-8 -*-
---
name: Build in rootfs for arch

on: # yamllint disable-line rule:truthy
push:
tags:
- '*'
jobs:
build:
runs-on: ubuntu-24.04
strategy:
matrix:
arch:
- amd64
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- id: describe
name: Describe HEAD
run: |
echo "describe=$(git describe --tags --always || echo 0)" | tee $GITHUB_OUTPUT
- name: Setup and build
run: |
ARCH=${{ matrix.arch }} ./scripts/build-rootfs.sh
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-${{ steps.describe.outputs.describe }}-${{ matrix.arch }}
path: build/dist/
- name: Upload Release Asset
id: upload-release-asset
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: build/dist/*
38 changes: 28 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
name: Docker Image CI
# YAML -*- mode: yaml; tab-width: 2; indent-tabs-mode: nil; coding: utf-8 -*-
---

on:
name: Build in docker

on: # yamllint disable-line rule:truthy
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]

jobs:
build:
env:
project-name: unifysdk # This should be lowercase for docker (and aligned)
runs-on: ubuntu-22.04
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Build Docker image from sources
run: docker build .
- uses: actions/[email protected]
with:
fetch-depth: 0
- id: describe
name: Describe HEAD
run: >-
echo "describe=$(git describe --tags --always || echo 0)"
| tee $GITHUB_OUTPUT
- name: Build Docker image from sources
run: docker build --tag "${{ env.project-name }}:latest" .
- name: Extract artifacts
run: >-
container=$(docker create "${{ env.project-name }}:latest")
&& docker cp
${container}:/usr/local/opt/${{ env.project-name }}/build/dist .
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
# yamllint disable-line
name: ${{ github.event.repository.name }}-${{ steps.describe.outputs.describe }}
path: dist/
20 changes: 17 additions & 3 deletions helper.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ SELF?=${CURDIR}/helper.mk

project?=unifysdk

# Allow overloading from env if needed
BUILD_DEV_GUI?=OFF

CMAKE_GENERATOR?=Ninja
export CMAKE_GENERATOR

Expand All @@ -25,7 +28,6 @@ packages+=nlohmann-json3-dev
# TODO: remove for offline build
packages+=curl wget python3-pip
packages+=time
packages+=yarnpkg

rust_url?=https://sh.rustup.rs
RUST_VERSION?=1.65.0
Expand All @@ -34,10 +36,17 @@ export PATH := ${HOME}/.cargo/bin:${PATH}
zpc_exe?=${build_dir}/applications/zpc/zpc
exes+=${zpc_exe}

# Allow overloading from env if needed
ifeq (${BUILD_DEV_GUI}, ON)
packages+=nodejs
packages+=yarnpkg
endif


zpc_cmake_options?=\
-DBUILD_AOXPC=OFF \
-DBUILD_CPCD=OFF \
-DBUILD_DEV_GUI=ON \
-DBUILD_DEV_GUI=${BUILD_DEV_GUI} \
-DBUILD_EMD=OFF \
-DBUILD_EPC=OFF \
-DBUILD_GMS=OFF \
Expand Down Expand Up @@ -150,6 +159,11 @@ test: ${build_dir}

check: test

dist: ${build_dir}
cmake --build $< --target package
install -d $</$@
cp -av ${<}/*.deb $</$@

distclean:
rm -rf ${build_dir}

Expand All @@ -167,7 +181,7 @@ zpc/build: zpc/configure build
zpc/test: ${build_dir}/applications/zpc/components/zwave_command_classes/test/
ctest --test-dir ${<}

zpc/default: zpc/configure zpc/build zpc/test
zpc/default: zpc/configure zpc/build zpc/test dist
@date -u

### @rootfs is faster than docker for env check
Expand Down
125 changes: 125 additions & 0 deletions scripts/build-rootfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#! /usr/bin/env bash
# -*- mode: Bash; tab-width: 2; indent-tabs-mode: nil; coding: utf-8 -*-
# vim:shiftwidth=4:softtabstop=4:tabstop=4:
# SPDX-License-Identifier: LicenseRef-MSLA
# SPDX-FileCopyrightText: Silicon Laboratories Inc. https://www.silabs.com

set -e
set -x

cat<<EOF
Usage:

ARCH=arm64 ./scripts/build-rootfs.sh
EOF

project="unifysdk"
debian_suite="bookworm"

# Can be overloaded from env eg: ARCH=arm64"
target_debian_arch=${ARCH:="$(dpkg --print-architecture)"}

debian_mirror_url="http://deb.debian.org/debian"
sudo="sudo"
machine="${project}-${debian_suite}-${target_debian_arch}-rootfs"
rootfs_dir="/var/tmp/var/lib/machines/${machine}"
MAKE="/usr/bin/make"
CURDIR="$PWD"
chroot="systemd-nspawn"
packages="debootstrap \
binfmt-support \
debian-archive-keyring \
qemu-user-static \
systemd-container \
time \
"
case $target_debian_arch in
amd64)
export CMAKE_SYSTEM_PROCESSOR="x86_64"
export CARGO_TARGET_TRIPLE="${CMAKE_SYSTEM_PROCESSOR}-unknown-linux-gnu"
packages="${packages} qemu-system-x86"
qemu_system="qemu-system-${CMAKE_SYSTEM_PROCESSOR}"
;;

arm64)
qemu_arch="aarch64"
qemu_system="qemu-system-${qemu_arch}"
export CMAKE_SYSTEM_PROCESSOR="${qemu_arch}"
export CARGO_TARGET_TRIPLE="${CMAKE_SYSTEM_PROCESSOR}-unknown-linux-gnu"
packages="${packages} qemu-system-arm"
;;

*)
CMAKE_SYSTEM_PROCESSOR="$ARCH"
CARGO_TARGET_TRIPLE="${CMAKE_SYSTEM_PROCESSOR}-unknown-linux-gnu"
qemu_arch="${ARCH}"
qemu_system="qemu-system-${qemu_arch}"
echo "error: Not supported yet"

exit 1
;;
esac

${sudo} apt-get update
${sudo} apt install -y ${packages}
if [ -e "/var/lib/binfmts/qemu-${qemu_arch}" ]; then
${sudo} update-binfmts --enable "qemu-${qemu_arch}"
fi
qemu_file="/usr/bin/${qemu_system}"

if [ ! -d "${rootfs_dir}" ] ; then
${sudo} mkdir -pv "${rootfs_dir}"
time ${sudo} debootstrap \
--arch="${target_debian_arch}" \
"${debian_suite}" "${rootfs_dir}" "${debian_mirror_url}"
${sudo} chmod -v u+rX "${rootfs_dir}"
fi

# TODO: https://github.com/rust-lang/cargo/issues/8719#issuecomment-1516492970
env_vars="$env_vars CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse"

# TODO: https://github.com/rust-lang/cargo/issues/10583
env_vars="$env_vars CARGO_NET_GIT_FETCH_WITH_CLI=true"

cargo_dir="/tmp/$USER/${machine}/${HOME}/.cargo"
${sudo} mkdir -pv "${cargo_dir}"

case ${chroot} in
"systemd-nspawn")
rootfs_shell="${sudo} systemd-nspawn \
--directory="${rootfs_dir}" \
--machine="${machine}" \
--bind="${CURDIR}:${CURDIR}" \
--bind="${cargo_dir}:/root/.cargo" \
"
if [ -e "${qemu_file}" ] ; then
rootfs_shell="$rootfs_shell --bind ${qemu_file}"
fi
;;
*)
rootfs_shell="${sudo} chroot ${rootfs_dir}"
l="dev dev/pts sys proc"
for t in $l ; do
$sudo mkdir -p "${rootfs_dir}/$t"
$sudo mount --bind "/$t" "${rootfs_dir}/$t"
done
;;
esac

${rootfs_shell} \
apt-get install -y -- make sudo util-linux

${rootfs_shell} \
${MAKE} \
--directory="${CURDIR}" \
--file="${CURDIR}/helper.mk" \
USER="${USER}" \
${env_vars} \
-- \
help setup default \
target_debian_arch="${target_debian_arch}" \
CMAKE_SYSTEM_PROCESSOR="${CMAKE_SYSTEM_PROCESSOR}" \
CARGO_TARGET_TRIPLE="${CARGO_TARGET_TRIPLE}" \
# EoL

sudo du -hs "/var/tmp/var/lib/machines/${machine}"