Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support specifying the version with the package name #3

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pkg/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package pkg

import (
"fmt"
"log"

"github.com/chainguard-dev/cargobump/pkg/run"
"github.com/chainguard-dev/cargobump/pkg/types"
"golang.org/x/mod/semver"
"log"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my editor

)

func Update(patches map[string]*types.Package, pkgs []types.CargoPackage, cargoRoot string) error {
Expand All @@ -22,6 +21,19 @@ func Update(patches map[string]*types.Package, pkgs []types.CargoPackage, cargoR
}
log.Printf("Package updated successfully: %s to version %s\n", p.Name, v.Version)
}
// Try updating packages referring to a specific version
packageVersion := p.Name + "@" + p.Version
v, existsVersionRef := patches[packageVersion]
if existsVersionRef {
log.Printf("Update package with a specific version: %s\n", packageVersion)
if semver.Compare(p.Version, patches[packageVersion].Version) > 0 {
return fmt.Errorf("warning: package %s with version '%s' is already at version %s", packageVersion, v.Version, p.Version)
}
if output, err := run.CargoUpdatePackage(packageVersion, v.Version, cargoRoot); err != nil {
return fmt.Errorf("failed to run cargo update '%v' with error: '%v'", output, err)
}
log.Printf("Package updated successfully: %s to version %s\n", packageVersion, v.Version)
}
}
return nil
}
Loading