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