Skip to content

Commit

Permalink
Merge pull request #30 from mackerelio/m-g-r-selective-assets
Browse files Browse the repository at this point in the history
Support collect assets under specified directories
  • Loading branch information
yseto authored Jan 13, 2021
2 parents b981526 + 72bf62e commit 6a3d8ff
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions cmd/mackerel-github-release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func run(argv []string) int {
return exitError
}
log.Printf("Start uploading files to GitHub Releases. version: %s, staging: %t, dry-run: %t\n", v.Version, *staging, *dryRun)
err = uploadToGithubRelease(proj, v.Version, *staging, *dryRun)
err = uploadToGithubRelease(proj, v.Version, *staging, *dryRun, fs.Args())
if err != nil {
log.Printf("error occured while uploading artifacts to github: %+v\n", err)
return exitError
Expand All @@ -79,7 +79,7 @@ func run(argv []string) int {

var errAlreadyReleased = fmt.Errorf("the release of this version has already existed at GitHub Releases, so skip the process")

func uploadToGithubRelease(proj *github.Project, releaseVer string, staging, dryRun bool) error {
func uploadToGithubRelease(proj *github.Project, releaseVer string, staging, dryRun bool, directories []string) error {
tag := "staging"
if !staging {
tag = "v" + releaseVer
Expand All @@ -102,7 +102,13 @@ func uploadToGithubRelease(proj *github.Project, releaseVer string, staging, dry
}

body := pr.Body
assets, err := collectAssets()

var assets []string
if len(directories) > 0 {
assets, err = specifiedCollectAssets(directories)
} else {
assets, err = collectAssets()
}
if err != nil {
return fmt.Errorf("error occured while collecting releasing assets: %w", err)
}
Expand Down Expand Up @@ -243,6 +249,25 @@ func collectAssets() (assets []string, err error) {
return assets, nil
}

func specifiedCollectAssets(directories []string) (assets []string, err error) {
for _, dir := range directories {
errWalk := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
assets = append(assets, path)
return nil
})
if errWalk != nil {
return nil, errWalk
}
}
return assets, nil
}

func uploadAssets(gh *github.Client, release *github.Release, assets []string) error {
for _, asset := range assets {
err := retry.Retry(3, 3*time.Second, func() error {
Expand Down

0 comments on commit 6a3d8ff

Please sign in to comment.