Skip to content

Commit 30a7aa0

Browse files
committed
Group the build output in GitHub Action
1 parent 5f0b746 commit 30a7aa0

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

build-functions/gh-functions.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
###
4+
# A regular echo, that only prints if ${GH_ACTION} is defined.
5+
###
6+
gh_echo() {
7+
if [ -n "${GH_ACTION}" ]; then
8+
echo "${@}"
9+
fi
10+
}
11+
12+
###
13+
# Prints the output to the file defined in ${GITHUB_ENV}.
14+
# Only executes if ${GH_ACTION} is defined.
15+
# Example Usage: gh_env "FOO_VAR=bar_value"
16+
###
17+
gh_env() {
18+
if [ -n "${GH_ACTION}" ]; then
19+
echo "${@}" >>"${GITHUB_ENV}"
20+
fi
21+
}

build.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
9595
fi
9696
fi
9797

98+
source ./build-functions/gh-functions.sh
99+
98100
###
99101
# Enabling dry-run mode
100102
###
@@ -105,6 +107,8 @@ else
105107
DRY="echo"
106108
fi
107109

110+
gh_echo "::group::⤵️ Fetching the NetBox source code"
111+
108112
###
109113
# Variables for fetching the NetBox source
110114
###
@@ -121,9 +125,7 @@ if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ]; then
121125
REMOTE_EXISTS=$(git ls-remote --heads --tags "${URL}" "${NETBOX_BRANCH}" | wc -l)
122126
if [ "${REMOTE_EXISTS}" == "0" ]; then
123127
echo "❌ Remote branch '${NETBOX_BRANCH}' not found in '${URL}'; Nothing to do"
124-
if [ -n "${GH_ACTION}" ]; then
125-
echo "::set-output name=skipped::true"
126-
fi
128+
gh_echo "::set-output name=skipped::true"
127129
exit 0
128130
fi
129131
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
146148
echo "✅ Checked out NetBox"
147149
fi
148150

151+
gh_echo "::endgroup::"
152+
gh_echo "::group::🧮 Calculating Values"
153+
149154
###
150155
# Determining the value for DOCKERFILE
151156
# and checking whether it exists
@@ -221,11 +226,14 @@ DEFAULT_DOCKER_TARGETS=("main" "ldap")
221226
DOCKER_TARGETS=("${DOCKER_TARGET:-"${DEFAULT_DOCKER_TARGETS[@]}"}")
222227
echo "🏭 Building the following targets:" "${DOCKER_TARGETS[@]}"
223228

229+
gh_echo "::endgroup::"
230+
224231
###
225232
# Build each target
226233
###
227234
export DOCKER_BUILDKIT=${DOCKER_BUILDKIT-1}
228235
for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
236+
gh_echo "::group::🏗 Building the target '${DOCKER_TARGET}'"
229237
echo "🏗 Building the target '${DOCKER_TARGET}'"
230238

231239
###
@@ -237,10 +245,8 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
237245
fi
238246
TARGET_DOCKER_TAG_PROJECT="${TARGET_DOCKER_TAG}-${PROJECT_VERSION}"
239247

240-
if [ -n "${GH_ACTION}" ]; then
241-
echo "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG_PROJECT}" >>"$GITHUB_ENV"
242-
echo "::set-output name=skipped::false"
243-
fi
248+
gh_env "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG_PROJECT}"
249+
gh_echo "::set-output name=skipped::false"
244250

245251
###
246252
# composing the additional DOCKER_SHORT_TAG,
@@ -401,4 +407,6 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
401407
push_image_to_registry "${TARGET_DOCKER_LATEST_TAG_PROJECT}"
402408
fi
403409
fi
410+
411+
gh_echo "::endgroup::"
404412
done

0 commit comments

Comments
 (0)