From 981f49587b254ae2e48db7e407a30db062d59432 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sat, 25 Jan 2025 11:16:33 +0300 Subject: [PATCH 1/2] fix: use platform specific release in compare --- internal/overrides/overrides.go | 20 ++++++++++++ internal/translations/default.pot | 44 +++++++++++++------------- internal/translations/po/ru/default.po | 44 +++++++++++++------------- pkg/build/build.go | 5 ++- pkg/distro/osrelease.go | 2 ++ upgrade.go | 7 ++-- 6 files changed, 73 insertions(+), 49 deletions(-) diff --git a/internal/overrides/overrides.go b/internal/overrides/overrides.go index f434b01..0ba130c 100644 --- a/internal/overrides/overrides.go +++ b/internal/overrides/overrides.go @@ -20,7 +20,9 @@ package overrides import ( + "fmt" "reflect" + "regexp" "strings" "golang.org/x/exp/slices" @@ -223,3 +225,21 @@ func parseLangs(langs []string, tags []language.Tag) ([]string, error) { out = slices.Compact(out) return out, nil } + +func ReleasePlatformSpecific(release int, info *distro.OSRelease) string { + if info.ID == "altlinux" { + return fmt.Sprintf("alt%d", release) + } + + for _, v := range info.Like { + if v == "fedora" { + re := regexp.MustCompile(`platform:(\S+)`) + match := re.FindStringSubmatch(info.PlatformID) + if len(match) > 1 { + return fmt.Sprintf("%d.%s", release, match[0]) + } + } + } + + return fmt.Sprintf("%d", release) +} diff --git a/internal/translations/default.pot b/internal/translations/default.pot index 1557ecd..1305878 100644 --- a/internal/translations/default.pot +++ b/internal/translations/default.pot @@ -285,81 +285,81 @@ msgstr "" msgid "Error while running app" msgstr "" -#: pkg/build/build.go:104 +#: pkg/build/build.go:105 msgid "Failed to prompt user to view build script" msgstr "" -#: pkg/build/build.go:108 +#: pkg/build/build.go:109 msgid "Building package" msgstr "" -#: pkg/build/build.go:152 +#: pkg/build/build.go:153 msgid "Downloading sources" msgstr "" -#: pkg/build/build.go:164 +#: pkg/build/build.go:165 msgid "Building package metadata" msgstr "" -#: pkg/build/build.go:186 +#: pkg/build/build.go:187 msgid "Compressing package" msgstr "" -#: pkg/build/build.go:312 +#: pkg/build/build.go:313 msgid "" "Your system's CPU architecture doesn't match this package. Do you want to " "build anyway?" msgstr "" -#: pkg/build/build.go:323 +#: pkg/build/build.go:324 msgid "This package is already installed" msgstr "" -#: pkg/build/build.go:351 +#: pkg/build/build.go:352 msgid "Installing build dependencies" msgstr "" -#: pkg/build/build.go:393 +#: pkg/build/build.go:394 msgid "Installing dependencies" msgstr "" -#: pkg/build/build.go:439 +#: pkg/build/build.go:440 msgid "Executing version()" msgstr "" -#: pkg/build/build.go:459 +#: pkg/build/build.go:460 msgid "Updating version" msgstr "" -#: pkg/build/build.go:464 +#: pkg/build/build.go:465 msgid "Executing prepare()" msgstr "" -#: pkg/build/build.go:474 +#: pkg/build/build.go:475 msgid "Executing build()" msgstr "" -#: pkg/build/build.go:486 +#: pkg/build/build.go:487 msgid "Executing package()" msgstr "" -#: pkg/build/build.go:524 +#: pkg/build/build.go:525 msgid "Executing files()" msgstr "" -#: pkg/build/build.go:601 +#: pkg/build/build.go:600 msgid "AutoProv is not implemented for this package format, so it's skipped" msgstr "" -#: pkg/build/build.go:612 +#: pkg/build/build.go:611 msgid "AutoReq is not implemented for this package format, so it's skipped" msgstr "" -#: pkg/build/build.go:719 +#: pkg/build/build.go:718 msgid "Would you like to remove the build dependencies?" msgstr "" -#: pkg/build/build.go:825 +#: pkg/build/build.go:824 msgid "The checksums array must be the same length as sources" msgstr "" @@ -445,14 +445,14 @@ msgstr "" msgid "Pull all repositories that have changed" msgstr "" -#: upgrade.go:46 +#: upgrade.go:47 msgid "Upgrade all installed packages" msgstr "" -#: upgrade.go:82 +#: upgrade.go:83 msgid "Error checking for updates" msgstr "" -#: upgrade.go:93 +#: upgrade.go:94 msgid "There is nothing to do." msgstr "" diff --git a/internal/translations/po/ru/default.po b/internal/translations/po/ru/default.po index 79057e5..11696a2 100644 --- a/internal/translations/po/ru/default.po +++ b/internal/translations/po/ru/default.po @@ -299,27 +299,27 @@ msgstr "" msgid "Error while running app" msgstr "Ошибка при запуске приложения" -#: pkg/build/build.go:104 +#: pkg/build/build.go:105 msgid "Failed to prompt user to view build script" msgstr "Не удалось предложить пользователю просмотреть скрипт сборки" -#: pkg/build/build.go:108 +#: pkg/build/build.go:109 msgid "Building package" msgstr "Сборка пакета" -#: pkg/build/build.go:152 +#: pkg/build/build.go:153 msgid "Downloading sources" msgstr "Скачивание источников" -#: pkg/build/build.go:164 +#: pkg/build/build.go:165 msgid "Building package metadata" msgstr "Сборка метаданных пакета" -#: pkg/build/build.go:186 +#: pkg/build/build.go:187 msgid "Compressing package" msgstr "Сжатие пакета" -#: pkg/build/build.go:312 +#: pkg/build/build.go:313 msgid "" "Your system's CPU architecture doesn't match this package. Do you want to " "build anyway?" @@ -327,57 +327,57 @@ msgstr "" "Архитектура процессора вашей системы не соответствует этому пакету. Вы все " "равно хотите выполнить сборку?" -#: pkg/build/build.go:323 +#: pkg/build/build.go:324 msgid "This package is already installed" msgstr "Этот пакет уже установлен" -#: pkg/build/build.go:351 +#: pkg/build/build.go:352 msgid "Installing build dependencies" msgstr "Установка зависимостей сборки" -#: pkg/build/build.go:393 +#: pkg/build/build.go:394 msgid "Installing dependencies" msgstr "Установка зависимостей" -#: pkg/build/build.go:439 +#: pkg/build/build.go:440 msgid "Executing version()" msgstr "Исполнение версия()" -#: pkg/build/build.go:459 +#: pkg/build/build.go:460 msgid "Updating version" msgstr "Обновление версии" -#: pkg/build/build.go:464 +#: pkg/build/build.go:465 msgid "Executing prepare()" msgstr "Исполнение prepare()" -#: pkg/build/build.go:474 +#: pkg/build/build.go:475 msgid "Executing build()" msgstr "Исполнение build()" -#: pkg/build/build.go:486 +#: pkg/build/build.go:487 msgid "Executing package()" msgstr "Исполнение package()" -#: pkg/build/build.go:524 +#: pkg/build/build.go:525 msgid "Executing files()" msgstr "Исполнение package()" -#: pkg/build/build.go:601 +#: pkg/build/build.go:600 msgid "AutoProv is not implemented for this package format, so it's skipped" msgstr "" "AutoProv не реализовано для этого формата пакета, поэтому будет пропущено" -#: pkg/build/build.go:612 +#: pkg/build/build.go:611 msgid "AutoReq is not implemented for this package format, so it's skipped" msgstr "" "AutoReq не реализовано для этого формата пакета, поэтому будет пропущено" -#: pkg/build/build.go:719 +#: pkg/build/build.go:718 msgid "Would you like to remove the build dependencies?" msgstr "Хотели бы вы удалить зависимости сборки?" -#: pkg/build/build.go:825 +#: pkg/build/build.go:824 msgid "The checksums array must be the same length as sources" msgstr "Массив контрольных сумм должен быть той же длины, что и источники" @@ -465,14 +465,14 @@ msgstr "Ошибка при удалении пакетов из базы дан msgid "Pull all repositories that have changed" msgstr "Скачать все изменённые репозитории" -#: upgrade.go:46 +#: upgrade.go:47 msgid "Upgrade all installed packages" msgstr "Обновить все установленные пакеты" -#: upgrade.go:82 +#: upgrade.go:83 msgid "Error checking for updates" msgstr "Ошибка при проверке обновлений" -#: upgrade.go:93 +#: upgrade.go:94 msgid "There is nothing to do." msgstr "Здесь нечего делать." diff --git a/pkg/build/build.go b/pkg/build/build.go index 0b10ae8..2723541 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -52,6 +52,7 @@ import ( "gitea.plemya-x.ru/Plemya-x/ALR/internal/cpu" "gitea.plemya-x.ru/Plemya-x/ALR/internal/db" "gitea.plemya-x.ru/Plemya-x/ALR/internal/dl" + "gitea.plemya-x.ru/Plemya-x/ALR/internal/overrides" "gitea.plemya-x.ru/Plemya-x/ALR/internal/shutils/decoder" "gitea.plemya-x.ru/Plemya-x/ALR/internal/shutils/handlers" "gitea.plemya-x.ru/Plemya-x/ALR/internal/shutils/helpers" @@ -571,9 +572,7 @@ func buildPkgMetadata( }) } - if pkgFormat == "rpm" && info.ID == "altlinux" { - pkgInfo.Release = "alt" + pkgInfo.Release - } + pkgInfo.Release = overrides.ReleasePlatformSpecific(vars.Release, info) if vars.Epoch != 0 { pkgInfo.Epoch = strconv.FormatUint(uint64(vars.Epoch), 10) diff --git a/pkg/distro/osrelease.go b/pkg/distro/osrelease.go index b44f694..4a9e2c3 100644 --- a/pkg/distro/osrelease.go +++ b/pkg/distro/osrelease.go @@ -44,6 +44,7 @@ type OSRelease struct { SupportURL string BugReportURL string Logo string + PlatformID string } var parsed *OSRelease @@ -102,6 +103,7 @@ func ParseOSRelease(ctx context.Context) (*OSRelease, error) { SupportURL: runner.Vars["SUPPORT_URL"].Str, BugReportURL: runner.Vars["BUG_REPORT_URL"].Str, Logo: runner.Vars["LOGO"].Str, + PlatformID: runner.Vars["PLATFORM_ID"].Str, } distroUpdated := false diff --git a/upgrade.go b/upgrade.go index 5e4bca0..e7b152a 100644 --- a/upgrade.go +++ b/upgrade.go @@ -33,6 +33,7 @@ import ( "gitea.plemya-x.ru/Plemya-x/ALR/internal/config" "gitea.plemya-x.ru/Plemya-x/ALR/internal/db" + "gitea.plemya-x.ru/Plemya-x/ALR/internal/overrides" "gitea.plemya-x.ru/Plemya-x/ALR/internal/types" "gitea.plemya-x.ru/Plemya-x/ALR/pkg/build" "gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro" @@ -127,10 +128,12 @@ func checkForUpdates(ctx context.Context, mgr manager.Manager, info *distro.OSRe pkg := pkgs[0] repoVer := pkg.Version + releaseStr := overrides.ReleasePlatformSpecific(pkg.Release, info) + if pkg.Release != 0 && pkg.Epoch == 0 { - repoVer = fmt.Sprintf("%s-%d", pkg.Version, pkg.Release) + repoVer = fmt.Sprintf("%s-%s", pkg.Version, releaseStr) } else if pkg.Release != 0 && pkg.Epoch != 0 { - repoVer = fmt.Sprintf("%d:%s-%d", pkg.Epoch, pkg.Version, pkg.Release) + repoVer = fmt.Sprintf("%d:%s-%s", pkg.Epoch, pkg.Version, releaseStr) } c := vercmp.Compare(repoVer, installed[pkgName]) From 3deb6c9455c52dd939942b9bc64daa33a50f637b Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sat, 25 Jan 2025 11:54:02 +0300 Subject: [PATCH 2/2] tests: add tests for ReleasePlatformSpecific --- internal/overrides/overrides.go | 12 ++++---- internal/overrides/overrides_test.go | 41 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/internal/overrides/overrides.go b/internal/overrides/overrides.go index 0ba130c..c5710b0 100644 --- a/internal/overrides/overrides.go +++ b/internal/overrides/overrides.go @@ -231,13 +231,11 @@ func ReleasePlatformSpecific(release int, info *distro.OSRelease) string { return fmt.Sprintf("alt%d", release) } - for _, v := range info.Like { - if v == "fedora" { - re := regexp.MustCompile(`platform:(\S+)`) - match := re.FindStringSubmatch(info.PlatformID) - if len(match) > 1 { - return fmt.Sprintf("%d.%s", release, match[0]) - } + if info.ID == "fedora" || slices.Contains(info.Like, "fedora") { + re := regexp.MustCompile(`platform:(\S+)`) + match := re.FindStringSubmatch(info.PlatformID) + if len(match) > 1 { + return fmt.Sprintf("%d.%s", release, match[1]) } } diff --git a/internal/overrides/overrides_test.go b/internal/overrides/overrides_test.go index f7be20e..0d51856 100644 --- a/internal/overrides/overrides_test.go +++ b/internal/overrides/overrides_test.go @@ -24,6 +24,7 @@ import ( "reflect" "testing" + "github.com/stretchr/testify/assert" "golang.org/x/text/language" "gitea.plemya-x.ru/Plemya-x/ALR/internal/overrides" @@ -195,3 +196,43 @@ func TestResolveLangs(t *testing.T) { t.Errorf("expected %v, got %v", expected, names) } } + +func TestReleasePlatformSpecific(t *testing.T) { + + type testCase struct { + info *distro.OSRelease + expected string + } + + for _, tc := range []testCase{ + { + info: &distro.OSRelease{ + ID: "centos", + Like: []string{"rhel", "fedora"}, + PlatformID: "platform:el8", + }, + expected: "1.el8", + }, + { + info: &distro.OSRelease{ + ID: "fedora", + PlatformID: "platform:f42", + }, + expected: "1.f42", + }, + { + info: &distro.OSRelease{ + ID: "altlinux", + }, + expected: "alt1", + }, + { + info: &distro.OSRelease{ + ID: "ubuntu", + }, + expected: "1", + }, + } { + assert.Equal(t, tc.expected, overrides.ReleasePlatformSpecific(1, tc.info)) + } +}