Skip to content

Add platform-specific builds to goreleaser#409

Merged
frjcomp merged 7 commits intomainfrom
copilot/extend-build-process-for-platforms
Dec 2, 2025
Merged

Add platform-specific builds to goreleaser#409
frjcomp merged 7 commits intomainfrom
copilot/extend-build-process-for-platforms

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 1, 2025

  • Explore repository structure and understand the codebase
  • Understand the current goreleaser.yaml configuration
  • Understand the Makefile targets
  • Identify the platforms (gitlab, github, bitbucket, devops, gitea)
  • Create separate main.go entry points for each platform
    • cmd/pipeleak-gitlab/main.go
    • cmd/pipeleak-github/main.go
    • cmd/pipeleak-bitbucket/main.go
    • cmd/pipeleak-devops/main.go
    • cmd/pipeleak-gitea/main.go
  • Update goreleaser.yaml to build per-platform binaries
  • Update Makefile to add platform-specific build targets
    • build-gitlab
    • build-github
    • build-bitbucket
    • build-devops
    • build-gitea
    • build-all
  • Update .gitignore to exclude platform-specific binaries
  • Test build configurations locally
  • Extract shared code to internal/cmd/common package
    • Terminal state management
    • Logging setup
    • Common flags
    • Version information
    • CustomWriter for cross-platform newline handling
    • formatLevelWithHitColor for HIT log coloring
  • Update platform descriptions to new template format
  • Update goreleaser ldflags to use common package path
  • Configure platform-specific builds to only run on release (skip on PRs/snapshots)
Original prompt

This section details on the original issue you should resolve

<issue_title>Subcommand builds</issue_title>
<issue_description>Extend the goreleaser build process, to create one main build as it is right now and newly add a build per platform. so e.g. gitlab has its own binary, github cmd has its own binary etc. update the make file as well. </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Copilot AI changed the title [WIP] Extend goreleaser build process for platform binaries Add platform-specific builds to goreleaser Dec 1, 2025
Copilot AI requested a review from frjcomp December 1, 2025 14:23
@frjcomp frjcomp requested a review from Copilot December 2, 2025 06:40
@frjcomp
Copy link
Copy Markdown
Collaborator

frjcomp commented Dec 2, 2025

@copilot Identify shared code/logic in the new main.go files and extract them to a shared common place.

@frjcomp frjcomp marked this pull request as ready for review December 2, 2025 06:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-all target

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

Comment thread cmd/pipeleak-gitea/main.go Outdated
}

func initLogger(cmd *cobra.Command) {
defaultOut := os.Stdout
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Stdout

To:

defaultOut := &CustomWriter{Writer: os.Stdout}

And update line 132:

defaultOut = runLogFile

To:

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.

Copilot uses AI. Check for mistakes.
Comment thread cmd/pipeleak-bitbucket/main.go Outdated
runLogFile, err := os.OpenFile(
LogFile,
os.O_APPEND|os.O_CREATE|os.O_WRONLY,
0600,
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copilot uses AI. Check for mistakes.
Comment thread cmd/pipeleak-github/main.go Outdated
}

func initLogger(cmd *cobra.Command) {
defaultOut := os.Stdout
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Stdout

To:

defaultOut := &CustomWriter{Writer: os.Stdout}

And update line 132:

defaultOut = runLogFile

To:

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.

Copilot uses AI. Check for mistakes.
Comment thread cmd/pipeleak-bitbucket/main.go Outdated
Comment on lines +35 to +50
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)
}

Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)
}

Copilot uses AI. Check for mistakes.
Comment thread cmd/pipeleak-github/main.go Outdated
runLogFile, err := os.OpenFile(
LogFile,
os.O_APPEND|os.O_CREATE|os.O_WRONLY,
0600,
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copilot uses AI. Check for mistakes.
Comment thread cmd/pipeleak-github/main.go Outdated
Comment on lines +35 to +50
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)
}

Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)
}

Copilot uses AI. Check for mistakes.
Comment thread cmd/pipeleak-devops/main.go Outdated
Comment on lines +35 to +50
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)
}

Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)
}

Copilot uses AI. Check for mistakes.
Comment thread cmd/pipeleak-gitlab/main.go Outdated
Comment on lines +148 to +152
output := zerolog.ConsoleWriter{
Out: defaultOut,
TimeFormat: "2006-01-02T15:04:05Z07:00",
NoColor: !colorEnabled,
}
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Include the same formatLevelWithHitColor implementation, or
  2. 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
}

Copilot uses AI. Check for mistakes.
Comment thread cmd/pipeleak-github/main.go Outdated
Comment on lines +148 to +152
output := zerolog.ConsoleWriter{
Out: defaultOut,
TimeFormat: "2006-01-02T15:04:05Z07:00",
NoColor: !colorEnabled,
}
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Include the same formatLevelWithHitColor implementation, or
  2. 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
}

Copilot uses AI. Check for mistakes.
Comment thread cmd/pipeleak-bitbucket/main.go Outdated
}

func initLogger(cmd *cobra.Command) {
defaultOut := os.Stdout
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Stdout

To:

defaultOut := &CustomWriter{Writer: os.Stdout}

And update line 132:

defaultOut = runLogFile

To:

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.

Copilot uses AI. Check for mistakes.
…tions

Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 2, 2025

@copilot Identify shared code/logic in the new main.go files and extract them to a shared common place.

Extracted shared code to internal/cmd/common package in commit 0df2d5f. Each platform main.go was reduced from ~194 lines to ~29 lines. The common package contains terminal state management, logging setup, common flags, and version information.

@frjcomp
Copy link
Copy Markdown
Collaborator

frjcomp commented Dec 2, 2025

@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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 2, 2025

@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.

Added skip: '{{ not .IsRelease }}' to all platform-specific builds in commit b388815. Now only the main pipeleak binary is built on PRs/snapshots, while all platform binaries are built on tagged releases.

@frjcomp
Copy link
Copy Markdown
Collaborator

frjcomp commented Dec 2, 2025

@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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 2, 2025

@copilot Ensure that the HIT log keeps the color, you somehow removed it.

Added formatLevelWithHitColor function to the common package in commit 22ab916. The HIT log level now has magenta coloring (color 35) to distinguish it from other log levels. Also added CustomWriter for proper cross-platform newline handling and used format.FileUserReadWrite constant for file permissions.

@frjcomp frjcomp enabled auto-merge (squash) December 2, 2025 08:01
@frjcomp frjcomp merged commit 79bcd93 into main Dec 2, 2025
11 checks passed
@frjcomp frjcomp deleted the copilot/extend-build-process-for-platforms branch December 2, 2025 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subcommand builds

3 participants