Browse Source

Cache the last successful build git commit hash

Teach `bin/ci.sh` to cache the git commit hash of the last successful
build.  Use the cached hash to determine whether building is even
necessary.  This feature introduces a new variable, `HBSD_CACHEDIR`, to
use as cache storage for the build.

Introduce `bin/cleanup.sh`. This script isn't even close to being
complete.

Signed-off-by:	Shawn Webb <shawn.webb@hardenedbsd.org>
pull/4/head
Shawn Webb 10 months ago
parent
commit
fd114df862
Signed by: shawn.webb <shawn.webb@hardenedbsd.org> GPG Key ID: FF2E67A277F8E1FA
6 changed files with 145 additions and 8 deletions
  1. +13
    -4
      bin/ci.sh
  2. +73
    -0
      bin/cleanup.sh
  3. +1
    -4
      lib/build.sh
  4. +2
    -0
      lib/config.sh
  5. +7
    -0
      lib/publish.sh
  6. +49
    -0
      lib/util.sh

+ 13
- 4
bin/ci.sh View File

@@ -60,18 +60,27 @@ main() {
config_set_dynamic

(
assert_unlocked && \
lock_build && \
update_codebase && \
clean_build && \
assert_unlocked && lock_build

update_codebase || exit ${?}

if ! should_build; then
unlock_build
exit 0
fi

clean_build && \
build_hardenedbsd && \
build_release && \
stage_release && \
sign_release && \
publish_release && \
kick_publisher_tires && \
cache_codebase_hashish && \
unlock_build
exit ${?}
) | build_log 2>&1

return ${?}
}



+ 73
- 0
bin/cleanup.sh View File

@@ -0,0 +1,73 @@
#!/bin/sh
#-
# Copyright (c) 2019 HardenedBSD
# Author: Shawn Webb <shawn.webb@hardenedbsd.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

get_topdir() {
local self

self=${1}

echo $(realpath $(dirname ${self}))
return ${?}
}

TOPDIR=$(get_topdir ${0})

. ${TOPDIR}/../lib/build.sh
. ${TOPDIR}/../lib/config.sh
. ${TOPDIR}/../lib/log.sh
. ${TOPDIR}/../lib/publish.sh
. ${TOPDIR}/../lib/util.sh

main() {
local self

self=${0}
shift

config_set_defaults

while getopts 'c:' o; do
case "${o}" in
c)
. ${OPTARG}
;;
esac
done

# TODO: provide our own version of config_set_dynamic
config_set_dynamic

(
assert_unlocked && \
lock_build && \
prune_old_builds && \
unlock_build
) | build_log 2>&1
return ${?}
}

main ${0} $*
exit ${?}

+ 1
- 4
lib/build.sh View File

@@ -120,10 +120,7 @@ stage_release() {
fi
done

(
cd ${HBSD_SRC}
git rev-parse HEAD > ${HBSD_STAGEDIR}/revision.txt
)
codebase_hashish > ${HBSD_STAGEDIR}/revision.txt

return 0
}


+ 2
- 0
lib/config.sh View File

@@ -38,6 +38,8 @@ config_set_defaults() {
HBSD_TARGET_ARCH=amd64
HBSD_NOCLEAN="-DNO_CLEAN"
HBSD_LOGDIR=/build/logs/13-current.amd64
HBSD_KEEP_NBUILDS=10
HBSD_CACHEDIR=/build/cache/13-current.amd64

# Set by config file, contains potentially sensitive data
HBSD_MIRROR_MASTER=""


+ 7
- 0
lib/publish.sh View File

@@ -30,9 +30,16 @@ publish_release() {
}

kick_publisher_tires() {
local res

[ -z "${HBSD_MIRROR_MASTER}" ] && return 0

rsync -a ${HBSD_PUBDIR}/${HBSD_BUILDNUMBER}/ \
${HBSD_MIRROR_MASTER}:${HBSD_MIRROR_PUBDIR}/build-${HBSD_BUILDNUMBER}
res=${?}
if [ ${res} -gt 0 ]; then
return ${res}
fi

return ${?}
}

+ 49
- 0
lib/util.sh View File

@@ -66,6 +66,20 @@ build_number() {
return 0
}

codebase_hashish() {
(
cd ${HBSD_SRC}
git rev-parse HEAD
exit ${?}
)
return ${?}
}

cache_codebase_hashish() {
codebase_hashish > ${HBSD_CACHEDIR}/last_build.txt
return ${?}
}

update_codebase() {
(
set -ex
@@ -75,3 +89,38 @@ update_codebase() {
)
return ${?}
}

should_build() {
local lastbuild
local currenthashish

if [ ! -f ${HBSD_CACHEDIR}/last_build.txt ]; then
return 0
fi

lastbuild=$(cat ${HBSD_CACHEDIR}/last_build.txt)
currenthashish=$(codebase_hashish)

if [ "${lastbuild}" = "${currenthashish}" ]; then
return 1
fi

return 0
}

prune_old_builds() {
[ ${HBSD_BUILDNUMBER} -lt ${HBSD_KEEP_NBUILDS} ] && return 0

return 0

floor=$((${HBSD_BUILDNUMBER} - ${HBSD_KEEP_NBUILDS}))

for d in $(find ${HBSD_PUBDIR} -maxdepth 1 -type d | sed 1d); do
n=$(basename ${d})
if [ ${n} -lt ${floor} ]; then
rm -rf ${d}
fi
done

return 0
}

Loading…
Cancel
Save