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 | |
| 27 | # If we're being triggered via a change against another repo, use speculatively merged stuff from Zuul, not our submodules |
| 28 | if [[ ${TRIGGERED_VIA_DEP} == 1 ]]; then |
Jan Kundrát | 699cd9c | 2020-05-13 21:24:07 +0200 | [diff] [blame] | 29 | # C++ dependencies can be provided either via cla-sysrepo, or via netconf-cli. |
| 30 | # Whatever is the latest change in the queue wins. |
| 31 | USE_DEPENDENCIES_VIA=$(jq < ~/zuul-env.json -r '[.items[]? | select(.project.name == "CzechLight/cla-sysrepo" or .project.name == "CzechLight/netconf-cli")][-1]?.project.src_dir + ""') |
| 32 | if [[ ! -z "${USE_DEPENDENCIES_VIA}" ]]; then |
| 33 | sed -i "s|${ZUUL_PROJECT_SRC_DIR}/submodules/cla-sysrepo/submodules/dependencies/|${HOME}/${USE_DEPENDENCIES_VIA}/submodules/dependencies/|g" local.mk |
| 34 | # Our Zuul playbook only prepares submodules within CzechLight/br2-external, not submodules of other projects |
| 35 | pushd ${HOME}/${USE_DEPENDENCIES_VIA} |
| 36 | # ...and before we check out, make sure that relative URLs work, i.e,. no file:///dev/null |
| 37 | git config remote.origin.url $(pwd) |
| 38 | git submodule update --init --recursive |
| 39 | git config remote.origin.url file:///dev/null |
| 40 | popd |
| 41 | fi |
Jan Kundrát | 699cd9c | 2020-05-13 21:24:07 +0200 | [diff] [blame] | 42 | fi |
| 43 | |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 44 | if [[ "${ZUUL_JOB_NAME}" =~ clearfog ]]; then |
| 45 | make czechlight_clearfog_defconfig |
Jan Kundrát | 6100cf9 | 2019-12-05 16:01:33 +0100 | [diff] [blame] | 46 | elif [[ "${ZUUL_JOB_NAME}" =~ beagleboneblack ]]; then |
| 47 | make czechlight_beaglebone_defconfig |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 48 | else |
| 49 | echo "Unrecognized job name, cannot determine defconfig target" |
| 50 | exit 1 |
| 51 | fi |
| 52 | |
Jan Kundrát | f5a026c | 2019-06-06 17:01:35 +0200 | [diff] [blame] | 53 | 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] | 54 | |
| 55 | if [[ ${TRIGGERED_VIA_DEP} == 1 ]]; then |
| 56 | ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "br2-work-dir") | select(.project == "CzechLight/br2-external")][-1]?.url + ""') |
| 57 | if [[ -z "${ARTIFACT_URL}" ]]; then |
| 58 | # no job ahead, try to use git commit ID |
| 59 | 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" |
| 60 | fi |
| 61 | # 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 |
| 62 | curl ${ARTIFACT_URL} | unzstd --stdout | tar -xf - || echo "No Buildroot prebuilt tarball found, will build from scratch" |
| 63 | |
Jan Kundrát | 02cbb81 | 2021-03-02 10:13:35 +0100 | [diff] [blame] | 64 | for PROJECT in cla-sysrepo netconf-cli gammarus velia rousette lldp-systemd-networkd-sysrepo; do |
Jan Kundrát | 6122a6d | 2020-05-14 20:26:38 +0200 | [diff] [blame] | 65 | # If there's a change for ${PROJECT} queued ahead, ensure it gets used. |
| 66 | # This means that if our submodules still pin, say, `cla-sysrepo` to some ancient version and we're testing a `netconf-cli` change, |
| 67 | # then we will keep using that ancient `cla-sysrepo`. Hopefully this reduces the number of false alerts. |
| 68 | DEPSRCDIR=$(jq < ~/zuul-env.json -r "[.items[]? | select(.project.name == \"CzechLight/${PROJECT}\")][-1]?.project.src_dir + \"\"") |
| 69 | if [[ ! -z "${DEPSRCDIR}" ]]; then |
| 70 | sed -i "s|${ZUUL_PROJECT_SRC_DIR}/submodules/${PROJECT}|${HOME}/${DEPSRCDIR}|g" local.mk |
| 71 | |
| 72 | # `make ${pkg}-reconfigure` is *not* enough with BR2_PER_PACKAGE_DIRECTORIES=y |
| 73 | # Even this is possibly fragile if these packages were not the "leaf" ones (in terms of BR-level dependencies). |
| 74 | rm -rf build/${PROJECT}-custom/ per-package/${PROJECT}/ |
| 75 | fi |
| 76 | done |
Jan Kundrát | 3113807 | 2021-01-19 10:54:45 +0100 | [diff] [blame] | 77 | |
| 78 | # Is there a change ahead which updates CzechLight/dependencies? If so, make sure these will get rebuilt |
| 79 | # This is (still) not foolproof. It will use a wrong version of dependencies if that change has been already merged, but br2-external doesn't have it merged |
| 80 | HAS_CHANGE_OF_DEPENDENCIES=$(jq < ~/zuul-env.json -r '[.items[]? | select(.project.name == "CzechLight/dependencies")][-1]?.project.src_dir + ""') |
| 81 | if [[ ! -z "${HAS_CHANGE_OF_DEPENDENCIES}" ]]; then |
| 82 | for PROJECT in libyang sysrepo libnetconf2 netopeer2; do |
| 83 | rm -rf build/{,host-}${PROJECT}-custom/ per-package/{,host-}${PROJECT}/ |
| 84 | done |
| 85 | fi |
Jan Kundrát | 6122a6d | 2020-05-14 20:26:38 +0200 | [diff] [blame] | 86 | fi |
| 87 | |
Jan Kundrát | 11a48c6 | 2019-03-08 14:44:53 +0100 | [diff] [blame] | 88 | make source -j${CI_PARALLEL_JOBS} --output-sync=target |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 89 | |
Jan Kundrát | 623bf87 | 2019-10-23 18:37:36 +0200 | [diff] [blame] | 90 | make -j${CI_PARALLEL_JOBS} --output-sync=target rootfs-czechlight-rauc |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 91 | mv images/update.raucb ~/zuul-output/artifacts/ |
| 92 | |
| 93 | if [[ "${ZUUL_JOB_NAME}" =~ clearfog ]]; then |
Jan Kundrát | d45c104 | 2020-05-14 15:06:42 +0200 | [diff] [blame] | 94 | if [[ ${TRIGGERED_VIA_DEP} != 1 ]]; then |
Jan Kundrát | d45c104 | 2020-05-14 15:06:42 +0200 | [diff] [blame] | 95 | # store a cached tarball as an artifact |
| 96 | ARTIFACT=br2-work-dir-${BR2_EXTERNAL_COMMIT}.tar.zst |
| 97 | # everything but local.mk which we might have adjusted in job prologue, so let's not overwrite that |
| 98 | tar --totals -c \ |
| 99 | --exclude='images/rootfs.*' \ |
| 100 | --exclude='images/sdcard.*' \ |
| 101 | --exclude='images/usb-flash.*' \ |
| 102 | .br* \ |
| 103 | build \ |
| 104 | .config \ |
| 105 | host \ |
| 106 | images \ |
| 107 | Makefile \ |
| 108 | per-package \ |
| 109 | target \ |
| 110 | | zstd -T0 > ~/zuul-output/artifacts/${ARTIFACT} |
| 111 | fi |
Jan Kundrát | a4fbff2 | 2019-03-01 11:03:21 +0100 | [diff] [blame] | 112 | fi |
| 113 | |
| 114 | # TODO: USB image as well? (`fallocate -d` to make it sparse) |
| 115 | # TODO: make legal-info |