Add platform-specific builds to goreleaser#409
Conversation
Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
|
@copilot Identify shared code/logic in the new main.go files and extract them to a shared common place. |
There was a problem hiding this comment.
Pull request overview
This PR extends the build system to produce platform-specific standalone binaries alongside the main pipeleak binary. Each platform binary (pipeleak-gitlab, pipeleak-github, pipeleak-bitbucket, pipeleak-devops, pipeleak-gitea) exposes only that platform's commands as the root, simplifying usage for single-platform deployments.
Key Changes:
- Added 5 new platform-specific entry points with self-contained logging and terminal handling
- Extended goreleaser configuration to build all platform binaries for Linux/Windows on amd64/arm64
- Updated Makefile with individual build targets and consolidated
build-alltarget
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 21 comments.
Show a summary per file
| File | Description |
|---|---|
| goreleaser.yaml | Added build configurations for 5 platform-specific binaries with appropriate ldflags for version info |
| cmd/pipeleak-gitlab/main.go | New GitLab-only entry point with standalone CLI initialization and logging setup |
| cmd/pipeleak-github/main.go | New GitHub-only entry point with standalone CLI initialization and logging setup |
| cmd/pipeleak-bitbucket/main.go | New BitBucket-only entry point with standalone CLI initialization and logging setup |
| cmd/pipeleak-devops/main.go | New Azure DevOps-only entry point with standalone CLI initialization and logging setup |
| cmd/pipeleak-gitea/main.go | New Gitea-only entry point with standalone CLI initialization and logging setup |
| Makefile | Added individual build-{platform} targets and build-all aggregator; updated clean target |
| .gitignore | Added patterns to ignore all new platform-specific binaries and their Windows .exe variants |
| } | ||
|
|
||
| func initLogger(cmd *cobra.Command) { | ||
| defaultOut := os.Stdout |
There was a problem hiding this comment.
Missing CustomWriter wrapper for proper cross-platform newline handling. The original internal/cmd/root.go uses a CustomWriter type (lines 88-117) that ensures proper newline handling across platforms (different behavior for Windows vs. Unix). Without this wrapper, log output may have incorrect line endings on Windows.
Change:
defaultOut := os.StdoutTo:
defaultOut := &CustomWriter{Writer: os.Stdout}And update line 132:
defaultOut = runLogFileTo:
defaultOut = &CustomWriter{Writer: runLogFile}You'll need to add the CustomWriter implementation from internal/cmd/root.go (lines 88-117) to this file or refactor to share the common code.
| runLogFile, err := os.OpenFile( | ||
| LogFile, | ||
| os.O_APPEND|os.O_CREATE|os.O_WRONLY, | ||
| 0600, |
There was a problem hiding this comment.
Use the named constant format.FileUserReadWrite instead of the magic number 0600 for file permissions. This is consistent with the original internal/cmd/root.go implementation (line 139) and improves maintainability. The constant is already defined in pkg/format/fileperms.go for this purpose.
Change:
0600,To:
format.FileUserReadWrite,(Note: You'll need to import "github.com/CompassSecurity/pipeleak/pkg/format")
| } | ||
|
|
||
| func initLogger(cmd *cobra.Command) { | ||
| defaultOut := os.Stdout |
There was a problem hiding this comment.
Missing CustomWriter wrapper for proper cross-platform newline handling. The original internal/cmd/root.go uses a CustomWriter type (lines 88-117) that ensures proper newline handling across platforms (different behavior for Windows vs. Unix). Without this wrapper, log output may have incorrect line endings on Windows.
Change:
defaultOut := os.StdoutTo:
defaultOut := &CustomWriter{Writer: os.Stdout}And update line 132:
defaultOut = runLogFileTo:
defaultOut = &CustomWriter{Writer: runLogFile}You'll need to add the CustomWriter implementation from internal/cmd/root.go (lines 88-117) to this file or refactor to share the common code.
| type TerminalRestoringWriter struct { | ||
| underlying io.Writer | ||
| } | ||
|
|
||
| func (w *TerminalRestoringWriter) Write(p []byte) (n int, err error) { | ||
| var logEntry map[string]interface{} | ||
| if err := json.Unmarshal(p, &logEntry); err == nil { | ||
| if level, ok := logEntry["level"].(string); ok && level == "fatal" { | ||
| _, _ = w.underlying.Write(p) | ||
| restoreTerminalState() | ||
| os.Exit(1) | ||
| } | ||
| } | ||
| return w.underlying.Write(p) | ||
| } | ||
|
|
There was a problem hiding this comment.
TerminalRestoringWriter is defined but never used in this file. The Write method implementation (lines 39-49) handles fatal log detection and terminal restoration, but no code in this file creates instances of this type or calls its methods. This appears to be vestigial code from copying the original cmd/pipeleak/main.go.
Consider removing this unused type or documenting its intended purpose if it's meant for future use.
| type TerminalRestoringWriter struct { | |
| underlying io.Writer | |
| } | |
| func (w *TerminalRestoringWriter) Write(p []byte) (n int, err error) { | |
| var logEntry map[string]interface{} | |
| if err := json.Unmarshal(p, &logEntry); err == nil { | |
| if level, ok := logEntry["level"].(string); ok && level == "fatal" { | |
| _, _ = w.underlying.Write(p) | |
| restoreTerminalState() | |
| os.Exit(1) | |
| } | |
| } | |
| return w.underlying.Write(p) | |
| } |
| runLogFile, err := os.OpenFile( | ||
| LogFile, | ||
| os.O_APPEND|os.O_CREATE|os.O_WRONLY, | ||
| 0600, |
There was a problem hiding this comment.
Use the named constant format.FileUserReadWrite instead of the magic number 0600 for file permissions. This is consistent with the original internal/cmd/root.go implementation (line 139) and improves maintainability. The constant is already defined in pkg/format/fileperms.go for this purpose.
Change:
0600,To:
format.FileUserReadWrite,(Note: You'll need to import "github.com/CompassSecurity/pipeleak/pkg/format")
| type TerminalRestoringWriter struct { | ||
| underlying io.Writer | ||
| } | ||
|
|
||
| func (w *TerminalRestoringWriter) Write(p []byte) (n int, err error) { | ||
| var logEntry map[string]interface{} | ||
| if err := json.Unmarshal(p, &logEntry); err == nil { | ||
| if level, ok := logEntry["level"].(string); ok && level == "fatal" { | ||
| _, _ = w.underlying.Write(p) | ||
| restoreTerminalState() | ||
| os.Exit(1) | ||
| } | ||
| } | ||
| return w.underlying.Write(p) | ||
| } | ||
|
|
There was a problem hiding this comment.
TerminalRestoringWriter is defined but never used in this file. The Write method implementation (lines 39-49) handles fatal log detection and terminal restoration, but no code in this file creates instances of this type or calls its methods. This appears to be vestigial code from copying the original cmd/pipeleak/main.go.
Consider removing this unused type or documenting its intended purpose if it's meant for future use.
| type TerminalRestoringWriter struct { | |
| underlying io.Writer | |
| } | |
| func (w *TerminalRestoringWriter) Write(p []byte) (n int, err error) { | |
| var logEntry map[string]interface{} | |
| if err := json.Unmarshal(p, &logEntry); err == nil { | |
| if level, ok := logEntry["level"].(string); ok && level == "fatal" { | |
| _, _ = w.underlying.Write(p) | |
| restoreTerminalState() | |
| os.Exit(1) | |
| } | |
| } | |
| return w.underlying.Write(p) | |
| } |
| type TerminalRestoringWriter struct { | ||
| underlying io.Writer | ||
| } | ||
|
|
||
| func (w *TerminalRestoringWriter) Write(p []byte) (n int, err error) { | ||
| var logEntry map[string]interface{} | ||
| if err := json.Unmarshal(p, &logEntry); err == nil { | ||
| if level, ok := logEntry["level"].(string); ok && level == "fatal" { | ||
| _, _ = w.underlying.Write(p) | ||
| restoreTerminalState() | ||
| os.Exit(1) | ||
| } | ||
| } | ||
| return w.underlying.Write(p) | ||
| } | ||
|
|
There was a problem hiding this comment.
TerminalRestoringWriter is defined but never used in this file. The Write method implementation (lines 39-49) handles fatal log detection and terminal restoration, but no code in this file creates instances of this type or calls its methods. This appears to be vestigial code from copying the original cmd/pipeleak/main.go.
Consider removing this unused type or documenting its intended purpose if it's meant for future use.
| type TerminalRestoringWriter struct { | |
| underlying io.Writer | |
| } | |
| func (w *TerminalRestoringWriter) Write(p []byte) (n int, err error) { | |
| var logEntry map[string]interface{} | |
| if err := json.Unmarshal(p, &logEntry); err == nil { | |
| if level, ok := logEntry["level"].(string); ok && level == "fatal" { | |
| _, _ = w.underlying.Write(p) | |
| restoreTerminalState() | |
| os.Exit(1) | |
| } | |
| } | |
| return w.underlying.Write(p) | |
| } |
| output := zerolog.ConsoleWriter{ | ||
| Out: defaultOut, | ||
| TimeFormat: "2006-01-02T15:04:05Z07:00", | ||
| NoColor: !colorEnabled, | ||
| } |
There was a problem hiding this comment.
Missing custom FormatLevel for the "hit" log level coloring. The original internal/cmd/root.go includes a formatLevelWithHitColor function (lines 178-216) that provides magenta coloring for the special "hit" log level used to mark detected secrets. Without this formatter, the "hit" level will not be distinctly colored in console output, making it harder to spot secrets in the logs.
The platform-specific binaries should either:
- Include the same
formatLevelWithHitColorimplementation, or - Refactor to share the common logging setup (as suggested in the code duplication comment)
Current code:
output := zerolog.ConsoleWriter{
Out: defaultOut,
TimeFormat: "2006-01-02T15:04:05Z07:00",
NoColor: !colorEnabled,
}Should be:
output := zerolog.ConsoleWriter{
Out: defaultOut,
TimeFormat: time.RFC3339, // Also use the named constant
NoColor: !colorEnabled,
FormatLevel: formatLevelWithHitColor(colorEnabled), // Add custom formatter
}| output := zerolog.ConsoleWriter{ | ||
| Out: defaultOut, | ||
| TimeFormat: "2006-01-02T15:04:05Z07:00", | ||
| NoColor: !colorEnabled, | ||
| } |
There was a problem hiding this comment.
Missing custom FormatLevel for the "hit" log level coloring. The original internal/cmd/root.go includes a formatLevelWithHitColor function (lines 178-216) that provides magenta coloring for the special "hit" log level used to mark detected secrets. Without this formatter, the "hit" level will not be distinctly colored in console output, making it harder to spot secrets in the logs.
The platform-specific binaries should either:
- Include the same
formatLevelWithHitColorimplementation, or - Refactor to share the common logging setup (as suggested in the code duplication comment)
Current code:
output := zerolog.ConsoleWriter{
Out: defaultOut,
TimeFormat: "2006-01-02T15:04:05Z07:00",
NoColor: !colorEnabled,
}Should be:
output := zerolog.ConsoleWriter{
Out: defaultOut,
TimeFormat: time.RFC3339, // Also use the named constant
NoColor: !colorEnabled,
FormatLevel: formatLevelWithHitColor(colorEnabled), // Add custom formatter
}| } | ||
|
|
||
| func initLogger(cmd *cobra.Command) { | ||
| defaultOut := os.Stdout |
There was a problem hiding this comment.
Missing CustomWriter wrapper for proper cross-platform newline handling. The original internal/cmd/root.go uses a CustomWriter type (lines 88-117) that ensures proper newline handling across platforms (different behavior for Windows vs. Unix). Without this wrapper, log output may have incorrect line endings on Windows.
Change:
defaultOut := os.StdoutTo:
defaultOut := &CustomWriter{Writer: os.Stdout}And update line 132:
defaultOut = runLogFileTo:
defaultOut = &CustomWriter{Writer: runLogFile}You'll need to add the CustomWriter implementation from internal/cmd/root.go (lines 88-117) to this file or refactor to share the common code.
…tions Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Extracted shared code to |
|
@copilot the goreleaser action should only build all binaries on a release. if it runs on a PR its ok to just build the main binary that includes all platfporms. |
Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Added |
|
@copilot Ensure that the HIT log keeps the color, you somehow removed it. |
…mon package Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Added |
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.