Skip to content

Commit

Permalink
Added a path to output a list of releases formatted as JSON (#18)
Browse files Browse the repository at this point in the history
* Added a path to output a list of releases formatted as JSON

* Update file permission

Co-authored-by: Le Van Nghia <[email protected]>

* Fix log message

Co-authored-by: Le Van Nghia <[email protected]>

* Fix log message

Co-authored-by: Le Van Nghia <[email protected]>

Co-authored-by: Le Van Nghia <[email protected]>
  • Loading branch information
na-ga and nghialv authored Oct 28, 2021
1 parent 257dd0c commit ea8674c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
|-----------------------|-----------------------------------------------------------------------------------|:--------:|:-------------:|
| token | The GITHUB_TOKEN secret. | yes | |
| release_file | The path to the RELEASE file or pattern to match one or multiple RELEASE files. | no | RELEASE |
| output_releases_file | The path to output the list of releases formatted in JSON. | no | |
## Outputs
Expand Down
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
token:
description: 'The GITHUB_TOKEN secret.'
required: true
output_releases_file_path:
description: 'The path to output the list of releases formatted in JSON.'
required: false

outputs:
releases:
Expand All @@ -24,3 +27,4 @@ runs:
args:
- release-file=${{ inputs.release_file }}
- token=${{ inputs.token }}
- output-releases-file-path=${{ inputs.output_releases_file_path }}
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ func main() {
log.Fatalf("Failed to marshal releases: %v\n", err)
}
fmt.Printf("::set-output name=releases::%s\n", string(releasesJSON))
if args.OutputReleasesFilePath != "" {
if err := os.WriteFile(args.OutputReleasesFilePath, releasesJSON, 0644); err != nil {
log.Fatalf("Failed to write releases JSON to %s: %v\n", args.OutputReleasesFilePath, err)
}
log.Printf("Successfully wrote releases JSON to %s\n", args.OutputReleasesFilePath)
}

// Create GitHub releases if the event was push.
if event.Name == eventPush {
Expand All @@ -166,8 +172,9 @@ func main() {
}

type arguments struct {
ReleaseFile string
Token string
ReleaseFile string
Token string
OutputReleasesFilePath string
}

func parseArgs(args []string) (arguments, error) {
Expand All @@ -183,6 +190,8 @@ func parseArgs(args []string) (arguments, error) {
out.ReleaseFile = ps[1]
case "token":
out.Token = ps[1]
case "output-releases-file-path":
out.OutputReleasesFilePath = ps[1]
}
}

Expand Down

0 comments on commit ea8674c

Please sign in to comment.