From fc01f9a032450a53b321c6ffbe21ace84092f2e4 Mon Sep 17 00:00:00 2001 From: grambbledook Date: Tue, 25 Nov 2025 19:36:52 +0100 Subject: [PATCH] run go foo during the buiild --- .../test-ci-instrumentation-workflow.yml | 31 +++++++++++++++ goinst/go.mod | 3 ++ goinst/main.go | 38 +++++++++++++++++++ pkg/build/cmd.go | 2 +- 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-ci-instrumentation-workflow.yml create mode 100644 goinst/go.mod create mode 100644 goinst/main.go diff --git a/.github/workflows/test-ci-instrumentation-workflow.yml b/.github/workflows/test-ci-instrumentation-workflow.yml new file mode 100644 index 00000000000..7b8295caf6d --- /dev/null +++ b/.github/workflows/test-ci-instrumentation-workflow.yml @@ -0,0 +1,31 @@ +name: test-ci-instrumentation-workflow.yml +on: + push: + branches: + - grambbledook/test-toolexec-instrumentation + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v5 + with: + persist-credentials: false + - name: Setup Go + uses: actions/setup-go@v6.0.0 + with: + go-version-file: go.mod + cache: true + + - name: Build foo + run: | + cd ./goinst + GOWORK=off go build -o foo + mv ./foo ../foo + cd ../ + + - name: Build Grafana + run: | + make build-go + diff --git a/goinst/go.mod b/goinst/go.mod new file mode 100644 index 00000000000..a4ea1c0ffcb --- /dev/null +++ b/goinst/go.mod @@ -0,0 +1,3 @@ +module goinst + +go 1.25.3 diff --git a/goinst/main.go b/goinst/main.go new file mode 100644 index 00000000000..4504f5e795d --- /dev/null +++ b/goinst/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "os" + "os/exec" + "time" +) + +func main() { + if len(os.Args) < 2 { + fmt.Fprintln(os.Stderr, "Usage: toolexec [args...]") + os.Exit(1) + } + + tool := os.Args[1] + args := os.Args[2:] + + start := time.Now() + + cmd := exec.Command(tool, args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + err := cmd.Run() + elapsed := time.Since(start) + + fmt.Fprintf(os.Stderr, "tool=%s elapsed=%s\n", tool, elapsed) + + if err != nil { + if exitErr, ok := err.(*exec.ExitError); ok { + os.Exit(exitErr.ExitCode()) + } else { + fmt.Fprintln(os.Stderr, "Error:", err) + os.Exit(1) + } + } +} diff --git a/pkg/build/cmd.go b/pkg/build/cmd.go index c3b9ec0bc50..98b5d3d1b20 100644 --- a/pkg/build/cmd.go +++ b/pkg/build/cmd.go @@ -207,7 +207,7 @@ func doBuild(binaryName, pkg string, opts BuildOpts) error { // We should not publish Grafana as a Go module, disabling vcs changes the version to (devel) // and works better with SBOM and Vulnerability Scanners. args = append(args, "-buildvcs=false") - + args = append(args, "-toolexec=\"./foo\"") args = append(args, "-o", binary) args = append(args, pkg)