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 () { mkimg () {
test -n "$TAG" test -n "$TAG"
test -n "$MODE"
node /actions/checkout/dist/index.js |grep -vFe ::add-matcher:: node /actions/checkout/dist/index.js |grep -vFe ::add-matcher::
git archive --prefix=icingaweb2/ HEAD |tar -x git archive --prefix=icingaweb2/ HEAD |tar -x
/get-mods.sh "$1" /get-mods.sh "$MODE"
/composer.bash /composer.bash
patch -d icingaweb2 -p0 < /icingaweb2.patch patch -d icingaweb2 -p0 < /icingaweb2.patch
@ -31,39 +32,24 @@ push () {
fi 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 case "$GITHUB_EVENT_NAME" in
workflow_dispatch|schedule|release) workflow_dispatch|schedule|release)
[[ "$GITHUB_REF" =~ $re_docker_tag ]] case "$GITHUB_REF" in
if [ -n "${BASH_REMATCH[3]}" ]; then refs/tags/v*)
TAG="${BASH_REMATCH[3]}" MODE=release
else TAG=${GITHUB_REF#refs/tags/v}
TAG="${BASH_REMATCH[2]}" ;;
fi 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 mkimg
push push
;; ;;

View File

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

View File

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