run go foo during the buiild
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module goinst
|
||||
|
||||
go 1.25.3
|
||||
@@ -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
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user