feat: adopt calendar versioning and reset the migration baseline (#6362)

This commit is contained in:
Johnny
2026-09-22 09:03:49 +08:00
committed by GitHub
parent e3d25e18dc
commit fa12d84606
161 changed files with 862 additions and 4759 deletions
+6 -3
View File
@@ -17,7 +17,7 @@ Usage:
install.sh [--version <version>] [--install-dir <dir>] [--repo <owner/name>] [--skip-checksum]
Environment:
MEMOS_VERSION Version to install. Accepts "0.28.1" or "v0.28.1". Defaults to latest release.
MEMOS_VERSION Version to install. Accepts "26.09" or "26.09.1". Defaults to latest release.
MEMOS_INSTALL_DIR Directory to install the binary into.
MEMOS_SKIP_CHECKSUM Set to 1 to skip checksum verification.
MEMOS_INSTALL_QUIET Set to 1 to reduce log output.
@@ -25,7 +25,7 @@ Environment:
Examples:
curl -fsSL https://raw.githubusercontent.com/usememos/memos/main/scripts/install.sh | sh
curl -fsSL https://raw.githubusercontent.com/usememos/memos/main/scripts/install.sh | sh -s -- --version 0.28.1
curl -fsSL https://raw.githubusercontent.com/usememos/memos/main/scripts/install.sh | sh -s -- --version 26.09
EOF
}
@@ -254,7 +254,10 @@ main() {
VERSION="$(normalize_version "$VERSION")"
install_dir="$(resolve_install_dir)"
tag="v${VERSION}"
case "$VERSION" in
0.*) tag="v${VERSION}" ;;
*) tag="$VERSION" ;;
esac
asset_suffix="${arch}"
if [ "$arch" = "armv7" ]; then
+79
View File
@@ -0,0 +1,79 @@
package scripts
import (
"crypto/sha256"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestInstallRelease(t *testing.T) {
for _, tc := range []struct{ input, tag string }{
{"26.09", "26.09"},
{"26.09.1", "26.09.1"},
{"v26.09.1", "26.09.1"},
{"26.09-rc.1", "26.09-rc.1"},
{"0.31.0", "v0.31.0"},
{"v0.31.0", "v0.31.0"},
{"", "26.09.2"},
{"", "v0.31.0"},
} {
input, tag := tc.input, tc.tag
t.Run("version="+input, func(t *testing.T) {
dir := t.TempDir()
mockBin := filepath.Join(dir, "bin")
require.NoError(t, os.Mkdir(mockBin, 0755))
version := strings.TrimPrefix(tag, "v")
writeExecutable(t, filepath.Join(dir, "memos"), "#!/bin/sh\nprintf '%s\\n' '"+version+"'\n")
archive := filepath.Join(dir, "release.tar.gz")
out, err := exec.Command("tar", "-czf", archive, "-C", dir, "memos").CombinedOutput()
require.NoError(t, err, string(out))
data, err := os.ReadFile(archive)
require.NoError(t, err)
asset := "memos_" + version + "_linux_amd64.tar.gz"
require.NoError(t, os.WriteFile(filepath.Join(dir, "checksums.txt"), []byte(fmt.Sprintf("%x %s\n", sha256.Sum256(data), asset)), 0644))
writeExecutable(t, filepath.Join(mockBin, "uname"), "#!/bin/sh\ncase $1 in -s) echo Linux;; -m) echo x86_64;; esac\n")
writeExecutable(t, filepath.Join(mockBin, "curl"), `#!/bin/sh
set -eu
url= dest=
while [ "$#" -gt 0 ]; do
case "$1" in
-o) dest="$2"; shift 2;;
-H) shift 2;;
-*) shift;;
*) url="$1"; shift;;
esac
done
printf '%s\n' "$url" >> "$TEST_DOWNLOAD_LOG"
case "$url" in
*/releases/latest) printf '{"tag_name":"%s"}\n' "$TEST_TAG";;
*/checksums.txt) cp "$TEST_FIXTURE/checksums.txt" "$dest";;
*/memos_*.tar.gz) cp "$TEST_FIXTURE/release.tar.gz" "$dest";;
*) exit 1;;
esac
`)
args := []string{"install.sh", "--install-dir", filepath.Join(dir, "installed")}
if input != "" {
args = append(args, "--version", input)
}
cmd := exec.Command("sh", args...)
logPath := filepath.Join(dir, "downloads.log")
cmd.Env = append(os.Environ(), "PATH="+mockBin+string(os.PathListSeparator)+os.Getenv("PATH"), "TEST_FIXTURE="+dir,
"TEST_TAG="+tag, "TEST_DOWNLOAD_LOG="+logPath, "MEMOS_VERSION=", "MEMOS_SKIP_CHECKSUM=0", "REPO=usememos/memos")
out, err = cmd.CombinedOutput()
require.NoError(t, err, string(out))
log, err := os.ReadFile(logPath)
require.NoError(t, err)
require.Contains(t, string(log), "https://github.com/usememos/memos/releases/download/"+tag+"/"+asset)
require.Contains(t, string(log), "/"+tag+"/checksums.txt")
out, err = exec.Command(filepath.Join(dir, "installed", "memos")).CombinedOutput()
require.NoError(t, err)
require.Equal(t, version+"\n", string(out))
})
}
}
+3 -21
View File
@@ -24,7 +24,7 @@ Docker image. With no options, the current worktree is built and tested.
Options:
--candidate-image IMAGE Test an existing image instead of building locally.
--previous-image IMAGE Image used to seed the upgrade test. By default, the
latest stable Git tag before HEAD is used.
latest supported stable Git tag before HEAD is used.
--keep-resources Keep containers and volumes after the test for debugging.
-h, --help Show this help text.
@@ -37,7 +37,7 @@ Examples:
./scripts/release_smoke_test.sh
./scripts/release_smoke_test.sh \
--candidate-image memos-smoke:local \
--previous-image neosmemo/memos:0.29.1
--previous-image neosmemo/memos:0.31.0
EOF
}
@@ -142,25 +142,7 @@ cleanup() {
trap cleanup EXIT
detect_previous_image() {
local head_sha tag tag_sha
head_sha="$(git -C "$REPO_ROOT" rev-parse HEAD)"
while IFS= read -r tag; do
case "$tag" in
*-rc.*) continue ;;
esac
tag_sha="$(git -C "$REPO_ROOT" rev-list -n 1 "$tag")"
if [[ "$tag_sha" == "$head_sha" ]]; then
continue
fi
if git -C "$REPO_ROOT" merge-base --is-ancestor "$tag" HEAD; then
printf 'neosmemo/memos:%s\n' "${tag#v}"
return
fi
done < <(git -C "$REPO_ROOT" tag --list 'v[0-9]*' --sort=-version:refname)
die "could not detect a previous stable release; pass --previous-image"
bash "$SCRIPT_DIR/release_version.sh" previous-image "$REPO_ROOT"
}
build_local_candidate() {
+87
View File
@@ -0,0 +1,87 @@
#!/usr/bin/env bash
set -euo pipefail
# Application releases use YY.MM[.N][-rc.N]. Database migration sequences are separate.
parse_release_tag() {
local tag="$1"
if [[ ! "$tag" =~ ^([1-9][0-9]\.(0[1-9]|1[0-2]))(\.([1-9][0-9]*))?(-rc\.([1-9][0-9]*))?$ ]]; then
return 1
fi
RELEASE_VERSION="$tag"
RELEASE_SERIES="${BASH_REMATCH[1]}"
RELEASE_IS_PRERELEASE=false
if [[ -n "${BASH_REMATCH[5]}" ]]; then
RELEASE_IS_PRERELEASE=true
fi
}
# previous_release_tag prints the newest stable release tag that is an ancestor
# of HEAD, excluding tags on HEAD itself. Legacy v0.31.x tags count because
# v0.31.0 is the fixed upgrade baseline.
previous_release_tag() {
local repo="$1" head_sha tag tag_sha
head_sha="$(git -C "$repo" rev-parse HEAD)"
# List calendar releases first: the legacy v prefix would otherwise sort ahead.
while IFS= read -r tag; do
if parse_release_tag "$tag"; then
[[ "$RELEASE_IS_PRERELEASE" == false ]] || continue
elif [[ ! "$tag" =~ ^v0\.31\.(0|[1-9][0-9]*)$ ]]; then
continue
fi
tag_sha="$(git -C "$repo" rev-list -n 1 "$tag")"
[[ "$tag_sha" != "$head_sha" ]] || continue
if git -C "$repo" merge-base --is-ancestor "$tag" HEAD; then
printf '%s\n' "$tag"
return
fi
done < <(
git -C "$repo" tag --list '[1-9][0-9].*' --sort=-version:refname
git -C "$repo" tag --list 'v0.31.*' --sort=-version:refname
)
echo 'No supported previous release found' >&2
return 1
}
previous_release_image() {
local tag
if ! tag="$(previous_release_tag "$1")"; then
echo 'Pass --previous-image' >&2
return 1
fi
printf 'neosmemo/memos:%s\n' "${tag#v}"
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
case "${1:-}" in
previous-tag)
previous_release_tag "${2:?repository required}"
exit
;;
previous-image)
previous_release_image "${2:?repository required}"
exit
;;
esac
tag="${2:?release tag required}"
if ! parse_release_tag "$tag"; then
echo "Unsupported release tag format: $tag" >&2
exit 1
fi
case "${1:-}" in
version)
printf 'tag=%s\nversion=%s\nseries=%s\nis_prerelease=%s\n' \
"$tag" "$RELEASE_VERSION" "$RELEASE_SERIES" "$RELEASE_IS_PRERELEASE"
;;
image-tags)
printf '%s\n' "$RELEASE_VERSION"
if [[ "$RELEASE_IS_PRERELEASE" == false ]]; then
if [[ "$RELEASE_SERIES" != "$RELEASE_VERSION" ]]; then
printf '%s\n' "$RELEASE_SERIES"
fi
printf 'stable\n'
fi
;;
*) echo "Unknown release command: ${1:-}" >&2; exit 1 ;;
esac
fi
+95
View File
@@ -0,0 +1,95 @@
package scripts
import (
"os/exec"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestReleaseVersions(t *testing.T) {
for _, tc := range []struct {
tag, series, prerelease, images string
}{
{"26.09", "26.09", "false", "26.09\nstable\n"},
{"26.09.1", "26.09", "false", "26.09.1\n26.09\nstable\n"},
{"26.09.10", "26.09", "false", "26.09.10\n26.09\nstable\n"},
{"26.10.1", "26.10", "false", "26.10.1\n26.10\nstable\n"},
{"27.01", "27.01", "false", "27.01\nstable\n"},
{"26.09-rc.1", "26.09", "true", "26.09-rc.1\n"},
{"26.09.1-rc.2", "26.09", "true", "26.09.1-rc.2\n"},
} {
t.Run(tc.tag, func(t *testing.T) {
out, err := exec.Command("bash", "release_version.sh", "version", tc.tag).CombinedOutput()
require.NoError(t, err, string(out))
require.Equal(t, "tag="+tc.tag+"\nversion="+tc.tag+"\nseries="+tc.series+"\nis_prerelease="+tc.prerelease+"\n", string(out))
out, err = exec.Command("bash", "release_version.sh", "image-tags", tc.tag).CombinedOutput()
require.NoError(t, err, string(out))
require.Equal(t, tc.images, string(out))
})
}
for _, tag := range []string{"v0.31.0", "v26.09", "v26.09.1", "v26.09-rc.1", "26.9", "26.00", "26.13", "2026.09", "26.09.0", "26.09.01", "26.09-rc.0", "26.09-rc.01", "26.09beta", "26.09.1+build"} {
out, err := exec.Command("bash", "release_version.sh", "version", tag).CombinedOutput()
require.Error(t, err, tag)
require.Contains(t, string(out), "Unsupported release tag")
}
}
func TestPreviousReleaseImage(t *testing.T) {
repo := t.TempDir()
runGit := func(args ...string) {
t.Helper()
cmd := exec.Command("git", append([]string{"-C", repo, "-c", "user.name=Release Test", "-c", "user.email=test@example.com", "-c", "commit.gpgsign=false"}, args...)...)
out, err := cmd.CombinedOutput()
require.NoError(t, err, string(out))
}
check := func(want string) {
t.Helper()
out, err := exec.Command("bash", "release_version.sh", "previous-tag", repo).CombinedOutput()
require.NoError(t, err, string(out))
require.Equal(t, want+"\n", string(out))
out, err = exec.Command("bash", "release_version.sh", "previous-image", repo).CombinedOutput()
require.NoError(t, err, string(out))
require.Equal(t, "neosmemo/memos:"+strings.TrimPrefix(want, "v")+"\n", string(out))
}
runGit("init", "-b", "main")
runGit("commit", "--allow-empty", "-m", "old")
runGit("tag", "v0.30.0")
runGit("commit", "--allow-empty", "-m", "baseline")
runGit("tag", "v0.31.0")
runGit("commit", "--allow-empty", "-m", "first calendar release")
runGit("tag", "26.09")
check("v0.31.0")
runGit("commit", "--allow-empty", "-m", "point release")
runGit("tag", "26.09.2")
check("26.09")
runGit("commit", "--allow-empty", "-m", "tenth point release")
runGit("tag", "26.09.10")
runGit("tag", "99.99")
runGit("commit", "--allow-empty", "-m", "release candidate")
runGit("tag", "26.10-rc.1")
check("26.09.10")
runGit("commit", "--allow-empty", "-m", "after release candidate")
check("26.09.10")
runGit("checkout", "--orphan", "unrelated")
runGit("commit", "--allow-empty", "-m", "unrelated release")
runGit("tag", "29.01")
runGit("checkout", "main")
check("26.09.10")
runGit("tag", "26.10")
runGit("commit", "--allow-empty", "-m", "next year")
runGit("tag", "27.01")
check("26.10")
// The floor excludes pre-baseline tags even if no supported release exists.
repo = t.TempDir()
runGit("init", "-b", "main")
runGit("commit", "--allow-empty", "-m", "old")
runGit("tag", "v0.30.0")
runGit("commit", "--allow-empty", "-m", "candidate")
for _, command := range []string{"previous-tag", "previous-image"} {
out, err := exec.Command("bash", "release_version.sh", command, repo).CombinedOutput()
require.Error(t, err, command)
require.Contains(t, string(out), "No supported previous release found")
}
}