blob: 96acdeb8f61604a3498f3b78e2d63f019bbafeb8 [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át723e22d2023-03-29 14:47:42 +020017# Dependencies are normally specified via the submodules/dependencies.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
Tomáš Pecka742c7ec2022-10-03 13:49:57 +020039 for PROJECT in cla-sysrepo netconf-cli gammarus velia rousette sysrepo-ietf-alarms; do
Jan Kundrát6122a6d2020-05-14 20:26:38 +020040 # If there's a change for ${PROJECT} queued ahead, ensure it gets used.
41 # This means that if our submodules still pin, say, `cla-sysrepo` to some ancient version and we're testing a `netconf-cli` change,
42 # then we will keep using that ancient `cla-sysrepo`. Hopefully this reduces the number of false alerts.
43 DEPSRCDIR=$(jq < ~/zuul-env.json -r "[.items[]? | select(.project.name == \"CzechLight/${PROJECT}\")][-1]?.project.src_dir + \"\"")
44 if [[ ! -z "${DEPSRCDIR}" ]]; then
45 sed -i "s|${ZUUL_PROJECT_SRC_DIR}/submodules/${PROJECT}|${HOME}/${DEPSRCDIR}|g" local.mk
Jan Kundrát6122a6d2020-05-14 20:26:38 +020046 fi
47 done
Jan Kundrát32ca34f2022-03-23 19:40:44 +010048fi
Jan Kundrát31138072021-01-19 10:54:45 +010049
Jan Kundrát32ca34f2022-03-23 19:40:44 +010050# Is there a change ahead which updates CzechLight/dependencies? If so, make sure these will get rebuilt.
51# This is fragile; if we're triggered via an external module (e.g., `netconf-cli`) and its corresponding change
52# depends on a backwards-incompatible update in the NETCONF stack, and the other projects (e.g., `velia`) have not
53# been updated yet, this will result in a potentially broken result of the build.
54# We cannot simply rebuild all C++ leaf projects either, because we're being triggered one-at-a-time. Since Zuul
55# requires (some) build job ordering, there will always be at least one repo which is "too new" for the rest of the leaf projects.
56# After a "big" update there should always be a standalone sync to `br2-external` as the very last step anyway.
57HAS_CHANGE_OF_DEPENDENCIES=$(jq < ~/zuul-env.json -r '[.items[]? | select(.project.name == "CzechLight/dependencies")][-1]?.project.src_dir + ""')
58if [[ ! -z "${HAS_CHANGE_OF_DEPENDENCIES}" ]]; then
Jan Kundrátc4e5ee42022-03-25 00:42:15 +010059 # redirect BR packages to a Zuul-injected dependency
60 sed -i "s|${ZUUL_PROJECT_SRC_DIR}/submodules/dependencies|${HOME}/${HAS_CHANGE_OF_DEPENDENCIES}|g" local.mk
Jan Kundrát9f072072023-03-29 15:40:58 +020061fi
Jan Kundrátc4e5ee42022-03-25 00:42:15 +010062
Jan Kundrát9f072072023-03-29 15:40:58 +020063# Show exact git versions of what we're going to build
64bash <<EOF
65 # Extract variables from Makefile into the env
66 eval \$(make -E "all:" -pn -f local.mk | grep _OVERRIDE_SRCDIR | sed -E "s/^(.*) = /export \\1=/")
67 for PROJ in {libyang,sysrepo,libnetconf2}{,-cpp} netopeer2 cla-sysrepo netconf-cli gammarus velia rousette; do
68 # indirect substitution involves the usual joy in bash
69 export PROJ_UCASE=\${PROJ@U}
70 export PROJ_DIR=\${PROJ_UCASE//-/_}_OVERRIDE_SRCDIR
71 cd \${!PROJ_DIR}
72 echo \${PROJ}: \$(git describe --dirty --long --always --tags)
73 done
74EOF
75
76if [[ ${TRIGGERED_VIA_DEP} == 0 ]]; then
77 # Zuul is building a direct change to br2-external. This is by definition the "last change" in the current CI job.
78 # There might be other changes for subsequent jobs, but that doesn't matter right now.
79 # Ensure that the submodules are already pinned to whatever was provided to Zuul through the `Depends-on` commit footers.
80 # In other words, it's an error if we push a change to br2-external which `Depends-on` on a change of some other repo,
81 # but that other repo is not explicitly synced in that change to br2-external.
82 for PROJECT in dependencies cla-sysrepo netconf-cli gammarus velia rousette; do
83 DEPSRCDIR=$(jq < ~/zuul-env.json -r "[.items[]? | select(.project.name == \"CzechLight/${PROJECT}\")][-1]?.project.src_dir + \"\"")
84 if [[ ! -z "${DEPSRCDIR}" ]]; then
85 COMMIT_IN_BR2_EXT=$(cd ${ZUUL_PROJECT_SRC_DIR}/submodules/${PROJECT}; git rev-parse HEAD)
86 COMMIT_VIA_ZUUL=$(cd ${HOME}/${DEPSRCDIR}; git rev-parse HEAD)
87 if [[ ${COMMIT_IN_BR2_EXT} != ${COMMIT_VIA_ZUUL} ]]; then
88 echo "br2-external says submodules/${PROJECT} is ${COMMIT_IN_BR2_EXT}, but Zuul prepared ${COMMIT_VIA_ZUUL} instead"
89 exit 1
90 fi
91 fi
Jan Kundrátc4e5ee42022-03-25 00:42:15 +010092 done
Jan Kundrát6122a6d2020-05-14 20:26:38 +020093fi
94
Jan Kundrát11a48c62019-03-08 14:44:53 +010095make source -j${CI_PARALLEL_JOBS} --output-sync=target
Jan Kundráta4fbff22019-03-01 11:03:21 +010096
Jan Kundrát623bf872019-10-23 18:37:36 +020097make -j${CI_PARALLEL_JOBS} --output-sync=target rootfs-czechlight-rauc
Jan Kundráta4fbff22019-03-01 11:03:21 +010098mv images/update.raucb ~/zuul-output/artifacts/
99
Tomáš Pecka04eb7372022-06-07 08:03:04 +0200100PATH="$PATH:$(pwd)/host/bin/" pytest -vv ${ZUUL_PROJECT_SRC_DIR}/tests/czechlight-cfg-fs/migrations.py
101
Jan Kundráta4fbff22019-03-01 11:03:21 +0100102# TODO: USB image as well? (`fallocate -d` to make it sparse)
103# TODO: make legal-info