Compare commits
No commits in common. "4054ca3b2e55ac486940562d871c4258cc051156" and "57fc43ff9c44013d3cfba569ddb3050763deca4f" have entirely different histories.
4054ca3b2e
...
57fc43ff9c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
||||
cmd/pbuild/pbuild
|
||||
cmd/pbuild/*.zip
|
||||
|
@ -8,15 +8,4 @@ type Config struct {
|
||||
|
||||
// Post message in Gitea format, only taking what we're interested in.
|
||||
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"`
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
logs, _, _ := profile.Run(".", "out.zip")
|
||||
logs, _, _ := profile.Run(".")
|
||||
|
||||
fmt.Print(logs)
|
||||
}
|
||||
|
@ -4,9 +4,5 @@
|
||||
"Commands": [
|
||||
"go clean",
|
||||
"go build -v"
|
||||
],
|
||||
|
||||
"Output": [
|
||||
"pbuild"
|
||||
]
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ type Profile struct {
|
||||
Commands []string // Commands to run on the profile.
|
||||
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.
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@ -15,29 +14,20 @@ type logsWriter struct {
|
||||
outfd int // 0(manual message) 1(stdout) or 2(stderr)
|
||||
}
|
||||
|
||||
func (l *logsWriter) Write(data []byte) (written int, err error) {
|
||||
datalen := len(data)
|
||||
written = datalen
|
||||
|
||||
func (l *logsWriter) Write(data []byte) (len int, err error) {
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
for data[datalen-1] == byte('\n') {
|
||||
datalen--
|
||||
}
|
||||
data = data[:datalen]
|
||||
|
||||
*l.logs = append(*l.logs, LogEntry{
|
||||
Time: time.Now(),
|
||||
Text: string(data),
|
||||
OutFd: l.outfd,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 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
|
||||
_, 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
|
||||
|
||||
fmt.Fprintf(logman, "building %s", p.Name)
|
||||
|
||||
// Run commands
|
||||
runcmds:
|
||||
for i, str := range p.Commands {
|
||||
|
||||
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.Stdout = logout
|
||||
cmd.Stderr = logerr
|
||||
@ -83,36 +71,12 @@ runcmds:
|
||||
|
||||
switch err.(type) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user