From 30a7aa0e9c2992d569cbb65a0861d3360c8e94d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=A4der?= Date: Tue, 5 Oct 2021 10:22:00 +0200 Subject: [PATCH] Group the build output in GitHub Action --- build-functions/gh-functions.sh | 21 +++++++++++++++++++++ build.sh | 22 +++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 build-functions/gh-functions.sh diff --git a/build-functions/gh-functions.sh b/build-functions/gh-functions.sh new file mode 100644 index 0000000..4928d0d --- /dev/null +++ b/build-functions/gh-functions.sh @@ -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 +} diff --git a/build.sh b/build.sh index 17d3e66..1cf6cd1 100755 --- a/build.sh +++ b/build.sh @@ -95,6 +95,8 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then fi fi +source ./build-functions/gh-functions.sh + ### # Enabling dry-run mode ### @@ -105,6 +107,8 @@ else DRY="echo" fi +gh_echo "::group::โคต๏ธ Fetching the NetBox source code" + ### # 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) if [ "${REMOTE_EXISTS}" == "0" ]; then echo "โŒ Remote branch '${NETBOX_BRANCH}' not found in '${URL}'; Nothing to do" - if [ -n "${GH_ACTION}" ]; then - echo "::set-output name=skipped::true" - fi + gh_echo "::set-output name=skipped::true" exit 0 fi 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" fi +gh_echo "::endgroup::" +gh_echo "::group::๐Ÿงฎ Calculating Values" + ### # Determining the value for DOCKERFILE # and checking whether it exists @@ -221,11 +226,14 @@ DEFAULT_DOCKER_TARGETS=("main" "ldap") DOCKER_TARGETS=("${DOCKER_TARGET:-"${DEFAULT_DOCKER_TARGETS[@]}"}") echo "๐Ÿญ Building the following targets:" "${DOCKER_TARGETS[@]}" +gh_echo "::endgroup::" + ### # Build each target ### export DOCKER_BUILDKIT=${DOCKER_BUILDKIT-1} for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do + gh_echo "::group::๐Ÿ— Building the target '${DOCKER_TARGET}'" echo "๐Ÿ— Building the target '${DOCKER_TARGET}'" ### @@ -237,10 +245,8 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do fi TARGET_DOCKER_TAG_PROJECT="${TARGET_DOCKER_TAG}-${PROJECT_VERSION}" - if [ -n "${GH_ACTION}" ]; then - echo "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG_PROJECT}" >>"$GITHUB_ENV" - echo "::set-output name=skipped::false" - fi + gh_env "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG_PROJECT}" + gh_echo "::set-output name=skipped::false" ### # 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}" fi fi + + gh_echo "::endgroup::" done