Skip to content

Commit 4a3cbdb

Browse files
committed
Add option to write changelog to a file
Signed-off-by: timflannagan <[email protected]>
1 parent 4924bc0 commit 4a3cbdb

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

action.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ inputs:
1717
end-sha:
1818
description: "The ending commit SHA (inclusive)"
1919
required: true
20+
output-path:
21+
description: "The path to write the changelog to"
22+
required: false
23+
default: "CHANGELOG.md"
24+
outputs:
25+
changelog-path:
26+
description: "The path to the generated changelog file"
2027
runs:
2128
using: "docker"
2229
image: "Dockerfile"
@@ -26,3 +33,4 @@ runs:
2633
- ${{ inputs.repo }}
2734
- ${{ inputs.start-sha }}
2835
- ${{ inputs.end-sha }}
36+
- ${{ inputs.output-path }}

main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212

1313
func main() {
1414
cmd := &cobra.Command{
15-
Use: "changelog-generator <token> <owner> <repo> <start-sha> <end-sha>",
15+
Use: "changelog-generator <token> <owner> <repo> <start-sha> <end-sha> <output-path>",
1616
Short: "Generate a changelog between two commits",
17-
Args: cobra.ExactArgs(5),
17+
Args: cobra.ExactArgs(6),
1818
RunE: func(cmd *cobra.Command, args []string) error {
19-
token, owner, repo, startSHA, endSHA := args[0], args[1], args[2], args[3], args[4]
19+
token, owner, repo, startSHA, endSHA, outputPath := args[0], args[1], args[2], args[3], args[4], args[5]
2020

2121
ctx := context.Background()
2222
client := github.NewClient(nil).WithAuthToken(token)
@@ -26,8 +26,11 @@ func main() {
2626
if err != nil {
2727
return fmt.Errorf("failed to generate changelog: %v", err)
2828
}
29+
if err := os.WriteFile(outputPath, []byte(changelog), 0644); err != nil {
30+
return fmt.Errorf("failed to write changelog to %s: %v", outputPath, err)
31+
}
32+
fmt.Printf("::set-output name=changelog-path::%s\n", outputPath)
2933

30-
fmt.Println(changelog)
3134
return nil
3235
},
3336
}

0 commit comments

Comments
 (0)