-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathgo.sh
More file actions
executable file
·82 lines (69 loc) · 3.17 KB
/
Copy pathgo.sh
File metadata and controls
executable file
·82 lines (69 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
set -euo pipefail
debug_log() {
if [ "${CODSPEED_LOG:-}" = "debug" ]; then
echo "[DEBUG go.sh] $*" >&2
fi
}
debug_log "Called with arguments: $*"
debug_log "Number of arguments: $#"
# Currently only walltime is supported
if [ "${CODSPEED_RUNNER_MODE:-}" != "walltime" ]; then
echo "CRITICAL: Go benchmarks can only be run with the walltime instrument"
exit 1
fi
# Find the real go binary by removing our directory from PATH (same approach as node.sh)
ORIGINAL_PATH=$(echo "$PATH" | tr ":" "\n" | grep -v "codspeed_introspected_go" | tr "\n" ":")
REAL_GO=$(env PATH="$ORIGINAL_PATH" which go 2>/dev/null || true)
debug_log "Real go path: $REAL_GO"
if [ -z "$REAL_GO" ]; then
echo "ERROR: Could not find real go binary" >&2
exit 1
fi
# Check if we have any arguments
if [ $# -eq 0 ]; then
debug_log "No arguments provided, using standard go binary"
"$REAL_GO"
exit $?
fi
# On arm64, warn about setting CODSPEED_PERF_UNWINDING_MODE to "fp" for correct flamegraphs
if [ "$(uname -m)" = "aarch64" ] && [ "${CODSPEED_GO_SUPPRESS_PERF_UNWINDING_MODE_WARNING:-}" != "true" ]; then
echo "::warning::Go profiling on arm64 require frame pointer unwinding. Set CODSPEED_PERF_UNWINDING_MODE=fp for better profiling." >&2
fi
# Route command based on first argument
case "$1" in
test)
debug_log "Detected 'test' command, routing to go-runner"
# Find go-runner or install if not found
GO_RUNNER=$(which codspeed-go-runner 2>/dev/null || true)
if [ -z "$GO_RUNNER" ]; then
# Build the installer URL with the specified version or use latest
INSTALLER_VERSION="${CODSPEED_GO_RUNNER_VERSION:-latest}"
if [ "$INSTALLER_VERSION" = "latest" ]; then
DOWNLOAD_URL="http://github.com/CodSpeedHQ/codspeed-go/releases/latest/download/codspeed-go-runner-installer.sh"
echo "::warning::Installing the latest version of codspeed-go-runner. This can silently introduce breaking changes. We recommend pinning a specific version via the \`go-runner-version\` option in the action." >&2
else
DOWNLOAD_URL="http://github.com/CodSpeedHQ/codspeed-go/releases/download/v${INSTALLER_VERSION}/codspeed-go-runner-installer.sh"
fi
debug_log "Installing go-runner from: $DOWNLOAD_URL"
curl -fsSL "$DOWNLOAD_URL" | bash -s -- --quiet
GO_RUNNER=$(which codspeed-go-runner 2>/dev/null || true)
fi
debug_log "Using go-runner at: $GO_RUNNER"
debug_log "Full command: RUST_LOG=info $GO_RUNNER $*"
"$GO_RUNNER" "$@"
;;
run)
debug_log "Detected 'run' command, injecting -work -ldflags flags"
# Insert flags after 'run' but before other arguments
# This is needed because GOFLAGS cannot handle spaces in ldflags...
debug_log "Full command: $REAL_GO run -work -ldflags=\"-s=false -w=false\" ${*:2}"
"$REAL_GO" run -work -ldflags="-s=false -w=false" "${@:2}"
;;
*)
debug_log "Detected non-test command ('$1'), routing to standard go binary"
debug_log "Full command: $REAL_GO $*"
"$REAL_GO" "$@"
;;
esac
exit $?