0
0
mirror of https://github.com/termux/termux-packages.git synced 2025-09-20 08:49:38 +00:00
Files
termux-packages/scripts/bin/golang-validation
TomIO 336f8c3f15 ci(golang-validation): Switch to using $GITHUB_STEP_SUMMARY
instead of producing a log artifact
2025-09-01 04:43:35 +02:00

76 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
cd "$(realpath "$(dirname "$0")")/../.." || { echo "cd failed"; exit 1; }
readarray -t TERMUX_PACKAGE_DIRECTORIES < <(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json)
readarray -t PACKAGES < <(grep -rl termux_setup_golang --include=build.sh "${TERMUX_PACKAGE_DIRECTORIES[@]}" | cut -d/ -f2 | sort -u || :) || :
ARCH="${1?"Usage: $0 [aarch64|arm|x86_64|i686]"}"
# Converts milliseconds to human-readable format.
# Example: `ms_to_human_readable 123456789` => 34h 17m 36s 789ms
ms_to_human_readable() {
echo "$(($1/3600000))h $(($1%3600000/60000))m $(($1%60000/1000))s $(($1%1000))ms" | sed 's/0h //;s/0m //;s/0s //'
}
maybe_cleanup() {
[[ -z "$CI" ]] && return
local PACKAGE="$1" CLEANUP_THRESHOLD=10 # GiB
if grep -Fxq "$PACKAGE" scripts/big-pkgs.list; then
echo "INFO: performing cleanup before building big package."
elif df "$HOME" | awk -v t="$CLEANUP_THRESHOLD" 'NR == 2 { exit ($4 / 1024^2 < t ? 0 : 1) }'; then
echo "INFO: Cleaning up, free disk space is below the threshold (${CLEANUP_THRESHOLD} GiB)."
else
return
fi
./clean.sh
rm -rf ./output/*
}
# This script aims to:
# 1. Obtain a list of all Golang packages.
# 2. Build them.
# 3. Create a CI summary containing only build logs of failed build attempts.
[[ -z "$CI" ]] && echo "INFO: Not running in CI environment, cleanup will not be performed."
echo "INFO: Rebuild list: ${PACKAGES[*]}" | tee "${GITHUB_STEP_SUMMARY}"
output=""
declare -A failed=()
start_building_arch="$(date +%10s%3N)"
for package in "${PACKAGES[@]}"; do
output="$(
start="$(date +%10s%3N)"
exec > >(tee /dev/fd/2) 2>&1 # output everything to both variable and stdout.
# Header
echo "INFO: Building ${package} for ${ARCH}"
maybe_cleanup "${package}"
./build-package.sh -I -f -a "${ARCH}" "${package}"
status="${PIPESTATUS[0]}"
echo # newline
echo "INFO: Building ${package} for ${ARCH} took $(ms_to_human_readable $(( $(date +%10s%3N) - start )))"
echo # newline
exit "$status"
)" || failed["${package} ${ARCH}"]="${output}"
done
echo "INFO: Building all packages for ${ARCH} took $(ms_to_human_readable $(( $(date +%10s%3N) - start_building_arch )))" | tee -a "${GITHUB_STEP_SUMMARY}"
echo # newline
if (( ${#failed[@]} > 0 )); then
echo "Writing output for failed packages to '$GITHUB_STEP_SUMMARY' to be logged in summary." >&2
echo "### The packages below failed to build for ${ARCH}." >> "$GITHUB_STEP_SUMMARY"
fi
for entry in "${!failed[@]}"; do
echo "${failed["${entry}"]}" >> "${GITHUB_STEP_SUMMARY}"
{
echo "<details><summary><code>${entry% *}</code></summary><p>"
echo ""
echo "${failed["${entry}"]}"
echo ""
echo "</p></details>"
} >> "$GITHUB_STEP_SUMMARY"
done
exit $(( ${#failed[@]} > 0 ))