fix(ci): fix apk/dnf latestVersion implementations

- apk: use 'apk search -e' instead of 'apk policy' (more portable)
- dnf: use 'dnf info' instead of 'dnf info --available' (Fedora 39 compat)
This commit is contained in:
2026-02-26 01:58:23 +00:00
parent 99dfc80003
commit ba58e6bb8b
2 changed files with 7 additions and 12 deletions

View File

@@ -12,24 +12,18 @@ import (
)
func latestVersion(ctx context.Context, pkg string) (string, error) {
// Use `apk policy` to get available versions
c := exec.CommandContext(ctx, "apk", "policy", pkg)
// Use `apk search -e` for exact match, output is "pkg-version"
c := exec.CommandContext(ctx, "apk", "search", "-e", pkg)
out, err := c.CombinedOutput()
if err != nil {
return "", fmt.Errorf("apk latestVersion %s: %w", pkg, snack.ErrNotFound)
}
// Output format:
// pkg-1.2.3-r0:
// lib/apk/db/installed
// http://...
// First line contains the version
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
if len(lines) == 0 {
if len(lines) == 0 || lines[0] == "" {
return "", fmt.Errorf("apk latestVersion %s: %w", pkg, snack.ErrNotFound)
}
// First line: "pkg-1.2.3-r0:"
first := strings.TrimSuffix(strings.TrimSpace(lines[0]), ":")
_, ver := splitNameVersion(first)
// Output: "pkg-1.2.3-r0"
_, ver := splitNameVersion(lines[0])
if ver == "" {
return "", fmt.Errorf("apk latestVersion %s: %w", pkg, snack.ErrNotFound)
}

View File

@@ -15,7 +15,8 @@ import (
)
func latestVersion(ctx context.Context, pkg string) (string, error) {
out, err := run(ctx, []string{"info", "--available", pkg}, snack.Options{})
// Try "dnf info <pkg>" which shows both installed and available
out, err := run(ctx, []string{"info", pkg}, snack.Options{})
if err != nil {
if strings.Contains(err.Error(), "exit status 1") {
return "", fmt.Errorf("dnf latestVersion %s: %w", pkg, snack.ErrNotFound)