- Fix remaining 187 pkg/ files referencing core/cli → core/go - Move SDK library code from internal/cmd/sdk/ → pkg/sdk/ (new package) - Create pkg/rag/helpers.go with convenience functions from internal/cmd/rag/ - Fix pkg/mcp/tools_rag.go to use pkg/rag instead of internal/cmd/rag - Fix pkg/build/buildcmd/cmd_sdk.go and pkg/release/sdk.go to use pkg/sdk - Remove all non-library content: main.go, internal/, cmd/, docker/, scripts/, tasks/, tools/, .core/, .forgejo/, .woodpecker/, Taskfile.yml - Run go mod tidy to trim unused dependencies core/go is now a pure Go package suite (library only). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Claude <developers@lethean.io> Reviewed-on: #3
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package sources
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"forge.lthn.ai/core/go/pkg/io"
|
|
)
|
|
|
|
// GitHubSource downloads images from GitHub Releases.
|
|
type GitHubSource struct {
|
|
config SourceConfig
|
|
}
|
|
|
|
// Compile-time interface check.
|
|
var _ ImageSource = (*GitHubSource)(nil)
|
|
|
|
// NewGitHubSource creates a new GitHub source.
|
|
func NewGitHubSource(cfg SourceConfig) *GitHubSource {
|
|
return &GitHubSource{config: cfg}
|
|
}
|
|
|
|
// Name returns "github".
|
|
func (s *GitHubSource) Name() string {
|
|
return "github"
|
|
}
|
|
|
|
// Available checks if gh CLI is installed and authenticated.
|
|
func (s *GitHubSource) Available() bool {
|
|
_, err := exec.LookPath("gh")
|
|
if err != nil {
|
|
return false
|
|
}
|
|
// Check if authenticated
|
|
cmd := exec.Command("gh", "auth", "status")
|
|
return cmd.Run() == nil
|
|
}
|
|
|
|
// LatestVersion returns the latest release tag.
|
|
func (s *GitHubSource) LatestVersion(ctx context.Context) (string, error) {
|
|
cmd := exec.CommandContext(ctx, "gh", "release", "view",
|
|
"-R", s.config.GitHubRepo,
|
|
"--json", "tagName",
|
|
"-q", ".tagName",
|
|
)
|
|
out, err := cmd.Output()
|
|
if err != nil {
|
|
return "", fmt.Errorf("github.LatestVersion: %w", err)
|
|
}
|
|
return strings.TrimSpace(string(out)), nil
|
|
}
|
|
|
|
// Download downloads the image from the latest release.
|
|
func (s *GitHubSource) Download(ctx context.Context, m io.Medium, dest string, progress func(downloaded, total int64)) error {
|
|
// Get release assets to find our image
|
|
cmd := exec.CommandContext(ctx, "gh", "release", "download",
|
|
"-R", s.config.GitHubRepo,
|
|
"-p", s.config.ImageName,
|
|
"-D", dest,
|
|
"--clobber",
|
|
)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
return fmt.Errorf("github.Download: %w", err)
|
|
}
|
|
return nil
|
|
}
|