Introduce explicit build mode and clean up code

This commit introduces an explicit build mode in get-mods.sh that determines
how the versions of external modules are selected.

Possible modes are:
 - release: chooses latest release for each module
 - snapshot: uses a snapshot/development version for each module (if available)

In action.bash, the mode is automatically set based on the GITHUB_REF variable.
For tags starting with "v" (i.e. version tags like v2.9.0) it is release, other
tag names are not supported. For branches it is snapshot.
This commit is contained in:
Julian Brost 2022-03-14 17:33:07 +01:00
parent 1e730db8a8
commit af683bee76
3 changed files with 53 additions and 50 deletions

View File

@ -6,12 +6,13 @@ TARGET=icinga/icingaweb2
mkimg () {
test -n "$TAG"
test -n "$MODE"
node /actions/checkout/dist/index.js |grep -vFe ::add-matcher::
git archive --prefix=icingaweb2/ HEAD |tar -x
/get-mods.sh "$1"
/get-mods.sh "$MODE"
/composer.bash
patch -d icingaweb2 -p0 < /icingaweb2.patch
@ -31,39 +32,24 @@ push () {
fi
}
# Matches Git references that start with `refs/` and then continue with `heads/` or `tags/`.
# An optional `v` that follows is ignored. Then the tag or branch name is captured. These may
# be of the following forms and what is captured of them:
#
# - <form> -> g1(´heads´ or ´tags´),g2,g3
#
# - v1 -> ,1,
# - v1.1 -> ,1.1,
# - v1.2-1 -> ,1.2-1,
# - 2.0.0 -> ,2.0.0,
# - master -> ,master,
# - main -> ,main,
# - something -> ,something,
# - verbose -> ,erbose,
# - vault -> ,ault,
# - fix/error-123 -> ,fix/error-123,error-123
# - fix/mistake-456 -> ,fix/mistake-456,mistake-456
# - fix/climate -> ,fix/climate,climate
# - bugfix/legacy -> ,bugfix/legacy,legacy
# - feature/green-energy -> ,feature/green-energy,green-energy
# - feature/verbosity -> ,feature/verbosity,verbosity
# - viehture/bullshit -> ,viehture/bullshit,bullshit
#
re_docker_tag="^refs/(heads|tags)/v?([^/]+|[a-z]+/(.*))$"
case "$GITHUB_EVENT_NAME" in
workflow_dispatch|schedule|release)
[[ "$GITHUB_REF" =~ $re_docker_tag ]]
if [ -n "${BASH_REMATCH[3]}" ]; then
TAG="${BASH_REMATCH[3]}"
else
TAG="${BASH_REMATCH[2]}"
fi
case "$GITHUB_REF" in
refs/tags/v*)
MODE=release
TAG=${GITHUB_REF#refs/tags/v}
;;
refs/heads/*)
MODE=snapshot
TAG=${GITHUB_REF#refs/heads/}
# Remove everything up to the first slash to remove prefixes like "feature/"
TAG=${TAG#*/}
;;
*)
echo "Unknown ref: $GITHUB_REF" >&2
false
;;
esac
mkimg
push
;;

View File

@ -3,7 +3,7 @@
set -exo pipefail
IW2SRC="$1"
export MODS_BRANCH="$2"
export BUILD_MODE="${2:-release}"
if [ -z "$IW2SRC" ]; then
cat <<EOF >&2
@ -22,14 +22,14 @@ docker run --rm -i \
-v "${IW2SRC}:/iw2src:ro" \
-v "${BLDCTX}:/bldctx:ro" \
-v /var/run/docker.sock:/var/run/docker.sock \
-e MODS_BRANCH \
-e BUILD_MODE \
icinga/icingaweb2-builder bash <<EOF
set -exo pipefail
git -C /iw2src archive --prefix=iw2cp/icingaweb2/ HEAD |tar -xC /
cd /iw2cp
/bldctx/get-mods.sh "$MODS_BRANCH"
/bldctx/get-mods.sh "$BUILD_MODE"
/bldctx/composer.bash
patch -d icingaweb2 -p0 < /bldctx/icingaweb2.patch

View File

@ -2,7 +2,15 @@
# Icinga Web 2 Docker image | (c) 2020 Icinga GmbH | GPLv2+
set -exo pipefail
BRANCH="$1"
usage() {
cat >&2 <<EOF
Usage: get-mods.sh <release|snapshot>
release: download the latest release version of all external modules
snapshot: download a snapshot/development version of all external modules
EOF
exit 1
}
get_tag () {
if git -C dockerweb2-temp tag |grep -qvFe -; then # ex. RCs
@ -17,22 +25,25 @@ get_special () {
rm -rf dockerweb2-temp
git clone --bare "https://github.com/Icinga/${1}.git" dockerweb2-temp
case "$2" in
icingaweb2/modules/incubator)
case "$MODE" in
release)
REF="$(get_tag)"
;;
*)
if [ "$BRANCH" = master ] && [[ "$2" == icinga-php/* ]]; then
REF=snapshot/nightly
elif [ -n "$BRANCH" ] && git -C dockerweb2-temp show -s --oneline "$BRANCH"; then
REF="$BRANCH"
else
REF="$(get_tag)"
if [ "$2" = icingaweb2/modules/icingadb ] && [ "$REF" = 'v1.0.0-rc1' ]; then
REF=2c0662c420617712bd26234da550dcf8d4afcdb8 # v1.0.0-rc1+
fi
fi
snapshot)
case "$2" in
icingaweb2/modules/incubator)
# "HINT: Do NOT install the GIT master, it will not work!"
# https://github.com/Icinga/icingaweb2-module-incubator/blob/master/README.md
REF="$(get_tag)"
;;
icinga-php/*)
# Special branch that contains vendored dependencies missing in HEAD
REF=snapshot/nightly
;;
*)
REF=HEAD
;;
esac
;;
esac
@ -53,6 +64,12 @@ get_mod () {
get_altname "icingaweb2-module-$1" "$1"
}
MODE="$1"
case "$MODE" in
release|snapshot) ;;
*) usage ;;
esac
get_lib library ipl
get_lib thirdparty vendor
get_mod audit