blob: 14e73bb645b85e395ae5b4179f02ed826dc38be9 [file] [log] [blame]
Jan Kundráta4fbff22019-03-01 11:03:21 +01001#!/bin/bash
2
3set -eux -o pipefail
4shopt -s failglob
5
6ZUUL_JOB_NAME=$(jq < ~/zuul-env.json -r '.job')
Jan Kundrátdf2c7b22020-05-16 00:11:31 +02007ZUUL_TENANT=$(jq < ~/zuul-env.json -r '.tenant')
8ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname')
9ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r ".projects[\"${ZUUL_GERRIT_HOSTNAME}/CzechLight/br2-external\"].src_dir")
10ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r ".projects[\"${ZUUL_GERRIT_HOSTNAME}/CzechLight/br2-external\"].short_name")
Jan Kundrát11a48c62019-03-08 14:44:53 +010011CI_PARALLEL_JOBS=$(awk -vcpu=$(getconf _NPROCESSORS_ONLN) 'BEGIN{printf "%.0f", cpu*1.3+1}')
Jan Kundráta4fbff22019-03-01 11:03:21 +010012
13BUILD_DIR=~/build
14mkdir ${BUILD_DIR}
15cd ${BUILD_DIR}
16
Jan Kundrát699cd9c2020-05-13 21:24:07 +020017# Dependencies are normally specified via the cla-sysrepo.git repo
Jan Kundráta4fbff22019-03-01 11:03:21 +010018${ZUUL_PROJECT_SRC_DIR}/dev-setup-git.sh
19
Jan Kundrát699cd9c2020-05-13 21:24:07 +020020if [[ $(jq < ~/zuul-env.json -r '.project.name') != 'CzechLight/br2-external' ]]; then
Jan Kundrátd45c1042020-05-14 15:06:42 +020021 TRIGGERED_VIA_DEP=1
22else
23 TRIGGERED_VIA_DEP=0
24fi
25BR2_EXTERNAL_COMMIT=$(git --git-dir ${ZUUL_PROJECT_SRC_DIR}/.git rev-parse HEAD)
26
Jan Kundráta4fbff22019-03-01 11:03:21 +010027if [[ "${ZUUL_JOB_NAME}" =~ clearfog ]]; then
28 make czechlight_clearfog_defconfig
Jan Kundrát6100cf92019-12-05 16:01:33 +010029elif [[ "${ZUUL_JOB_NAME}" =~ beagleboneblack ]]; then
30 make czechlight_beaglebone_defconfig
Jan Kundráta4fbff22019-03-01 11:03:21 +010031else
32 echo "Unrecognized job name, cannot determine defconfig target"
33 exit 1
34fi
35
Jan Kundrátf5a026c2019-06-06 17:01:35 +020036echo BR2_PRIMARY_SITE=\"https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-public/mirror/buildroot\" >> .config
Jan Kundrát6122a6d2020-05-14 20:26:38 +020037
38if [[ ${TRIGGERED_VIA_DEP} == 1 ]]; then
39 ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "br2-work-dir") | select(.project == "CzechLight/br2-external")][-1]?.url + ""')
40 if [[ -z "${ARTIFACT_URL}" ]]; then
41 # no job ahead, try to use git commit ID
42 ARTIFACT_URL="https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-${ZUUL_TENANT}/${ZUUL_GERRIT_HOSTNAME}/CzechLight/br2-external/${ZUUL_JOB_NAME}/br2-work-dir-${BR2_EXTERNAL_COMMIT}.tar.zst"
43 fi
44 # We don't use gating, so there's a risk that there's no prebuilt artifact, so don't die if we cannot download that file
45 curl ${ARTIFACT_URL} | unzstd --stdout | tar -xf - || echo "No Buildroot prebuilt tarball found, will build from scratch"
46
Tomáš Peckaea0e7692021-08-10 11:21:45 +020047 for PROJECT in cla-sysrepo netconf-cli gammarus velia rousette; do
Jan Kundrát6122a6d2020-05-14 20:26:38 +020048 # If there's a change for ${PROJECT} queued ahead, ensure it gets used.
49 # This means that if our submodules still pin, say, `cla-sysrepo` to some ancient version and we're testing a `netconf-cli` change,
50 # then we will keep using that ancient `cla-sysrepo`. Hopefully this reduces the number of false alerts.
51 DEPSRCDIR=$(jq < ~/zuul-env.json -r "[.items[]? | select(.project.name == \"CzechLight/${PROJECT}\")][-1]?.project.src_dir + \"\"")
52 if [[ ! -z "${DEPSRCDIR}" ]]; then
53 sed -i "s|${ZUUL_PROJECT_SRC_DIR}/submodules/${PROJECT}|${HOME}/${DEPSRCDIR}|g" local.mk
54
55 # `make ${pkg}-reconfigure` is *not* enough with BR2_PER_PACKAGE_DIRECTORIES=y
56 # Even this is possibly fragile if these packages were not the "leaf" ones (in terms of BR-level dependencies).
Jan Kundrátc4e5ee42022-03-25 00:42:15 +010057 # But any change to CzechLight/dependencies is handled explicitly below.
Jan Kundrát6122a6d2020-05-14 20:26:38 +020058 rm -rf build/${PROJECT}-custom/ per-package/${PROJECT}/
59 fi
60 done
Jan Kundrát32ca34f2022-03-23 19:40:44 +010061fi
Jan Kundrát31138072021-01-19 10:54:45 +010062
Jan Kundrát32ca34f2022-03-23 19:40:44 +010063# Is there a change ahead which updates CzechLight/dependencies? If so, make sure these will get rebuilt.
64# This is fragile; if we're triggered via an external module (e.g., `netconf-cli`) and its corresponding change
65# depends on a backwards-incompatible update in the NETCONF stack, and the other projects (e.g., `velia`) have not
66# been updated yet, this will result in a potentially broken result of the build.
67# We cannot simply rebuild all C++ leaf projects either, because we're being triggered one-at-a-time. Since Zuul
68# requires (some) build job ordering, there will always be at least one repo which is "too new" for the rest of the leaf projects.
69# After a "big" update there should always be a standalone sync to `br2-external` as the very last step anyway.
70HAS_CHANGE_OF_DEPENDENCIES=$(jq < ~/zuul-env.json -r '[.items[]? | select(.project.name == "CzechLight/dependencies")][-1]?.project.src_dir + ""')
71if [[ ! -z "${HAS_CHANGE_OF_DEPENDENCIES}" ]]; then
Jan Kundrátc4e5ee42022-03-25 00:42:15 +010072 # redirect BR packages to a Zuul-injected dependency
73 sed -i "s|${ZUUL_PROJECT_SRC_DIR}/submodules/dependencies|${HOME}/${HAS_CHANGE_OF_DEPENDENCIES}|g" local.mk
74
75 # persuade BR to rebuild them
76 for PROJECT in \
77 libyang sysrepo libnetconf2 netopeer2 \
78 libyang-cpp sysrepo-cpp \
79 docopt-cpp replxx cppcodec sdbus-cpp \
80 ; do
81 rm -rf build/{,host-}${PROJECT}-custom/ per-package/{,host-}${PROJECT}/
82 done
Jan Kundrát6122a6d2020-05-14 20:26:38 +020083fi
84
Jan Kundrát11a48c62019-03-08 14:44:53 +010085make source -j${CI_PARALLEL_JOBS} --output-sync=target
Jan Kundráta4fbff22019-03-01 11:03:21 +010086
Jan Kundrát623bf872019-10-23 18:37:36 +020087make -j${CI_PARALLEL_JOBS} --output-sync=target rootfs-czechlight-rauc
Jan Kundráta4fbff22019-03-01 11:03:21 +010088mv images/update.raucb ~/zuul-output/artifacts/
89
Tomáš Pecka04eb7372022-06-07 08:03:04 +020090PATH="$PATH:$(pwd)/host/bin/" pytest -vv ${ZUUL_PROJECT_SRC_DIR}/tests/czechlight-cfg-fs/migrations.py
91
Jan Kundráta4fbff22019-03-01 11:03:21 +010092if [[ "${ZUUL_JOB_NAME}" =~ clearfog ]]; then
Jan Kundrátd45c1042020-05-14 15:06:42 +020093 if [[ ${TRIGGERED_VIA_DEP} != 1 ]]; then
Jan Kundrátd45c1042020-05-14 15:06:42 +020094 # store a cached tarball as an artifact
95 ARTIFACT=br2-work-dir-${BR2_EXTERNAL_COMMIT}.tar.zst
96 # everything but local.mk which we might have adjusted in job prologue, so let's not overwrite that
97 tar --totals -c \
98 --exclude='images/rootfs.*' \
99 --exclude='images/sdcard.*' \
100 --exclude='images/usb-flash.*' \
101 .br* \
102 build \
103 .config \
104 host \
105 images \
106 Makefile \
107 per-package \
108 target \
109 | zstd -T0 > ~/zuul-output/artifacts/${ARTIFACT}
110 fi
Jan Kundráta4fbff22019-03-01 11:03:21 +0100111fi
112
113# TODO: USB image as well? (`fallocate -d` to make it sparse)
114# TODO: make legal-info