ParsePackageOverrideString parses a package version override string into a structure. Logic should align with PackageVersionResolver in the Octopus Server and .NET CLI In cases where things are ambiguous, we look in steps for matching values to see if something is a PackageID or a StepName
(packageOverride string)
| 297 | // Logic should align with PackageVersionResolver in the Octopus Server and .NET CLI |
| 298 | // In cases where things are ambiguous, we look in steps for matching values to see if something is a PackageID or a StepName |
| 299 | func ParsePackageOverrideString(packageOverride string) (*AmbiguousPackageVersionOverride, error) { |
| 300 | if packageOverride == "" { |
| 301 | return nil, errors.New("empty package version specification") |
| 302 | } |
| 303 | |
| 304 | components := splitPackageOverrideString(packageOverride) |
| 305 | packageReferenceName, stepNameOrPackageID, version := "", "", "" |
| 306 | |
| 307 | switch len(components) { |
| 308 | case 2: |
| 309 | // if there are two components it is (StepName|PackageID):Version |
| 310 | stepNameOrPackageID, version = strings.TrimSpace(components[0]), strings.TrimSpace(components[1]) |
| 311 | case 3: |
| 312 | // if there are three components it is (StepName|PackageID):PackageReferenceName:Version |
| 313 | stepNameOrPackageID, packageReferenceName, version = strings.TrimSpace(components[0]), strings.TrimSpace(components[1]), strings.TrimSpace(components[2]) |
| 314 | default: |
| 315 | return nil, fmt.Errorf("package version specification \"%s\" does not use expected format", packageOverride) |
| 316 | } |
| 317 | |
| 318 | // must always specify a version; must specify either packageID, stepName or both |
| 319 | if version == "" { |
| 320 | return nil, fmt.Errorf("package version specification \"%s\" does not use expected format", packageOverride) |
| 321 | } |
| 322 | if !isValidVersion(version) { |
| 323 | return nil, fmt.Errorf("version component \"%s\" is not a valid version", version) |
| 324 | } |
| 325 | |
| 326 | // compensate for wildcards |
| 327 | if packageReferenceName == "*" { |
| 328 | packageReferenceName = "" |
| 329 | } |
| 330 | if stepNameOrPackageID == "*" { |
| 331 | stepNameOrPackageID = "" |
| 332 | } |
| 333 | |
| 334 | return &AmbiguousPackageVersionOverride{ |
| 335 | ActionNameOrPackageID: stepNameOrPackageID, |
| 336 | PackageReferenceName: packageReferenceName, |
| 337 | Version: version, |
| 338 | }, nil |
| 339 | } |
| 340 | |
| 341 | func ResolvePackageOverride(override *AmbiguousPackageVersionOverride, steps []*StepPackageVersion) (*PackageVersionOverride, error) { |
| 342 | // shortcut for wildcard matches; these match everything so we don't need to do any work |
no test coverage detected