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

feat(contrib): manage promote/release cargo crate #6611

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
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
25 changes: 20 additions & 5 deletions contrib/integrations/artifactory/artifactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,18 @@ func CreateArtifactoryClient(ctx context.Context, url, token string) (artifactor
}

func PromoteFile(artiClient artifact_manager.ArtifactManager, data sdk.WorkflowRunResultArtifactManager, lowMaturity, highMaturity string, props *utils.Properties, skipExistingArtifacts bool) error {
srcRepo := fmt.Sprintf("%s-%s", data.RepoName, lowMaturity)
targetRepo := fmt.Sprintf("%s-%s", data.RepoName, highMaturity)
// artifactory does not manage virtual cargo repositories
var srcRepo, targetRepo string
sguiheux marked this conversation as resolved.
Show resolved Hide resolved
switch data.RepoType {
case "cargo":
repoParts := strings.Split(data.RepoName, "-")
srcRepo = fmt.Sprintf("%s-%s", strings.Join(repoParts[:len(repoParts)-1], "-"), lowMaturity)
targetRepo = fmt.Sprintf("%s-%s", strings.Join(repoParts[:len(repoParts)-1], "-"), highMaturity)
default:
srcRepo = fmt.Sprintf("%s-%s", data.RepoName, lowMaturity)
targetRepo = fmt.Sprintf("%s-%s", data.RepoName, highMaturity)
}

params := services.NewMoveCopyParams()
params.Pattern = fmt.Sprintf("%s/%s", srcRepo, data.Path)
params.Target = fmt.Sprintf("%s/%s", targetRepo, data.Path)
Expand Down Expand Up @@ -170,7 +180,7 @@ func PromoteDockerImage(ctx context.Context, artiClient artifact_manager.Artifac
}

if props != nil {
if err := SetPropertiesRecursive(ctx, artiClient, data.RepoName, highMaturity, data.Path, props); err != nil {
if err := SetPropertiesRecursive(ctx, artiClient, data.RepoType, data.RepoName, highMaturity, data.Path, props); err != nil {
return err
}
}
Expand Down Expand Up @@ -334,23 +344,28 @@ func computeBuildInfoModules(ctx context.Context, artiClient artifact_manager.Ar
props.AddProperty("build.number", execContext.version)
props.AddProperty("build.timestamp", strconv.FormatInt(time.Now().Unix(), 10))

if err := SetPropertiesRecursive(ctx, artiClient, data.RepoName, currentMaturity, data.Path, props); err != nil {
if err := SetPropertiesRecursive(ctx, artiClient, data.RepoType, data.RepoName, currentMaturity, data.Path, props); err != nil {
return nil, err
}

}
return modules, nil
}

func SetPropertiesRecursive(ctx context.Context, client artifact_manager.ArtifactManager, repoName string, maturity string, path string, props *utils.Properties) error {
func SetPropertiesRecursive(ctx context.Context, client artifact_manager.ArtifactManager, repoType string, repoName string, maturity string, path string, props *utils.Properties) error {
ctx, end := telemetry.Span(ctx, "artifactory.SetPropertiesRecursive")
defer end()
if props == nil {
return nil
}

repoSrc := repoName
if repoType == "cargo" {
repoParts := strings.Split(repoName, "-")
repoSrc = fmt.Sprintf("%s", strings.Join(repoParts[:len(repoParts)-1], "-"))
}
repoSrc += "-" + maturity

log.Debug(ctx, "setting properties %+v on repoSrc:%s path:%s", props, repoSrc, path)
_, endc := telemetry.Span(ctx, "artifactory.SetProperties", telemetry.Tag("repoSrc", repoSrc))
if err := client.SetProperties(repoSrc, path, props); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ func (e *artifactoryReleasePlugin) Run(ctx context.Context, opts *integrationplu
if err := art.PromoteFile(artifactClient, rData, latestPromotion.FromMaturity, latestPromotion.ToMaturity, props, true); err != nil {
return fail("unable to promote file: %s: %v", rData.Name, err)
}
promotedArtifacts = append(promotedArtifacts, fmt.Sprintf("%s-%s/%s", rData.RepoName, latestPromotion.ToMaturity, rData.Path))
// artifactory does not manage virtual cargo repositories
if rData.RepoType == "cargo" {
sguiheux marked this conversation as resolved.
Show resolved Hide resolved
repoParts := strings.Split(rData.RepoName, "-")
promotedArtifacts = append(promotedArtifacts, fmt.Sprintf("%s-%s/%s", strings.Join(repoParts[:len(repoParts)-1], "-"), latestPromotion.ToMaturity, rData.Path))
} else {
promotedArtifacts = append(promotedArtifacts, fmt.Sprintf("%s-%s/%s", rData.RepoName, latestPromotion.ToMaturity, rData.Path))
}
}
}

Expand Down