mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
armbian-next: logging: pure ASCII .log; included in Markdown for GHA
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
# This only includes a header, and all the .md logfiles, nothing else.
|
||||
function export_markdown_logs() {
|
||||
display_alert "Preparing Markdown log from" "${LOGDIR}" "debug"
|
||||
# check target_file variable is not empty
|
||||
if [[ -z "${target_file}" ]]; then
|
||||
display_alert "No target file specified for export_markdown_logs()" "${target_file}" "err"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local ascii_log_file="${1:-}"
|
||||
display_alert "Preparing Markdown log from" "${LOGDIR} (${ascii_log_file})" "debug"
|
||||
|
||||
cat <<- MARKDOWN_HEADER > "${target_file}"
|
||||
<details><summary>Build: ${ARMBIAN_ORIGINAL_ARGV[*]}</summary>
|
||||
@@ -12,40 +19,74 @@ function export_markdown_logs() {
|
||||
MARKDOWN_HEADER
|
||||
|
||||
if [[ -n "$(command -v git)" && -d "${SRC}/.git" ]]; then
|
||||
display_alert "Gathering git info for logs" "Processing git information, please wait..." "debug"
|
||||
cat <<- GIT_MARKDOWN_HEADER >> "${target_file}"
|
||||
#### Last revision:
|
||||
\`\`\`
|
||||
$(LC_ALL=C LANG=C git --git-dir="${SRC}/.git" log -1 --format=short --decorate)
|
||||
\`\`\`
|
||||
#### Git status:
|
||||
\`\`\`
|
||||
$(LC_ALL=C LANG=C git --work-tree="${SRC}" --git-dir="${SRC}/.git" status)
|
||||
\`\`\`
|
||||
#### Git changes:
|
||||
\`\`\`
|
||||
$(LC_ALL=C LANG=C git --work-tree="${SRC}" --git-dir="${SRC}/.git" diff -u)
|
||||
\`\`\`
|
||||
GIT_MARKDOWN_HEADER
|
||||
# If in GHA, very unlikely there will be changes, don't waste space.
|
||||
if [[ "${CI}" == "true" ]] && [[ "${GITHUB_ACTIONS}" == "true" ]]; then
|
||||
display_alert "Gathering git info for logs" "Processing git information, GHA version" "debug"
|
||||
cat <<- GIT_MARKDOWN_HEADER_GHA >> "${target_file}"
|
||||
#### Current revision:
|
||||
\`\`\`
|
||||
$(LC_ALL=C LANG=C git --git-dir="${SRC}/.git" log -1 --format=short --decorate)
|
||||
\`\`\`
|
||||
GIT_MARKDOWN_HEADER_GHA
|
||||
else
|
||||
display_alert "Gathering git info for logs" "Processing git information, please wait..." "debug"
|
||||
cat <<- GIT_MARKDOWN_HEADER >> "${target_file}"
|
||||
#### Current revision:
|
||||
\`\`\`
|
||||
$(LC_ALL=C LANG=C git --git-dir="${SRC}/.git" log -1 --format=short --decorate)
|
||||
\`\`\`
|
||||
#### Git status:
|
||||
\`\`\`
|
||||
$(LC_ALL=C LANG=C git --work-tree="${SRC}" --git-dir="${SRC}/.git" status)
|
||||
\`\`\`
|
||||
#### Git changes:
|
||||
\`\`\`
|
||||
$(LC_ALL=C LANG=C git --work-tree="${SRC}" --git-dir="${SRC}/.git" diff -u)
|
||||
\`\`\`
|
||||
GIT_MARKDOWN_HEADER
|
||||
fi
|
||||
fi
|
||||
|
||||
# Newlines are relevant here.
|
||||
# FOOTER: Newlines are relevant here.
|
||||
echo -e "\n\n</p></details>\n\n" >> "${target_file}"
|
||||
|
||||
display_alert "Preparing Markdown logs..." "Processing log files..." "debug"
|
||||
|
||||
# Find and sort the files there, store in array one per logfile
|
||||
declare -a logfiles_array
|
||||
mapfile -t logfiles_array < <(find "${LOGDIR}" -type f | grep "\.md\$" | LC_ALL=C sort -h)
|
||||
mapfile -t logfiles_array < <(find "${LOGDIR}" -type f | grep "\.md\$" | LC_ALL=C sort -h) # "human" sorting
|
||||
for logfile_full in "${logfiles_array[@]}"; do
|
||||
cat "${logfile_full}" >> "${target_file}"
|
||||
done
|
||||
|
||||
# If running in GHA, include the ascii logs as well, side a collapsible section.
|
||||
if [[ "${CI}" == "true" ]] && [[ "${GITHUB_ACTIONS}" == "true" ]]; then
|
||||
if [[ -f "${ascii_log_file}" ]]; then
|
||||
# Newlines are relevant here.
|
||||
cat <<- MARKDOWN_LOG_HEADER >> "${target_file}"
|
||||
<details><summary>ASCII logs: ${ARMBIAN_BUILD_UUID}</summary>
|
||||
<p>
|
||||
|
||||
\`\`\`bash
|
||||
MARKDOWN_LOG_HEADER
|
||||
|
||||
# GHA has a 1mb limit for Markdown. 500kb of logs, max, from the end.
|
||||
tail --bytes 500000 "${ascii_log_file}" >> "${target_file}" || true
|
||||
echo -e "\n\`\`\`\n\n</p></details>\n\n" >> "${target_file}"
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Export logs in plain format.
|
||||
function export_ansi_logs() {
|
||||
# check target_file variable is not empty
|
||||
if [[ -z "${target_file}" ]]; then
|
||||
display_alert "No target file specified for export_markdown_logs()" "${target_file}" "err"
|
||||
return 0
|
||||
fi
|
||||
|
||||
display_alert "Preparing ANSI log from" "${LOGDIR}" "debug"
|
||||
|
||||
declare dim_line_separator
|
||||
@@ -94,6 +135,7 @@ function export_ansi_logs() {
|
||||
# shellcheck disable=SC2001 # I saw, and I can't
|
||||
logfile_title="$(echo "${logfile_base}" | sed -e 's/^[^.]*\.[^.]*\.//')"
|
||||
|
||||
# shellcheck disable=SC2002 # cats, not useless, I like.
|
||||
cat <<- ANSI_ONE_LOGFILE >> "${target_file}"
|
||||
$(echo -e -n "${bright_blue_color}")### ${logfile_title} $(echo -e -n "${ansi_reset_color}")
|
||||
$(cat "${logfile_full}" | sed -e "${prefix_sed_cmd}")
|
||||
|
||||
Reference in New Issue
Block a user