Group the build output in GitHub Action

This commit is contained in:
Christian Mäder 2021-10-05 10:22:00 +02:00
parent 5f0b7467d1
commit 30a7aa0e9c
2 changed files with 36 additions and 7 deletions

View File

@ -0,0 +1,21 @@
#!/bin/bash
###
# A regular echo, that only prints if ${GH_ACTION} is defined.
###
gh_echo() {
if [ -n "${GH_ACTION}" ]; then
echo "${@}"
fi
}
###
# Prints the output to the file defined in ${GITHUB_ENV}.
# Only executes if ${GH_ACTION} is defined.
# Example Usage: gh_env "FOO_VAR=bar_value"
###
gh_env() {
if [ -n "${GH_ACTION}" ]; then
echo "${@}" >>"${GITHUB_ENV}"
fi
}

View File

@ -95,6 +95,8 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
fi fi
fi fi
source ./build-functions/gh-functions.sh
### ###
# Enabling dry-run mode # Enabling dry-run mode
### ###
@ -105,6 +107,8 @@ else
DRY="echo" DRY="echo"
fi fi
gh_echo "::group::⤵️ Fetching the NetBox source code"
### ###
# Variables for fetching the NetBox source # Variables for fetching the NetBox source
### ###
@ -121,9 +125,7 @@ if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ]; then
REMOTE_EXISTS=$(git ls-remote --heads --tags "${URL}" "${NETBOX_BRANCH}" | wc -l) REMOTE_EXISTS=$(git ls-remote --heads --tags "${URL}" "${NETBOX_BRANCH}" | wc -l)
if [ "${REMOTE_EXISTS}" == "0" ]; then if [ "${REMOTE_EXISTS}" == "0" ]; then
echo "❌ Remote branch '${NETBOX_BRANCH}' not found in '${URL}'; Nothing to do" echo "❌ Remote branch '${NETBOX_BRANCH}' not found in '${URL}'; Nothing to do"
if [ -n "${GH_ACTION}" ]; then gh_echo "::set-output name=skipped::true"
echo "::set-output name=skipped::true"
fi
exit 0 exit 0
fi fi
echo "🌐 Checking out '${NETBOX_BRANCH}' of NetBox from the url '${URL}' into '${NETBOX_PATH}'" echo "🌐 Checking out '${NETBOX_BRANCH}' of NetBox from the url '${URL}' into '${NETBOX_PATH}'"
@ -146,6 +148,9 @@ if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ]; then
echo "✅ Checked out NetBox" echo "✅ Checked out NetBox"
fi fi
gh_echo "::endgroup::"
gh_echo "::group::🧮 Calculating Values"
### ###
# Determining the value for DOCKERFILE # Determining the value for DOCKERFILE
# and checking whether it exists # and checking whether it exists
@ -221,11 +226,14 @@ DEFAULT_DOCKER_TARGETS=("main" "ldap")
DOCKER_TARGETS=("${DOCKER_TARGET:-"${DEFAULT_DOCKER_TARGETS[@]}"}") DOCKER_TARGETS=("${DOCKER_TARGET:-"${DEFAULT_DOCKER_TARGETS[@]}"}")
echo "🏭 Building the following targets:" "${DOCKER_TARGETS[@]}" echo "🏭 Building the following targets:" "${DOCKER_TARGETS[@]}"
gh_echo "::endgroup::"
### ###
# Build each target # Build each target
### ###
export DOCKER_BUILDKIT=${DOCKER_BUILDKIT-1} export DOCKER_BUILDKIT=${DOCKER_BUILDKIT-1}
for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
gh_echo "::group::🏗 Building the target '${DOCKER_TARGET}'"
echo "🏗 Building the target '${DOCKER_TARGET}'" echo "🏗 Building the target '${DOCKER_TARGET}'"
### ###
@ -237,10 +245,8 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
fi fi
TARGET_DOCKER_TAG_PROJECT="${TARGET_DOCKER_TAG}-${PROJECT_VERSION}" TARGET_DOCKER_TAG_PROJECT="${TARGET_DOCKER_TAG}-${PROJECT_VERSION}"
if [ -n "${GH_ACTION}" ]; then gh_env "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG_PROJECT}"
echo "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG_PROJECT}" >>"$GITHUB_ENV" gh_echo "::set-output name=skipped::false"
echo "::set-output name=skipped::false"
fi
### ###
# composing the additional DOCKER_SHORT_TAG, # composing the additional DOCKER_SHORT_TAG,
@ -401,4 +407,6 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
push_image_to_registry "${TARGET_DOCKER_LATEST_TAG_PROJECT}" push_image_to_registry "${TARGET_DOCKER_LATEST_TAG_PROJECT}"
fi fi
fi fi
gh_echo "::endgroup::"
done done