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

Added a path to output a list of releases formatted as JSON #18

Merged
merged 4 commits into from
Oct 28, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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