Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
227 changes: 227 additions & 0 deletions .github/scripts/parallel-go-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
#!/usr/bin/env bash
# parallel-go-build.sh
# Recursively find go.mod files and run `go build ./...` in each module directory.
# - truncates build-errors.log at start
# - appends failures immediately, annotated with source line + 1-line context
# - runs in parallel (jobs = CPU cores)
# - atomic appends (mkdir lock)
# - handles Ctrl+C (SIGINT) and SIGTERM: kills children and cleans up
# - colored terminal output (OK = green, FAIL = red, WARN = yellow)
set -euo pipefail
IFS=$'\n\t'

JOBS="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)"
LOGFILE="build-errors.log"

# Colors (only if stdout is a tty)
if [ -t 1 ]; then
GREEN=$'\e[32m'
RED=$'\e[31m'
YELLOW=$'\e[33m'
RESET=$'\e[0m'
else
GREEN=""
RED=""
YELLOW=""
RESET=""
fi

# truncate central logfile at start
: > "$LOGFILE"

# find all module directories (skip common vendor trees)
mapfile -t MODULE_DIRS < <(
find . \( -path "./.git" -o -path "./vendor" -o -path "./node_modules" \) -prune -o \
-type f -name 'go.mod' -print0 |
xargs -0 -n1 dirname |
sort -u
)

if [ "${#MODULE_DIRS[@]}" -eq 0 ]; then
printf '%s\n' "No go.mod files found. Nothing to do."
exit 0
fi

# create absolute temp dir
TMPDIR="$(mktemp -d 2>/dev/null || mktemp -d /tmp/build-logs.XXXXXX)"
if [ -z "$TMPDIR" ] || [ ! -d "$TMPDIR" ]; then
printf '%s\n' "Failed to create temporary directory" >&2
exit 2
fi

# ensure cleanup on exit (will try multiple times)
cleanup_tmpdir() {
local attempts=0
while [ "$attempts" -lt 5 ]; do
if rm -rf "$TMPDIR" 2>/dev/null; then
break
fi
attempts=$((attempts+1))
sleep 0.1
done
if [ -d "$TMPDIR" ]; then
printf '%s\n' "WARNING: could not fully remove temporary dir: $TMPDIR"
fi
}

# signal handling: kill children, wait, cleanup, exit
pids=()
on_interrupt() {
printf '%b\n' "${YELLOW}Received interrupt. Killing background jobs...${RESET}"
# kill all tracked background pids
for pid in "${pids[@]:-}"; do
if kill -0 "$pid" 2>/dev/null; then
kill "$pid" 2>/dev/null || true
fi
done
# give them a moment, then force
sleep 0.1
for pid in "${pids[@]:-}"; do
if kill -0 "$pid" 2>/dev/null; then
kill -9 "$pid" 2>/dev/null || true
fi
done
cleanup_tmpdir
printf '%b\n' "${YELLOW}Aborted by user.${RESET}"
exit 130
}
trap on_interrupt INT TERM

# helper: sanitize a dir to a filename-safe token
sanitize_name() {
local d="$1"
d="${d#./}"
d="${d//\//__}"
d="${d// /_}"
printf '%s' "${d//[^A-Za-z0-9._-]/_}"
}

# annotate a module's temp log and append to central logfile atomically
annotate_and_append() {
local src_log="$1" # absolute path to per-module temp log
local module_dir="$2"
local lockdir="$TMPDIR/.lock"

# create annotated temp file
local annotated
annotated="$(mktemp "$TMPDIR/annotated.XXXXXX")" || {
# fallback: append raw log
until mkdir "$lockdir" 2>/dev/null; do sleep 0.01; done
printf '==== %s ====\n' "$module_dir" >> "$LOGFILE"
cat "$src_log" >> "$LOGFILE"
rm -f "$src_log" || true
rmdir "$lockdir" 2>/dev/null || true
return
}

# process lines: if matches file.go:LINE[:COL] annotate with source snippet
while IFS= read -r line || [ -n "$line" ]; do
# regex: capture path ending with .go, line number, optional column, rest
if [[ $line =~ ^([^:]+\.go):([0-9]+):?([0-9]*)[:[:space:]]*(.*)$ ]]; then
local fp="${BASH_REMATCH[1]}"
local ln="${BASH_REMATCH[2]}"
local col="${BASH_REMATCH[3]}"
local rest="${BASH_REMATCH[4]}"
local candidate=""

# try to resolve file path: as-is, relative to module_dir, or relative to repo root
if [ -f "$fp" ]; then
candidate="$fp"
elif [ -f "$module_dir/$fp" ]; then
candidate="$module_dir/$fp"
elif [ -f "./$fp" ]; then
candidate="./$fp"
fi

if [ -n "$candidate" ]; then
# pick context: line-1 .. line+1
local start=$(( ln > 1 ? ln - 1 : 1 ))
local end=$(( ln + 1 ))
printf '%s\n' "---- source: $candidate:$ln ----" >> "$annotated"
# print numbered context lines
awk -v s="$start" -v e="$end" 'NR>=s && NR<=e { printf("%6d %s\n", NR, $0) }' "$candidate" >> "$annotated"
printf '%s\n\n' "Error: $line" >> "$annotated"
else
printf '%s\n' "---- (source not found) $line ----" >> "$annotated"
fi
else
# plain copy line
printf '%s\n' "$line" >> "$annotated"
fi
done < "$src_log"

# append annotated file to central logfile under lock
until mkdir "$lockdir" 2>/dev/null; do
sleep 0.01
done
{
printf '==== %s ====\n' "$module_dir"
cat "$annotated"
printf '\n\n'
} >> "$LOGFILE"
rm -f "$annotated" "$src_log" || true
rmdir "$lockdir" 2>/dev/null || true
}

# run build for one module
run_build() {
local module_dir="$1"
local safe
safe="$(sanitize_name "$module_dir")"
local mod_log="$TMPDIR/$safe.log"
mkdir -p "$(dirname "$mod_log")"

# run inside subshell to avoid changing caller's cwd
if ( cd "$module_dir" 2>/dev/null && go build ./... >/dev/null 2>"$mod_log" ); then
printf '%b\n' "${GREEN}OK: ${RESET}$module_dir"
rm -f "$mod_log" >/dev/null 2>&1 || true
return 0
else
# ensure we captured something
if [ ! -s "$mod_log" ]; then
( cd "$module_dir" 2>/dev/null && go build ./... >"$mod_log" 2>&1 ) || true
fi
printf '%b\n' "${RED}FAIL: ${RESET}$module_dir (appending to $LOGFILE)"
annotate_and_append "$mod_log" "$module_dir"
return 1
fi
}

# main launcher: spawn jobs, throttle to JOBS, wait properly
fail_count=0

for md in "${MODULE_DIRS[@]}"; do
run_build "$md" &
pids+=( "$!" )

# if we reached jobs, wait for the oldest launched
if [ "${#pids[@]}" -ge "$JOBS" ]; then
if wait "${pids[0]}"; then
: # success
else
fail_count=$((fail_count+1))
fi
# drop first pid
pids=( "${pids[@]:1}" )
fi
done

# wait remaining background jobs
for pid in "${pids[@]:-}"; do
if wait "$pid"; then :; else fail_count=$((fail_count+1)); fi
done

# final cleanup and status
cleanup_tmpdir

if [ "$fail_count" -gt 0 ]; then
printf '\n%b\n' "${RED}Done. $fail_count module(s) failed. See $LOGFILE for details (annotated snippets included).${RESET}"
exit 1
else
printf '\n%b\n' "${GREEN}Done. All modules built successfully.${RESET}"
# remove logfile if empty
if [ -f "$LOGFILE" ] && [ ! -s "$LOGFILE" ]; then
rm -f "$LOGFILE"
fi
exit 0
fi
19 changes: 12 additions & 7 deletions 404-handler/go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
module main

go 1.23.0
go 1.25.0

require github.com/gofiber/fiber/v2 v2.52.9
require github.com/gofiber/fiber/v3 v3.0.0-beta.5.0.20250824113156-64a711307367

require (
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/gofiber/schema v1.6.0 // indirect
github.com/gofiber/utils/v2 v2.0.0-rc.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/philhofer/fwd v1.2.0 // indirect
github.com/tinylib/msgp v1.3.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.64.0 // indirect
golang.org/x/sys v0.34.0 // indirect
github.com/valyala/fasthttp v1.65.0 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
)
51 changes: 36 additions & 15 deletions 404-handler/go.sum
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=
github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
github.com/gofiber/fiber/v2 v2.52.9 h1:YjKl5DOiyP3j0mO61u3NTmK7or8GzzWzCFzkboyP5cw=
github.com/gofiber/fiber/v2 v2.52.9/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=
github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
github.com/gofiber/fiber/v3 v3.0.0-beta.5.0.20250824113156-64a711307367 h1:En2BvMtoQwAtX/QPGs8ZKP104D0DRdskYxWPG+UfpY0=
github.com/gofiber/fiber/v3 v3.0.0-beta.5.0.20250824113156-64a711307367/go.mod h1:WxaMswqN6mnr5ExbxbaUpIXkJTUEQr0TPDsGhTK5lSo=
github.com/gofiber/schema v1.6.0 h1:rAgVDFwhndtC+hgV7Vu5ItQCn7eC2mBA4Eu1/ZTiEYY=
github.com/gofiber/schema v1.6.0/go.mod h1:WNZWpQx8LlPSK7ZaX0OqOh+nQo/eW2OevsXs1VZfs/s=
github.com/gofiber/utils/v2 v2.0.0-rc.1 h1:b77K5Rk9+Pjdxz4HlwEBnS7u5nikhx7armQB8xPds4s=
github.com/gofiber/utils/v2 v2.0.0-rc.1/go.mod h1:Y1g08g7gvST49bbjHJ1AVqcsmg93912R/tbKWhn6V3E=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM=
github.com/philhofer/fwd v1.2.0/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shamaton/msgpack/v2 v2.3.0 h1:eawIa7lQmwRv0V6rdmL/5Ev9KdJHk07eQH3ceJi3BUw=
github.com/shamaton/msgpack/v2 v2.3.0/go.mod h1:6khjYnkx73f7VQU7wjcFS9DFjs+59naVWJv1TB7qdOI=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tinylib/msgp v1.3.0 h1:ULuf7GPooDaIlbyvgAxBV/FI7ynli6LZ1/nVUNu+0ww=
github.com/tinylib/msgp v1.3.0/go.mod h1:ykjzy2wzgrlvpDCRc4LA8UXy6D8bzMSuAF3WD57Gok0=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.64.0 h1:QBygLLQmiAyiXuRhthf0tuRkqAFcrC42dckN2S+N3og=
github.com/valyala/fasthttp v1.64.0/go.mod h1:dGmFxwkWXSK0NbOSJuF7AMVzU+lkHz0wQVvVITv2UQA=
github.com/valyala/fasthttp v1.65.0 h1:j/u3uzFEGFfRxw79iYzJN+TteTJwbYkru9uDp3d0Yf8=
github.com/valyala/fasthttp v1.65.0/go.mod h1:P/93/YkKPMsKSnATEeELUCkG8a7Y+k99uxNHVbKINr4=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6 changes: 3 additions & 3 deletions 404-handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main
import (
"log"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v3"
)

func main() {
Expand All @@ -18,7 +18,7 @@ func main() {
app.Get("/hello", hello)

// 404 Handler
app.Use(func(c *fiber.Ctx) error {
app.Use(func(c fiber.Ctx) error {
return c.SendStatus(404) // => 404 "Not Found"
})

Expand All @@ -27,6 +27,6 @@ func main() {
}

// Handler
func hello(c *fiber.Ctx) error {
func hello(c fiber.Ctx) error {
return c.SendString("I made a ☕ for you!")
}
19 changes: 12 additions & 7 deletions air/go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
module main

go 1.23.0
go 1.25.0

require github.com/gofiber/fiber/v2 v2.52.9
require github.com/gofiber/fiber/v3 v3.0.0-beta.5.0.20250824113156-64a711307367

require (
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/gofiber/schema v1.6.0 // indirect
github.com/gofiber/utils/v2 v2.0.0-rc.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/philhofer/fwd v1.2.0 // indirect
github.com/tinylib/msgp v1.3.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.64.0 // indirect
golang.org/x/sys v0.34.0 // indirect
github.com/valyala/fasthttp v1.65.0 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
)
Loading
Loading