fix: publish nightly builds where dl.gitea.com does not cache them for a year (#102)

`gt upgrade --nightly` and the install scripts' nightly option could fail with a checksum mismatch, or silently install an old build. dl.gitea.com serves `gitea-cli/main/` like a released version, with `cache-control: public, max-age=31536000, immutable`, but each nightly overwrites those files, and each file then leaves the cache on its own. `gitea-cli-main-linux-amd64.xz` was still a build from Nov 2 while its `.sha256` was from Nov 5.

Directories with `nightly` in their name, such as `gitea/main-nightly` and `gitea-runner/nightly`, get `max-age=300, must-revalidate`, so nightlies now go to `gitea-cli/main-nightly`, named like Gitea's.

The v1.0.0 and v1.1.0 binaries still look in `main`, so their `gt upgrade --nightly` stays on the last build there until they upgrade to a release with this change. The CDN's rule isn't in this repository: the headers of the first nightly after this merge will confirm it applies.

Reviewed-on: https://gitea.com/gitea/cli/pulls/102
Reviewed-by: techknowlogick <[email protected]>
This commit is contained in:
bircni
2026-11-06 19:31:31 +00:00
parent f7b69d80c4
commit 65b30a62e3
5 changed files with 30 additions and 6 deletions
+2 -1
View File
@@ -187,7 +187,8 @@ snapshot:
version_template: "{{ .Branch }}-devel"
nightly:
version_template: "{{ .Branch }}"
# dl.gitea.com caches a version directory for a year; only one named nightly is replaced quickly.
version_template: "{{ .Branch }}-nightly"
gitea_urls:
api: https://gitea.com/api/v1
+1 -1
View File
@@ -312,7 +312,7 @@ func (a *application) upgrade(cmd *cobra.Command, want string, nightly, dryRun,
label := want
switch {
case nightly:
want, label = "main", "the latest nightly build"
want, label = "main-nightly", "the latest nightly build"
case want == "":
release, err := (services.Releases{Client: a.deps.Client(releaseInstance, "", false).WithResponseTimeout(a.responseTimeout()), Repository: releaseRepository}).Latest(ctx)
if err != nil {
+23
View File
@@ -107,6 +107,29 @@ func TestUpgrade(t *testing.T) {
require.NoError(t, err)
require.Len(t, entries, 1)
})
t.Run("takes a nightly build from the directory that the CDN does not cache for long", func(t *testing.T) {
platform, err := releasePlatform(runtime.GOOS, runtime.GOARCH)
require.NoError(t, err)
file := "gitea-cli-main-nightly-" + platform
build := []byte("gt nightly")
digest := sha256.Sum256(build)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/gitea-cli/main-nightly/" + file:
_, _ = w.Write(build)
case "/gitea-cli/main-nightly/" + file + ".sha256":
_, _ = fmt.Fprintf(w, "%x %s\n", digest, file)
default:
w.WriteHeader(http.StatusNotFound)
}
}))
defer server.Close()
deps, executable := releaseDeps(t, server, map[string]string{"GITEA_CLI_DOWNLOAD_URL": server.URL + "/gitea-cli"})
require.NoError(t, Execute(context.Background(), deps, []string{"upgrade", "--nightly", "--yes"}))
data, err := os.ReadFile(executable)
require.NoError(t, err)
require.Equal(t, build, data)
})
t.Run("removes the old executable on Windows when it no longer runs", func(t *testing.T) {
dir := t.TempDir()
executable, staged := filepath.Join(dir, "gt.exe"), filepath.Join(dir, "gt.new")
+2 -2
View File
@@ -28,8 +28,8 @@ if (-not $version) {
}
}
$version = $version -replace '^v', ''
# Nightly builds of the main branch are published as version main.
if ($version -eq 'nightly') { $version = 'main' }
# Nightly builds of the main branch are published as version main-nightly.
if ($version -eq 'nightly') { $version = 'main-nightly' }
$arch = switch ($env:PROCESSOR_ARCHITECTURE) {
'AMD64' { 'amd64' }
+2 -2
View File
@@ -110,8 +110,8 @@ trap 'rm -rf "$work"' EXIT INT TERM
version=${requested:-$(latest_version)}
version=${version#v}
# Nightly builds of the main branch are published as version main.
[ "$version" != nightly ] || version=main
# Nightly builds of the main branch are published as version main-nightly.
[ "$version" != nightly ] || version=main-nightly
file="gitea-cli-$version-$(platform)"
# The compressed file is smaller; without xz, the plain binary is downloaded instead.
if command -v xz >/dev/null 2>&1; then