blob: 4fced8e713e581f2b25210209e6a1c7f0960b47f [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
27# If we're being triggered via a change against another repo, use speculatively merged stuff from Zuul, not our submodules
28if [[ ${TRIGGERED_VIA_DEP} == 1 ]]; then
Jan Kundrát699cd9c2020-05-13 21:24:07 +020029 # 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át699cd9c2020-05-13 21:24:07 +020042fi
43
Jan Kundráta4fbff22019-03-01 11:03:21 +010044if [[ "${ZUUL_JOB_NAME}" =~ clearfog ]]; then
45 make czechlight_clearfog_defconfig
Jan Kundrát6100cf92019-12-05 16:01:33 +010046elif [[ "${ZUUL_JOB_NAME}" =~ beagleboneblack ]]; then
47 make czechlight_beaglebone_defconfig
Jan Kundráta4fbff22019-03-01 11:03:21 +010048else
49 echo "Unrecognized job name, cannot determine defconfig target"
50 exit 1
51fi
52
Jan Kundrátf5a026c2019-06-06 17:01:35 +020053echo 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 +020054
55if [[ ${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
Tomáš Pecka785ceb32020-10-15 18:28:47 +020064 for PROJECT in cla-sysrepo netconf-cli gammarus velia lldp-systemd-networkd-sysrepo; do
Jan Kundrát6122a6d2020-05-14 20:26:38 +020065 # 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
77fi
78
Jan Kundrát11a48c62019-03-08 14:44:53 +010079make source -j${CI_PARALLEL_JOBS} --output-sync=target
Jan Kundráta4fbff22019-03-01 11:03:21 +010080
Jan Kundrát623bf872019-10-23 18:37:36 +020081make -j${CI_PARALLEL_JOBS} --output-sync=target rootfs-czechlight-rauc
Jan Kundráta4fbff22019-03-01 11:03:21 +010082mv images/update.raucb ~/zuul-output/artifacts/
83
84if [[ "${ZUUL_JOB_NAME}" =~ clearfog ]]; then
Jan Kundrátd45c1042020-05-14 15:06:42 +020085 if [[ ${TRIGGERED_VIA_DEP} != 1 ]]; then
86 mv images/u-boot-spl.kwb ~/zuul-output/artifacts/
87
88 # store a cached tarball as an artifact
89 ARTIFACT=br2-work-dir-${BR2_EXTERNAL_COMMIT}.tar.zst
90 # everything but local.mk which we might have adjusted in job prologue, so let's not overwrite that
91 tar --totals -c \
92 --exclude='images/rootfs.*' \
93 --exclude='images/sdcard.*' \
94 --exclude='images/usb-flash.*' \
95 .br* \
96 build \
97 .config \
98 host \
99 images \
100 Makefile \
101 per-package \
102 target \
103 | zstd -T0 > ~/zuul-output/artifacts/${ARTIFACT}
104 fi
Jan Kundráta4fbff22019-03-01 11:03:21 +0100105fi
106
107# TODO: USB image as well? (`fallocate -d` to make it sparse)
108# TODO: make legal-info