Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-7058 feat(cli): support self-hosted Gitea release sources (#8027)

2233admin2bd4f1757106
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.md
index 59b2daad74..bfaef20cdc 100644
--- a/CLI_AND_DAEMON.md
+++ b/CLI_AND_DAEMON.md
@@ -31,7 +31,23 @@ For install script or manual installs, use:
multica update
```
-`multica update` auto-detects your installation method and upgrades accordingly.
+`multica update` uses GitHub Releases by default. Self-hosted installations can
+point the CLI at a GitHub Releases-compatible metadata mirror and an artifact
+mirror without changing the command. To let a daemon poll that source, also
+enable self-update explicitly because self-hosted auto-update is disabled by
+default:
+
+```bash
+export MULTICA_RELEASE_API_BASE_URL=https://updates.example/api
+export MULTICA_RELEASE_DOWNLOAD_BASE_URL=https://updates.example/releases/download
+export MULTICA_DAEMON_AUTO_UPDATE=true
+multica update
+```
+
+The metadata mirror must serve `/repos/multica-ai/multica/releases/latest` and
+`/repos/multica-ai/multica/releases/tags/<tag>`. The artifact mirror must serve
+`/<tag>/<asset-name>` and preserve the published `checksums.txt` contents.
+When these variables are unset, the GitHub defaults remain unchanged.
## Quick Start
diff --git a/server/cmd/multica/cmd_update.go b/server/cmd/multica/cmd_update.go
index 4b8c7e6f0c..b3998ad586 100644
--- a/server/cmd/multica/cmd_update.go
+++ b/server/cmd/multica/cmd_update.go
@@ -30,7 +30,7 @@ func runUpdate(_ *cobra.Command, _ []string) error {
fmt.Fprintf(os.Stderr, "Current version: %s (commit: %s, built: %s)\n", version, commit, date)
- // Check latest version from GitHub.
+ // Check the configured release source.
latest, err := cli.FetchLatestRelease()
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: could not check latest version: %v\n", err)
@@ -56,12 +56,12 @@ func runUpdate(_ *cobra.Command, _ []string) error {
return nil
}
- // Not installed via brew — download binary directly from GitHub Releases.
+ // Not installed via brew — download the binary from the configured release source.
if latest == nil {
- return fmt.Errorf("could not determine latest version; check https://github.com/multica-ai/multica/releases/latest")
+ return fmt.Errorf("could not determine latest version; check the configured release source")
}
targetVersion := latest.TagName
- fmt.Fprintf(os.Stderr, "Downloading %s from GitHub Releases...\n", targetVersion)
+ fmt.Fprintf(os.Stderr, "Downloading %s from the configured release source...\n", targetVersion)
output, err := cli.UpdateViaDownloadWithTimeout(targetVersion, updateDownloadTimeout)
if err != nil {
return fmt.Errorf("update failed: %w", err)
diff --git a/server/internal/cli/update.go b/server/internal/cli/update.go
index 4c57997096..b9be7155ba 100644
--- a/server/internal/cli/update.go
+++ b/server/internal/cli/update.go
@@ -13,6 +13,7 @@ import (
"fmt"
"io"
"net/http"
+ "net/url"
"os"
"os/exec"
"path/filepath"
@@ -30,8 +31,35 @@ import (
// changes one place.
const ChecksumManifestName = "checksums.txt"
+const defaultReleaseAPIBaseURL = "https://api.github.com"
+
+// MULTICA_RELEASE_API_BASE_URL points at a GitHub Releases API-compatible
+// mirror. MULTICA_RELEASE_DOWNLOAD_BASE_URL points at an artifact mirror
+// serving /<tag>/<asset-name>; when unset, the release-provided URLs win.
+const releaseAPIBaseURLEnv = "MULTICA_RELEASE_API_BASE_URL"
+const releaseDownloadBaseURLEnv = "MULTICA_RELEASE_DOWNLOAD_BASE_URL"
+
const DefaultUpdateDownloadTimeout = 120 * time.Second
+func releaseAPIBaseURL() string {
+ if value := strings.TrimRight(strings.TrimSpace(os.Getenv(releaseAPIBaseURLEnv)), "/"); value != "" {
+ return value
+ }
+ return defaultReleaseAPIBaseURL
+}
+
+func releaseDownloadBaseURL() string {
+ return strings.TrimRight(strings.TrimSpace(os.Getenv(releaseDownloadBaseURLEnv)), "/")
+}
+
+func releaseAssetDownloadURL(assetName, targetVersion, fallback string) string {
+ base := releaseDownloadBaseURL()
+ if base == "" {
+ return fallback
+ }
+ return fmt.Sprintf("%s/%s/%s", base, url.PathEscape(normalizeReleaseTag(targetVersion)), url.PathEscape(assetName))
+}
+
// GitHubRelease is the subset of the GitHub releases API response we need.
type GitHubRelease struct {
TagName string `json:"tag_name"`
@@ -226,7 +254,7 @@ func verifyAssetSHA256(data []byte, expectedHex, assetName string) error {
func fetchReleaseByTag(tag string) (*GitHubRelease, error) {
client := &http.Client{Timeout: 10 * time.Second}
- req, err := http.NewRequest(http.MethodGet, "https://api.github.com/repos/multica-ai/multica/releases/tags/"+tag, nil)
+ req, err := http.NewRequest(http.MethodGet, releaseAPIBaseURL()+"/repos/multica-ai/multica/releases/tags/"+url.PathEscape(tag), nil)
if err != nil {
return nil, err
}
@@ -239,7 +267,7 @@ func fetchReleaseByTag(tag string) (*GitHubRelease, error) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("GitHub API returned %d", resp.StatusCode)
+ return nil, fmt.Errorf("release API returned %d", resp.StatusCode)
}
var release GitHubRelease
@@ -252,7 +280,7 @@ func fetchReleaseByTag(tag string) (*GitHubRelease, error) {
// FetchLatestRelease fetches the latest release tag from the multica GitHub repo.
func FetchLatestRelease() (*GitHubRelease, error) {
client := &http.Client{Timeout: 10 * time.Second}
- req, err := http.NewRequest(http.MethodGet, "https://api.github.com/repos/multica-ai/multica/releases/latest", nil)
+ req, err := http.NewRequest(http.MethodGet, releaseAPIBaseURL()+"/repos/multica-ai/multica/releases/latest", nil)
if err != nil {
return nil, err
}
@@ -265,7 +293,7 @@ func FetchLatestRelease() (*GitHubRelease, error) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("GitHub API returned %d", resp.StatusCode)
+ return nil, fmt.Errorf("release API returned %d", resp.StatusCode)
}
var release GitHubRelease
@@ -392,14 +420,15 @@ func UpdateViaDownloadWithTimeout(targetVersion string, downloadTimeout time.Dur
if err != nil {
return "", err
}
- downloadURL := asset.BrowserDownloadURL
+ downloadURL := releaseAssetDownloadURL(asset.Name, tag, asset.BrowserDownloadURL)
assetName := asset.Name
// Pull the checksum manifest first so a release that is half-published
// (archives uploaded but checksums.txt not yet) fails before we eat the
// archive's bandwidth.
timeout := updateDownloadTimeoutOrDefault(downloadTimeout)
- manifestData, err := fetchURLBytes(manifestAsset.BrowserDownloadURL, timeout)
+ manifestURL := releaseAssetDownloadURL(manifestAsset.Name, tag, manifestAsset.BrowserDownloadURL)
+ manifestData, err := fetchURLBytes(manifestURL, timeout)
if err != nil {
return "", fmt.Errorf("download checksum manifest: %w", err)
}
diff --git a/server/internal/cli/update_source_test.go b/server/internal/cli/update_source_test.go
new file mode 100644
index 0000000000..93e78e29a2
--- /dev/null
+++ b/server/internal/cli/update_source_test.go
@@ -0,0 +1,53 @@
+package cli
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+)
+
+func TestReleaseSourceDefaultsToGitHub(t *testing.T) {
+ t.Setenv(releaseAPIBaseURLEnv, "")
+ t.Setenv(releaseDownloadBaseURLEnv, "")
+
+ if got := releaseAPIBaseURL(); got != defaultReleaseAPIBaseURL {
+ t.Fatalf("release API base URL = %q, want %q", got, defaultReleaseAPIBaseURL)
+ }
+ if got := releaseAssetDownloadURL("archive.tar.gz", "v1.2.3", "https://github.example/archive.tar.gz"); got != "https://github.example/archive.tar.gz" {
+ t.Fatalf("fallback download URL = %q", got)
+ }
+}
+
+func TestReleaseSourceOverridesGitHub(t *testing.T) {
+ t.Setenv(releaseAPIBaseURLEnv, "https://mirror.example/api/")
+ t.Setenv(releaseDownloadBaseURLEnv, "https://mirror.example/releases/")
+
+ if got := releaseAPIBaseURL(); got != "https://mirror.example/api" {
+ t.Fatalf("release API base URL = %q", got)
+ }
+ if got := releaseAssetDownloadURL("multica-cli-1.2.3-linux-amd64.tar.gz", "v1.2.3", "https://github.example/archive.tar.gz"); got != "https://mirror.example/releases/v1.2.3/multica-cli-1.2.3-linux-amd64.tar.gz" {
+ t.Fatalf("mirror download URL = %q", got)
+ }
+}
+
+func TestFetchLatestReleaseUsesConfiguredAPI(t *testing.T) {
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path != "/repos/multica-ai/multica/releases/latest" {
+ http.NotFound(w, r)
+ return
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _ = json.NewEncoder(w).Encode(GitHubRelease{TagName: "v9.8.7"})
+ }))
+ defer server.Close()
+ t.Setenv(releaseAPIBaseURLEnv, server.URL)
+
+ got, err := FetchLatestRelease()
+ if err != nil {
+ t.Fatalf("FetchLatestRelease() error = %v", err)
+ }
+ if got.TagName != "v9.8.7" {
+ t.Fatalf("release tag = %q, want v9.8.7", got.TagName)
+ }
+}