Files
act/common/line_writer.go
zeekayandHanzo Dev 873e28c9b4 fork act model + exprparser from gitea.com/gitea/runner
The forge needs to PARSE and EVALUATE workflows: model, exprparser, and the two
small helper packages they use. It does not need to run them — that is the
runner process, and a container runtime is 12000 of the 15754 lines in the
upstream act subtree.

So this is the 3619 lines that a forge actually calls, not a fork of the whole
engine. gitea.com/gitea/runner was the last gitea.com dependency in
hanzoai/git.

Pins match upstream (actionlint v1.7.12 with go.yaml.in/yaml/v4 v4.0.0-rc.3 —
the two are version-coupled and a free resolution of actionlint does not build)
and go 1.26, which exprparser needs for reflect.Fields.

Upstream MIT notices retained; ours added above them.

All four packages green.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-27 18:44:23 -07:00

56 lines
1.1 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// Copyright 2020 The Gitea Authors. All rights reserved.
// Copyright 2020 The nektos/act Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package common
import (
"bytes"
"io"
)
// LineHandler is a callback function for handling a line
type LineHandler func(line string) bool
type lineWriter struct {
buffer bytes.Buffer
handlers []LineHandler
}
// NewLineWriter creates a new instance of a line writer
func NewLineWriter(handlers ...LineHandler) io.Writer {
w := new(lineWriter)
w.handlers = handlers
return w
}
func (lw *lineWriter) Write(p []byte) (n int, err error) {
pBuf := bytes.NewBuffer(p)
written := 0
for {
line, err := pBuf.ReadString('\n')
w, _ := lw.buffer.WriteString(line)
written += w
if err == nil {
lw.handleLine(lw.buffer.String())
lw.buffer.Reset()
} else if err == io.EOF {
break
} else {
return written, err
}
}
return written, nil
}
func (lw *lineWriter) handleLine(line string) {
for _, h := range lw.handlers {
ok := h(line)
if !ok {
break
}
}
}