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

Add ability to output version to a separate file #65

Merged
merged 1 commit into from
Feb 8, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CHANGELOG.md
VERSION
/test/results
/dist
/snapshot
Expand Down
16 changes: 16 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func setCreateFlags(flags *pflag.FlagSet) {
fmt.Sprintf("output format to use: %+v", format.All()),
)

flags.StringP(
"version-file", "", "",
"output the current version of the generated changelog to the given file",
)

flags.StringP(
"since-tag", "s", "",
"tag to start changelog processing from (inclusive)",
Expand Down Expand Up @@ -85,6 +90,7 @@ func bindCreateConfigOptions(flags *pflag.FlagSet) error {
"until-tag",
"title",
"speculate-next-version",
"version-file",
} {
if err := viper.BindPFlag(flag, flags.Lookup(flag)); err != nil {
return err
Expand All @@ -101,6 +107,16 @@ func runCreate(cmd *cobra.Command, args []string) error {
return err
}

if appConfig.VersionFile != "" {
f, err := os.OpenFile(appConfig.VersionFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
return fmt.Errorf("unable to open version file %q: %w", appConfig.VersionFile, err)
}
if _, err := f.WriteString(description.Version); err != nil {
return fmt.Errorf("unable to write version to file %q: %w", appConfig.VersionFile, err)
}
}

f := format.FromString(appConfig.Output)
if f == nil {
return fmt.Errorf("unable to parse output format: %q", appConfig.Output)
Expand Down
5 changes: 3 additions & 2 deletions internal/config/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ type Application struct {
Log logging `yaml:"log" json:"log" mapstructure:"log"` // all logging-related options
CliOptions CliOnlyOptions `yaml:"-" json:"-"` // all options only available through the CLI (not via env vars or config)
SpeculateNextVersion bool `yaml:"speculate-next-version" json:"speculate-next-version" mapstructure:"speculate-next-version"` // -n, guess the next version based on issues and PRs
SinceTag string `yaml:"since-tag" json:"since-tag" mapstructure:"since-tag"`
UntilTag string `yaml:"until-tag" json:"until-tag" mapstructure:"until-tag"`
VersionFile string `yaml:"version-file" json:"version-file" mapstructure:"version-file"` // --version-file, the path to a file containing the version to use for the changelog
SinceTag string `yaml:"since-tag" json:"since-tag" mapstructure:"since-tag"` // -s, the tag to start the changelog from
UntilTag string `yaml:"until-tag" json:"until-tag" mapstructure:"until-tag"` // -u, the tag to end the changelog at
EnforceV0 bool `yaml:"enforce-v0" json:"enforce-v0" mapstructure:"enforce-v0"`
Title string `yaml:"title" json:"title" mapstructure:"title"`
Github githubSummarizer `yaml:"github" json:"github" mapstructure:"github"`
Expand Down