From 892d67644bbce592f8299dc665cb00d418c4da92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E5=B7=9D=E7=99=BD=E6=B5=AA?= <1679659@qq.com> Date: Sat, 5 Dec 2026 02:19:03 -0700 Subject: [PATCH] fix(runtime): fall back to Reims-Go releases --- changes/runtime-release-fallback.json | 7 +++++++ internal/runtime/remote.go | 29 +++++++++++++++++++++------ internal/runtime/remote_test.go | 25 +++++++++++++++++++++-- 3 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 changes/runtime-release-fallback.json diff --git a/changes/runtime-release-fallback.json b/changes/runtime-release-fallback.json new file mode 100644 index 0000000..b0bf729 --- /dev/null +++ b/changes/runtime-release-fallback.json @@ -0,0 +1,7 @@ +{ + "group": "fixes", + "order": 0, + "authors": ["Nwflower"], + "zh": "主运行时发布仓库无法访问时,自动从 `Nwflower/Reims-Go` 检查可用运行时。", + "en": "Check `Nwflower/Reims-Go` for available runtimes when the primary runtime release repository is unavailable." +} diff --git a/internal/runtime/remote.go b/internal/runtime/remote.go index 5d5da79..53ecbb6 100644 --- a/internal/runtime/remote.go +++ b/internal/runtime/remote.go @@ -27,11 +27,12 @@ import ( ) const ( - DefaultReleasesRepo = "reims-go/reims-vgpu" - DefaultAPIBase = "https://api.github.com" - DefaultWebBase = "https://github.com" - runtimeTagPrefix = "runtime-" - sumsAsset = fetch.SumsAsset + DefaultReleasesRepo = "reims-go/reims-vgpu" + fallbackReleasesRepo = "Nwflower/Reims-Go" + DefaultAPIBase = "https://api.github.com" + DefaultWebBase = "https://github.com" + runtimeTagPrefix = "runtime-" + sumsAsset = fetch.SumsAsset ) var errRateLimited = errors.New("GitHub API rate limit reached") @@ -145,8 +146,24 @@ func (s Source) webBase() string { } // ListRemote lists published runtime packages, newest first. Alpha runtimes -// are included only when includeAlpha is set. +// are included only when includeAlpha is set. If the default repository cannot +// be listed, it tries the original Reims-Go releases repository. func (s Source) ListRemote(ctx context.Context, includeAlpha bool) ([]Remote, error) { + list, err := s.listRemote(ctx, includeAlpha) + if err == nil || s.Repo != DefaultReleasesRepo || ctx.Err() != nil { + return list, err + } + + fallback := s + fallback.Repo = fallbackReleasesRepo + list, fallbackErr := fallback.listRemote(ctx, includeAlpha) + if fallbackErr != nil { + return nil, fmt.Errorf("%s: %w; %s: %w", s.Repo, err, fallback.Repo, fallbackErr) + } + return list, nil +} + +func (s Source) listRemote(ctx context.Context, includeAlpha bool) ([]Remote, error) { base := strings.TrimRight(s.APIBase, "/") url := fmt.Sprintf("%s/repos/%s/releases?per_page=100", base, s.Repo) var rels []ghRelease diff --git a/internal/runtime/remote_test.go b/internal/runtime/remote_test.go index 34fb82d..7efceeb 100644 --- a/internal/runtime/remote_test.go +++ b/internal/runtime/remote_test.go @@ -28,7 +28,7 @@ func newFakeGitHub(t *testing.T) *fakeGitHub { sum := sha256.Sum256(g.archive) g.sums = hex.EncodeToString(sum[:]) + " reims-runtime-win-x64-abc1234.tar.zst\n" mux := http.NewServeMux() - mux.HandleFunc("/repos/o/r/releases", func(w http.ResponseWriter, r *http.Request) { + listReleases := func(w http.ResponseWriter, r *http.Request) { if r.Header.Get("User-Agent") != "reims-go" { t.Errorf("User-Agent = %q", r.Header.Get("User-Agent")) } @@ -48,7 +48,9 @@ func newFakeGitHub(t *testing.T) *fakeGitHub { {"tag_name":"runtime-draft00","draft":true,"assets":[]}, {"tag_name":"v0.1.0","prerelease":false,"assets":[]} ]`, len(g.archive), base, base, base, base, base, base, base, base) - }) + } + mux.HandleFunc("/repos/o/r/releases", listReleases) + mux.HandleFunc("/repos/Nwflower/Reims-Go/releases", listReleases) mux.HandleFunc("/a/archive", func(w http.ResponseWriter, r *http.Request) { g.hits["archive"]++ if r.Header.Get("Range") != "" { @@ -78,6 +80,25 @@ func TestDefaultSourceRepository(t *testing.T) { } } +func TestListRemoteFallsBackFromUnavailableDefaultRepository(t *testing.T) { + g := newFakeGitHub(t) + src := g.source() + src.Repo = DefaultReleasesRepo // This repository returns 404 in the fixture. + stable, err := src.ListRemote(context.Background(), false) + if err != nil || len(stable) != 1 || stable[0].Commit != "0000old" { + t.Fatalf("fallback stable releases = %+v, err = %v", stable, err) + } + all, err := src.ListRemote(context.Background(), true) + if err != nil || len(all) != 2 || all[0].Commit != "abc1234" { + t.Fatalf("fallback alpha and stable releases = %+v, err = %v", all, err) + } + + src.Repo = "example/runtime" + if list, err := src.ListRemote(context.Background(), true); err == nil { + t.Fatalf("custom repository attempted fallback, releases = %+v", list) + } +} + func TestListRemoteFiltersChannelsAndIncompleteReleases(t *testing.T) { g := newFakeGitHub(t) stable, err := g.source().ListRemote(context.Background(), false)