Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/anchore/sbom-actio…
Browse files Browse the repository at this point in the history
…n-0.15.2
  • Loading branch information
olblak committed Jan 4, 2024
2 parents 5a66deb + 1581da6 commit 9cb6ef8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 29 deletions.
9 changes: 9 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (

"github.com/spf13/cobra"
"github.com/updatecli/releasepost/internal/core/config"
"github.com/updatecli/releasepost/internal/core/dryrun"
"github.com/updatecli/releasepost/internal/core/engine"
"github.com/updatecli/releasepost/internal/core/result"
)

var (
configFile string
e engine.Engine
dryRun bool

rootCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -22,6 +24,12 @@ var (
fmt.Printf("Failed to initialize releasepost: %v", err)
os.Exit(2)
}

fmt.Println("Running releasepost")
if dryRun {
dryrun.Enabled = true
fmt.Println("Dry run mode enabled, no changelog will be saved to disk")
}
err = e.Run()
if err != nil {
fmt.Printf("Failed to run releasepost: %v", err)
Expand All @@ -42,6 +50,7 @@ and then copy them to locally to a directory of your choice.

func init() {
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "Releasepost configuration file")
rootCmd.PersistentFlags().BoolVarP(&dryRun, "dry-run", "d", false, "Dry run mode")
rootCmd.AddCommand(
versionCmd,
)
Expand Down
18 changes: 10 additions & 8 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ changelogs:
frontmatters: |
---
title: "{{ .Changelog.Name }}"
--
- extension: json
frontmatters: |
date: {{ .Changelog.PublishedAt }}
---
title: "{{ .Changelog.Name }}"
--
indexfrontmatters: |
---
title: "Index Changelog"
---
- extension: json
- extension: markdown
frontmatters: |
---
title: "{{ .Changelog.Name }}"
--
date: {{ .Changelog.PublishedAt }}
---
indexfrontmatters: |
---
title: "Custom Changelog"
--
title: "Index Changelog"
---
spec:
# No release
# owner: updatecli-test
Expand Down
11 changes: 10 additions & 1 deletion examples/hugo/.releaserepost.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ changelogs:
dir: content/en/docs/changelogs/updatecli
formats:
- extension: asciidoc
frontmatters: |
---
title: "{{ .Changelog.Name }}"
date: {{ .Changelog.PublishedAt }}
---
indexfilename: _index
indexfrontmatters: |
---
title: "Index Changelog"
---
- extension: json
indexfilename: _index
spec:
owner: updatecli
repository: updatecli
repository: udash
12 changes: 1 addition & 11 deletions internal/core/changelog/configFormat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,9 @@ var (
defaultFormats = []ConfigFormat{
{
Extension: "markdown",
IndexFileName: "_index",
IndexFileName: "index",
},
}

// defaultIndexFileName is the default front matters using yaml syntax to add to the index file.
defaultIndexFrontMatters = `---
title: Changelogs
---`

defaultFrontMatters = `---
title: "{{ .Changelog.Name }}"
date: {{ .Changelog.PublishedAt }}
---`
)

type ConfigFormat struct {
Expand Down
8 changes: 8 additions & 0 deletions internal/core/changelog/frontmatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import (
"text/template"
)

var (
// defaultIndexFileName is the default front matters using yaml syntax to add to the index file.
defaultIndexFrontMatters = ""

// defaultFrontMatters is the default front matters using yaml syntax to add to the changelog file.
defaultFrontMatters = ""
)

func renderFrontMatters(data interface{}, frontMatters string) (string, error) {

tmpl, err := template.New("frontmatters").Parse(frontMatters)
Expand Down
21 changes: 12 additions & 9 deletions internal/core/changelog/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"

"github.com/updatecli/releasepost/internal/core/dryrun"
"github.com/updatecli/releasepost/internal/core/result"
)

Expand All @@ -26,15 +27,17 @@ func dataToFile(data []byte, filename string) error {
currentChecksum := getChecksumFromFile(filename)
newChecksum := getChecksumFromByte(data)

f, err := os.Create(filename)
if err != nil {
fmt.Printf("creating file %s: %v", filename, err)
return err
}
defer f.Close()
_, err = f.Write(data)
if err != nil {
fmt.Printf("writing file %s: %v", filename, err)
if !dryrun.Enabled {
f, err := os.Create(filename)
if err != nil {
fmt.Printf("creating file %s: %v", filename, err)
return err
}
defer f.Close()
_, err = f.Write(data)
if err != nil {
fmt.Printf("writing file %s: %v", filename, err)
}
}

if currentChecksum == "" && newChecksum != "" {
Expand Down
6 changes: 6 additions & 0 deletions internal/core/dryrun/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dryrun

var (
// Enabled is a global variable to enable or disable dry-run mode
Enabled bool
)

0 comments on commit 9cb6ef8

Please sign in to comment.