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 | 699cd9c | 2020-05-13 21:24:07 +0200 | [diff] [blame] | 17 | # Dependencies are normally specified via the cla-sysrepo.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 |
| 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áš Pecka | ea0e769 | 2021-08-10 11:21:45 +0200 | [diff] [blame] | 47 | for PROJECT in cla-sysrepo netconf-cli gammarus velia rousette; do |
Jan Kundrát | 6122a6d | 2020-05-14 20:26:38 +0200 | [diff] [blame] | 48 | # 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át | c4e5ee4 | 2022-03-25 00:42:15 +0100 | [diff] [blame] | 57 | # But any change to CzechLight/dependencies is handled explicitly below. |
Jan Kundrát | 6122a6d | 2020-05-14 20:26:38 +0200 | [diff] [blame] | 58 | rm -rf build/${PROJECT}-custom/ per-package/${PROJECT}/ |
| 59 | fi |
| 60 | done |
Jan Kundrát | 32ca34f | 2022-03-23 19:40:44 +0100 | [diff] [blame] | 61 | fi |
Jan Kundrát | 3113807 | 2021-01-19 10:54:45 +0100 | [diff] [blame] | 62 | |
Jan Kundrát | 32ca34f | 2022-03-23 19:40:44 +0100 | [diff] [blame] | 63 | # 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. |
| 70 | HAS_CHANGE_OF_DEPENDENCIES=$(jq < ~/zuul-env.json -r '[.items[]? | select(.project.name == "CzechLight/dependencies")][-1]?.project.src_dir + ""') |
| 71 | if [[ ! -z "${HAS_CHANGE_OF_DEPENDENCIES}" ]]; then |
Jan Kundrát | c4e5ee4 | 2022-03-25 00:42:15 +0100 | [diff] [blame] | 72 | # 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 \ |
Jan Kundrát | 4186a20 | 2023-02-16 00:12:53 +0100 | [diff] [blame^] | 79 | replxx cppcodec sdbus-cpp \ |
Jan Kundrát | c4e5ee4 | 2022-03-25 00:42:15 +0100 | [diff] [blame] | 80 | ; do |
| 81 | rm -rf build/{,host-}${PROJECT}-custom/ per-package/{,host-}${PROJECT}/ |
| 82 | done |
Jan Kundrát | 6122a6d | 2020-05-14 20:26:38 +0200 | [diff] [blame] | 83 | fi |
| 84 | |
Jan Kundrát | 11a48c6 | 2019-03-08 14:44:53 +0100 | [diff] [blame] | 85 | make source -j${CI_PARALLEL_JOBS} --output-sync=target |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 86 | |
Jan Kundrát | 623bf87 | 2019-10-23 18:37:36 +0200 | [diff] [blame] | 87 | make -j${CI_PARALLEL_JOBS} --output-sync=target rootfs-czechlight-rauc |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 88 | mv images/update.raucb ~/zuul-output/artifacts/ |
| 89 | |
Tomáš Pecka | 04eb737 | 2022-06-07 08:03:04 +0200 | [diff] [blame] | 90 | PATH="$PATH:$(pwd)/host/bin/" pytest -vv ${ZUUL_PROJECT_SRC_DIR}/tests/czechlight-cfg-fs/migrations.py |
| 91 | |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 92 | if [[ "${ZUUL_JOB_NAME}" =~ clearfog ]]; then |
Jan Kundrát | d45c104 | 2020-05-14 15:06:42 +0200 | [diff] [blame] | 93 | if [[ ${TRIGGERED_VIA_DEP} != 1 ]]; then |
Jan Kundrát | d45c104 | 2020-05-14 15:06:42 +0200 | [diff] [blame] | 94 | # 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át | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 111 | fi |
| 112 | |
| 113 | # TODO: USB image as well? (`fallocate -d` to make it sparse) |
| 114 | # TODO: make legal-info |