Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -eux -o pipefail |
| 4 | shopt -s failglob |
| 5 | |
| 6 | ZUUL_JOB_NAME=$(jq < ~/zuul-env.json -r '.job') |
Jan Kundrát | df2c7b2 | 2020-05-16 00:11:31 +0200 | [diff] [blame] | 7 | ZUUL_TENANT=$(jq < ~/zuul-env.json -r '.tenant') |
| 8 | ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname') |
| 9 | ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r ".projects[\"${ZUUL_GERRIT_HOSTNAME}/CzechLight/br2-external\"].src_dir") |
| 10 | ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r ".projects[\"${ZUUL_GERRIT_HOSTNAME}/CzechLight/br2-external\"].short_name") |
Jan Kundrát | 11a48c6 | 2019-03-08 14:44:53 +0100 | [diff] [blame] | 11 | CI_PARALLEL_JOBS=$(awk -vcpu=$(getconf _NPROCESSORS_ONLN) 'BEGIN{printf "%.0f", cpu*1.3+1}') |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 12 | |
| 13 | BUILD_DIR=~/build |
| 14 | mkdir ${BUILD_DIR} |
| 15 | cd ${BUILD_DIR} |
| 16 | |
Jan Kundrát | 723e22d | 2023-03-29 14:47:42 +0200 | [diff] [blame] | 17 | # Dependencies are normally specified via the submodules/dependencies.git repo |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 18 | ${ZUUL_PROJECT_SRC_DIR}/dev-setup-git.sh |
| 19 | |
Jan Kundrát | 699cd9c | 2020-05-13 21:24:07 +0200 | [diff] [blame] | 20 | if [[ $(jq < ~/zuul-env.json -r '.project.name') != 'CzechLight/br2-external' ]]; then |
Jan Kundrát | d45c104 | 2020-05-14 15:06:42 +0200 | [diff] [blame] | 21 | TRIGGERED_VIA_DEP=1 |
| 22 | else |
| 23 | TRIGGERED_VIA_DEP=0 |
| 24 | fi |
| 25 | BR2_EXTERNAL_COMMIT=$(git --git-dir ${ZUUL_PROJECT_SRC_DIR}/.git rev-parse HEAD) |
| 26 | |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 27 | if [[ "${ZUUL_JOB_NAME}" =~ clearfog ]]; then |
| 28 | make czechlight_clearfog_defconfig |
Jan Kundrát | 6100cf9 | 2019-12-05 16:01:33 +0100 | [diff] [blame] | 29 | elif [[ "${ZUUL_JOB_NAME}" =~ beagleboneblack ]]; then |
| 30 | make czechlight_beaglebone_defconfig |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 31 | else |
| 32 | echo "Unrecognized job name, cannot determine defconfig target" |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
Jan Kundrát | f5a026c | 2019-06-06 17:01:35 +0200 | [diff] [blame] | 36 | echo BR2_PRIMARY_SITE=\"https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-public/mirror/buildroot\" >> .config |
Jan Kundrát | 6122a6d | 2020-05-14 20:26:38 +0200 | [diff] [blame] | 37 | |
| 38 | if [[ ${TRIGGERED_VIA_DEP} == 1 ]]; then |
Tomáš Pecka | 742c7ec | 2022-10-03 13:49:57 +0200 | [diff] [blame] | 39 | for PROJECT in cla-sysrepo netconf-cli gammarus velia rousette sysrepo-ietf-alarms; do |
Jan Kundrát | 6122a6d | 2020-05-14 20:26:38 +0200 | [diff] [blame] | 40 | # 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át | 6122a6d | 2020-05-14 20:26:38 +0200 | [diff] [blame] | 46 | fi |
| 47 | done |
Jan Kundrát | 32ca34f | 2022-03-23 19:40:44 +0100 | [diff] [blame] | 48 | fi |
Jan Kundrát | 3113807 | 2021-01-19 10:54:45 +0100 | [diff] [blame] | 49 | |
Jan Kundrát | 32ca34f | 2022-03-23 19:40:44 +0100 | [diff] [blame] | 50 | # 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. |
| 57 | HAS_CHANGE_OF_DEPENDENCIES=$(jq < ~/zuul-env.json -r '[.items[]? | select(.project.name == "CzechLight/dependencies")][-1]?.project.src_dir + ""') |
| 58 | if [[ ! -z "${HAS_CHANGE_OF_DEPENDENCIES}" ]]; then |
Jan Kundrát | c4e5ee4 | 2022-03-25 00:42:15 +0100 | [diff] [blame] | 59 | # 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át | 9f07207 | 2023-03-29 15:40:58 +0200 | [diff] [blame] | 61 | fi |
Jan Kundrát | c4e5ee4 | 2022-03-25 00:42:15 +0100 | [diff] [blame] | 62 | |
Jan Kundrát | 9f07207 | 2023-03-29 15:40:58 +0200 | [diff] [blame] | 63 | # Show exact git versions of what we're going to build |
| 64 | bash <<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 |
| 74 | EOF |
| 75 | |
| 76 | if [[ ${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át | c4e5ee4 | 2022-03-25 00:42:15 +0100 | [diff] [blame] | 92 | done |
Jan Kundrát | 6122a6d | 2020-05-14 20:26:38 +0200 | [diff] [blame] | 93 | fi |
| 94 | |
Jan Kundrát | 11a48c6 | 2019-03-08 14:44:53 +0100 | [diff] [blame] | 95 | make source -j${CI_PARALLEL_JOBS} --output-sync=target |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 96 | |
Jan Kundrát | 623bf87 | 2019-10-23 18:37:36 +0200 | [diff] [blame] | 97 | make -j${CI_PARALLEL_JOBS} --output-sync=target rootfs-czechlight-rauc |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 98 | mv images/update.raucb ~/zuul-output/artifacts/ |
| 99 | |
Tomáš Pecka | 04eb737 | 2022-06-07 08:03:04 +0200 | [diff] [blame] | 100 | PATH="$PATH:$(pwd)/host/bin/" pytest -vv ${ZUUL_PROJECT_SRC_DIR}/tests/czechlight-cfg-fs/migrations.py |
| 101 | |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 102 | # TODO: USB image as well? (`fallocate -d` to make it sparse) |
| 103 | # TODO: make legal-info |