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: remove 'v' and add release date for changelog generation #15579

Merged
merged 1 commit into from
Sep 17, 2021
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
14 changes: 12 additions & 2 deletions tools/generator/cmd/template/templateCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/tools/generator/flags"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -57,6 +58,7 @@ func BindFlags(flagSet *pflag.FlagSet) {
flagSet.String("template-path", "tools/generator/template/rpName/packageName", "Specifies the path of the template")
flagSet.String("package-title", "", "Specifies the title of this package")
flagSet.String("commit", "", "Specifies the commit hash of azure-rest-api-specs")
flagSet.String("release-date", "", "Specifies the release date in changelog")
}

// ParseFlags parses the flags to a Flags struct
Expand All @@ -66,6 +68,7 @@ func ParseFlags(flagSet *pflag.FlagSet) Flags {
TemplatePath: flags.GetString(flagSet, "template-path"),
PackageTitle: flags.GetString(flagSet, "package-title"),
Commit: flags.GetString(flagSet, "commit"),
ReleaseDate: flags.GetString(flagSet, "release-date"),
}
}

Expand All @@ -75,6 +78,7 @@ type Flags struct {
TemplatePath string
PackageTitle string
Commit string
ReleaseDate string
}

// GeneratePackageByTemplate creates a new set of files based on the things in template directory
Expand All @@ -95,7 +99,7 @@ func GeneratePackageByTemplate(rpName, packageName string, flags Flags) error {
}

// build the replaceMap
buildReplaceMap(rpName, packageName, flags.PackageTitle, flags.Commit)
buildReplaceMap(rpName, packageName, flags.PackageTitle, flags.Commit, flags.ReleaseDate)

// copy everything to destination directory
for _, file := range fileList {
Expand All @@ -119,13 +123,18 @@ func GeneratePackageByTemplate(rpName, packageName string, flags Flags) error {
return nil
}

func buildReplaceMap(rpName, packageName, packageTitle, commitID string) {
func buildReplaceMap(rpName, packageName, packageTitle, commitID, releaseDate string) {
replaceMap = make(map[string]string)

replaceMap[RPNameKey] = rpName
replaceMap[PackageNameKey] = packageName
replaceMap[PackageTitleKey] = packageTitle
replaceMap[CommitIDKey] = commitID
if releaseDate == "" {
replaceMap[ReleaseDate] = time.Now().Format("2006-01-02")
} else {
replaceMap[ReleaseDate] = releaseDate
}
}

func readAndReplace(path string) (string, error) {
Expand Down Expand Up @@ -166,4 +175,5 @@ const (
PackageTitleKey = "{{PackageTitle}}"
CommitIDKey = "{{commitID}}"
FilenameSuffix = ".tpl"
ReleaseDate = "{{releaseDate}}"
)
8 changes: 6 additions & 2 deletions tools/generator/cmd/v2/common/fileProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/tools/generator/autorest/model"
"github.com/Azure/azure-sdk-for-go/tools/generator/common"
Expand Down Expand Up @@ -219,7 +220,7 @@ func CalculateNewVersion(changelog *model.Changelog, packageRootPath string) (*s
}

// add new changelog md to changelog file
func AddChangelogToFile(changelog *model.Changelog, version *semver.Version, packageRootPath string) (string, error) {
func AddChangelogToFile(changelog *model.Changelog, version *semver.Version, packageRootPath, releaseDate string) (string, error) {
path := filepath.Join(packageRootPath, common.ChangelogFilename)
b, err := ioutil.ReadFile(path)
if err != nil {
Expand All @@ -228,7 +229,10 @@ func AddChangelogToFile(changelog *model.Changelog, version *semver.Version, pac
oldChangelog := string(b)
insertPos := strings.Index(oldChangelog, "##")
additionalChangelog := changelog.ToCompactMarkdown()
newChangelog := oldChangelog[:insertPos] + "## v" + version.String() + " (released)\n" + additionalChangelog + "\n\n" + oldChangelog[insertPos:]
if releaseDate == "" {
releaseDate = time.Now().Format("2006-01-02")
}
newChangelog := oldChangelog[:insertPos] + "## " + version.String() + " (" + releaseDate + ")\n" + additionalChangelog + "\n\n" + oldChangelog[insertPos:]
err = ioutil.WriteFile(path, []byte(newChangelog), 0644)
if err != nil {
return "", err
Expand Down
3 changes: 2 additions & 1 deletion tools/generator/cmd/v2/common/generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type GenerateParam struct {
SpecficVersion string
SpecficPackageTitle string
SpecRPName string
ReleaseDate string
}

func (ctx GenerateContext) GenerateForAutomation(readme, repo string) ([]GenerateResult, []error) {
Expand Down Expand Up @@ -191,7 +192,7 @@ func (ctx GenerateContext) GenerateForSingleRPNamespace(generateParam *GenerateP
}

log.Printf("Add changelog to file...")
changelogMd, err := AddChangelogToFile(changelog, version, packagePath)
changelogMd, err := AddChangelogToFile(changelog, version, packagePath, generateParam.ReleaseDate)
if err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions tools/generator/cmd/v2/release/releaseCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Flags struct {
PackageTitle string
SDKRepo string
SpecRPName string
ReleaseDate string
}

func BindFlags(flagSet *pflag.FlagSet) {
Expand All @@ -71,6 +72,7 @@ func BindFlags(flagSet *pflag.FlagSet) {
flagSet.String("sdk-repo", "https://github.com/Azure/azure-sdk-for-go", "Specifies the sdk repo URL for generation")
flagSet.String("spec-repo", "https://github.com/Azure/azure-rest-api-specs", "Specifies the swagger repo URL for generation")
flagSet.String("spec-rp-name", "", "Specifies the swagger spec RP name, default is RP name")
flagSet.String("release-date", "", "Specifies the release date in changelog")
}

func ParseFlags(flagSet *pflag.FlagSet) Flags {
Expand All @@ -80,6 +82,7 @@ func ParseFlags(flagSet *pflag.FlagSet) Flags {
SDKRepo: flags.GetString(flagSet, "sdk-repo"),
SwaggerRepo: flags.GetString(flagSet, "spec-repo"),
SpecRPName: flags.GetString(flagSet, "spec-rp-name"),
ReleaseDate: flags.GetString(flagSet, "release-date"),
}
}

Expand Down Expand Up @@ -146,6 +149,7 @@ func (c *commandContext) execute(sdkRepoParam, specRepoParam string) error {
SpecficPackageTitle: c.flags.PackageTitle,
SpecficVersion: c.flags.VersionNumber,
SpecRPName: c.flags.SpecRPName,
ReleaseDate: c.flags.ReleaseDate,
})
if err != nil {
return fmt.Errorf("failed to finish release generation process: %+v", err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Release History

## v0.1.0 (released)
## 0.1.0 ({{releaseDate}})