Skip to content

Build/auto update#3

Merged
datbth merged 4 commits into
mainfrom
build/auto_update
Jul 22, 2026
Merged

Build/auto update#3
datbth merged 4 commits into
mainfrom
build/auto_update

Conversation

@datbth

@datbth datbth commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator
  • install script
  • update command

@datbth
datbth requested a review from khanhhuy as a code owner July 22, 2026 05:26

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a self-update mechanism for the anfra CLI, including a manual update command, background update checks, and an install.sh script. The review feedback highlights several critical issues: a compilation failure on Windows due to a missing detachProcess implementation, fragile manual command parsing in main.go that should be replaced with Cobra's ExecuteC(), a security risk in install.sh where credentials could leak during redirects, a potential script crash if the SHELL environment variable is empty, and opportunities to improve context propagation for cancellation and semver comparison robustness.

Comment thread cmd/anfra/detach_unix.go
@@ -0,0 +1,14 @@
//go:build !windows

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The file is configured with //go:build !windows, but there is no Windows implementation of detachProcess. This will cause compilation to fail on Windows with undefined: detachProcess.

To support Windows compilation (even if Windows builds are not officially released yet), please add a detach_windows.go file with a stub or Windows-specific implementation:

//go:build windows

package main

import "os/exec"

func detachProcess(cmd *exec.Cmd) {
	// Stub or Windows-specific process detaching logic
}

Comment thread cmd/anfra/main.go Outdated
Comment thread cmd/anfra/main.go Outdated
Comment thread install.sh Outdated
Comment thread install.sh
Comment thread cmd/anfra/update.go
Comment on lines +17 to +28
func newUpdateCmd() *cobra.Command {
var checkOnly bool
cmd := &cobra.Command{
Use: "update",
Short: "Update anfra to the latest release (use --check to only report)",
RunE: func(_ *cobra.Command, _ []string) error {
return runUpdate(checkOnly)
},
}
cmd.Flags().BoolVar(&checkOnly, "check", false, "only check for an update; do not install")
return cmd
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Pass the command's context cmd.Context() to runUpdate to support cancellation (e.g., if the user presses Ctrl+C during a large download).

Suggested change
func newUpdateCmd() *cobra.Command {
var checkOnly bool
cmd := &cobra.Command{
Use: "update",
Short: "Update anfra to the latest release (use --check to only report)",
RunE: func(_ *cobra.Command, _ []string) error {
return runUpdate(checkOnly)
},
}
cmd.Flags().BoolVar(&checkOnly, "check", false, "only check for an update; do not install")
return cmd
}
func newUpdateCmd() *cobra.Command {
var checkOnly bool
cmd := &cobra.Command{
Use: "update",
Short: "Update anfra to the latest release (use --check to only report)",
RunE: func(cmd *cobra.Command, _ []string) error {
return runUpdate(cmd.Context(), checkOnly)
},
}
cmd.Flags().BoolVar(&checkOnly, "check", false, "only check for an update; do not install")
return cmd
}

Comment thread cmd/anfra/update.go
Comment on lines +30 to +34
func runUpdate(checkOnly bool) error {
// Root at Background (repo convention, see host.go/runServe); timeouts are
// bounded per-request inside the update package (a quick lookup, then a large
// download).
ctx := context.Background()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Update runUpdate to accept and use the passed context instead of context.Background().

Suggested change
func runUpdate(checkOnly bool) error {
// Root at Background (repo convention, see host.go/runServe); timeouts are
// bounded per-request inside the update package (a quick lookup, then a large
// download).
ctx := context.Background()
func runUpdate(ctx context.Context, checkOnly bool) error {
// Root at Background (repo convention, see host.go/runServe); timeouts are
// bounded per-request inside the update package (a quick lookup, then a large
// download).

Comment thread internal/update/update.go
@datbth
datbth merged commit 211ab43 into main Jul 22, 2026
4 checks passed
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.

2 participants