Skip to content

Commit

Permalink
fix(ci): copy binary headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pandatix committed Jan 16, 2025
1 parent 50956aa commit e60d736
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions api/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,31 @@ func scenario() ([]byte, error) {
}

// Add binary file
bmain, err := compile()
fs, err := compile()
if err != nil {
return nil, err
}
w, err = archive.Create("main")
defer fs.Close()

fst, err := fs.Stat()
if err != nil {
return nil, err
}
header, err := zip.FileInfoHeader(fst)
if err != nil {
return nil, err
}
header.Name = "main"

// Create archive
f, err := archive.CreateHeader(header)
if err != nil {
return nil, err
}
if _, err := io.Copy(w, bytes.NewBuffer(bmain)); err != nil {

// Copy the file's contents into the archive.
_, err = io.Copy(f, fs)
if err != nil {
return nil, err
}

Expand All @@ -197,7 +213,7 @@ func scenario() ([]byte, error) {
return buf.Bytes(), nil
}

func compile() ([]byte, error) {
func compile() (*os.File, error) {
cmd := exec.Command("go", "build", "-o", "main", "../examples/dynamiciac/scenario/main.go")
cmd.Env = append(os.Environ(), "CGO_ENABLED=0")
if err := cmd.Run(); err != nil {
Expand All @@ -207,7 +223,7 @@ func compile() ([]byte, error) {
cmd := exec.Command("rm", "main")
_ = cmd.Run()
}()
return os.ReadFile("main")
return os.Open("main")
}

func ptr[T any](t T) *T {
Expand Down

0 comments on commit e60d736

Please sign in to comment.