run go foo during the buiild

This commit is contained in:
grambbledook
2025-12-11 19:09:47 +01:00
parent d83b216a32
commit fc01f9a032
4 changed files with 73 additions and 1 deletions
@@ -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
+3
View File
@@ -0,0 +1,3 @@
module goinst
go 1.25.3
+38
View File
@@ -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 <tool> [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)
}
}
}
+1 -1
View File
@@ -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)