From 333a4a4a09cc0ad1b91eca43ef58c5cd205b8c68 Mon Sep 17 00:00:00 2001 From: ArcturusZhang Date: Fri, 18 Jun 2021 10:48:34 +0800 Subject: [PATCH] initial change to squash the package files --- .../generator/cmd/automation/automationCmd.go | 20 ++++++++++++++++++- .../cmd/automation/pipeline/model.go | 4 ++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tools/generator/cmd/automation/automationCmd.go b/tools/generator/cmd/automation/automationCmd.go index f6ec05777dcd..338845b07da4 100644 --- a/tools/generator/cmd/automation/automationCmd.go +++ b/tools/generator/cmd/automation/automationCmd.go @@ -253,10 +253,28 @@ func (ctx *automationContext) generate(input *pipeline.GenerateInput) (*pipeline } return &pipeline.GenerateOutput{ - Packages: results, + Packages: squashResults(results), }, errorBuilder.build() } +// squashResults squashes the package results by appending all of the `path`s in the following items to the first item +// By doing this, the SDK automation pipeline will only create one PR that contains all of the generation results +// instead of creating one PR for each generation result. +// This is to reduce the resource cost on GitHub +func squashResults(packages []pipeline.PackageResult) []pipeline.PackageResult { + if len(packages) == 0 { + return packages + } + for i := 1; i < len(packages); i++ { + // append the path of the i-th item to the first + packages[0].Path = append(packages[0].Path, packages[i].Path...) + // erase the path on the i-th item + packages[i].Path = make([]string, 0) + } + + return packages +} + func (ctx *automationContext) readRepoContent() error { ctx.repoContent = make(map[string]exports.Content) pkgs, err := track1.List(filepath.Join(ctx.sdkRoot, "services")) diff --git a/tools/generator/cmd/automation/pipeline/model.go b/tools/generator/cmd/automation/pipeline/model.go index 577b5aae5c2e..b84e207cd374 100644 --- a/tools/generator/cmd/automation/pipeline/model.go +++ b/tools/generator/cmd/automation/pipeline/model.go @@ -76,8 +76,8 @@ func (o GenerateOutput) WriteTo(writer io.Writer) (int64, error) { type PackageResult struct { Version string `json:"version,omitempty"` PackageName string `json:"packageName,omitempty"` - Path []string `json:"path,omitempty"` - ReadmeMd []string `json:"readmeMd,omitempty"` + Path []string `json:"path"` + ReadmeMd []string `json:"readmeMd"` Changelog *Changelog `json:"changelog,omitempty"` Artifacts []string `json:"artifacts,omitempty"` InstallInstructions *InstallInstructionScriptOutput `json:"installInstructions,omitempty"`