Compare commits

..

No commits in common. "4054ca3b2e55ac486940562d871c4258cc051156" and "57fc43ff9c44013d3cfba569ddb3050763deca4f" have entirely different histories.

6 changed files with 6 additions and 58 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
cmd/pbuild/pbuild cmd/pbuild/pbuild
cmd/pbuild/*.zip

View File

@ -8,15 +8,4 @@ type Config struct {
// Post message in Gitea format, only taking what we're interested in. // Post message in Gitea format, only taking what we're interested in.
type GiteaPost struct { type GiteaPost struct {
Before string `json:"before"`
After string `json:"after"`
Repository struct {
ID int `json:"id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Description string `json:"description"`
SSHURL string `json:"ssh_url"`
} `json:"repostiory"`
} }

View File

@ -21,7 +21,7 @@ func main() {
panic(err) panic(err)
} }
logs, _, _ := profile.Run(".", "out.zip") logs, _, _ := profile.Run(".")
fmt.Print(logs) fmt.Print(logs)
} }

View File

@ -4,9 +4,5 @@
"Commands": [ "Commands": [
"go clean", "go clean",
"go build -v" "go build -v"
],
"Output": [
"pbuild"
] ]
} }

View File

@ -13,7 +13,7 @@ type Profile struct {
Commands []string // Commands to run on the profile. Commands []string // Commands to run on the profile.
Environ map[string]string // Environment variables Environ map[string]string // Environment variables
Output []string // List of globs to match output files, fed directly into the shell. Output []string // List of globs to match output files.
OutputDir string // The globs will be matched in this relative directory. OutputDir string // The globs will be matched in this relative directory.
} }

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"strings"
"sync" "sync"
"time" "time"
) )
@ -15,29 +14,20 @@ type logsWriter struct {
outfd int // 0(manual message) 1(stdout) or 2(stderr) outfd int // 0(manual message) 1(stdout) or 2(stderr)
} }
func (l *logsWriter) Write(data []byte) (written int, err error) { func (l *logsWriter) Write(data []byte) (len int, err error) {
datalen := len(data)
written = datalen
l.lock.Lock() l.lock.Lock()
defer l.lock.Unlock() defer l.lock.Unlock()
for data[datalen-1] == byte('\n') {
datalen--
}
data = data[:datalen]
*l.logs = append(*l.logs, LogEntry{ *l.logs = append(*l.logs, LogEntry{
Time: time.Now(), Time: time.Now(),
Text: string(data), Text: string(data),
OutFd: l.outfd, OutFd: l.outfd,
}) })
return return
} }
// Run runs the profile on the target directory, preserving output. // Run runs the profile on the target directory, preserving output.
func (p *Profile) Run(dir string, outfile string) (logs Logs, exitcode int, err error) { func (p *Profile) Run(dir string) (logs Logs, exitcode int, err error) {
// Try if the directory exists // Try if the directory exists
_, err = os.ReadDir(dir) _, err = os.ReadDir(dir)
@ -62,15 +52,13 @@ func (p *Profile) Run(dir string, outfile string) (logs Logs, exitcode int, err
var systime, usrtime time.Duration var systime, usrtime time.Duration
fmt.Fprintf(logman, "building %s", p.Name)
// Run commands // Run commands
runcmds: runcmds:
for i, str := range p.Commands { for i, str := range p.Commands {
fmt.Fprintf(logman, "[%d/%d] running \"%s\"", i, len(p.Commands), str) fmt.Fprintf(logman, "[%d/%d] running \"%s\"", i, len(p.Commands), str)
cmd := exec.Command("sh", "-c", "exec "+str) cmd := exec.Command("sh", "-c", str)
cmd.Env = append(cmd.Env, env...) cmd.Env = append(cmd.Env, env...)
cmd.Stdout = logout cmd.Stdout = logout
cmd.Stderr = logerr cmd.Stderr = logerr
@ -83,36 +71,12 @@ runcmds:
switch err.(type) { switch err.(type) {
case *exec.ExitError: case *exec.ExitError:
fmt.Fprintf(logman, "!!!!! command exit with code %d: %s", err.(*exec.ExitError).ExitCode(), err.Error()) fmt.Fprintf(logman, "!!!!! command exit with code %d !!!!!", err.(*exec.ExitError).ExitCode())
break runcmds break runcmds
} }
} }
fmt.Fprintf(logman, "system %.4f, user %.4f", systime.Seconds(), usrtime.Seconds()) fmt.Fprintf(logman, "system %.4f, user %.4f", systime.Seconds(), usrtime.Seconds())
// package the files
writer, err := os.OpenFile(outfile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
defer writer.Close()
if err != nil {
fmt.Fprintf(logman, "!!!!! error opening output pack: %s", err.Error())
return
}
packstr := "zip -r - " + strings.Join(p.Output, " ")
fmt.Fprintf(logman, "[fin] packing output: \"%s\"", packstr)
packcmd := exec.Command("sh", "-c", "exec "+packstr)
packcmd.Dir = p.OutputDir
packcmd.Stdout = writer
packcmd.Stderr = logerr
err = packcmd.Run()
if err != nil {
fmt.Fprintf(logman, "!!!!! pack subprocess return %d: %s", packcmd.ProcessState.ExitCode(), err.Error())
return
}
fmt.Fprintf(logman, "output is at %s", outfile)
return return
} }