Merge pull request 'feat: add getRelease before createRelease to allow adding to existing release' (#2) from myrqs/release-action:add-attachments into main
Reviewed-on: https://gitea.com/actions/release-action/pulls/2 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
commit
489f83257d
23
main.go
23
main.go
|
@ -52,7 +52,7 @@ func main() {
|
||||||
owner := ctx.RepositoryOwner
|
owner := ctx.RepositoryOwner
|
||||||
repo := strings.Split(ctx.Repository, "/")[1]
|
repo := strings.Split(ctx.Repository, "/")[1]
|
||||||
|
|
||||||
rel, err := createRelease(ctx, c, owner, repo, gitea.CreateReleaseOption{
|
rel, err := createOrGetRelease(ctx, c, owner, repo, gitea.CreateReleaseOption{
|
||||||
TagName: ctx.RefName,
|
TagName: ctx.RefName,
|
||||||
IsDraft: draft,
|
IsDraft: draft,
|
||||||
IsPrerelease: preRelease,
|
IsPrerelease: preRelease,
|
||||||
|
@ -129,13 +129,22 @@ func getFiles(parentDir, files string) ([]string, error) {
|
||||||
return fileList, nil
|
return fileList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRelease(ctx *gha.GitHubContext, c *gitea.Client, owner, repo string, opts gitea.CreateReleaseOption) (*gitea.Release, error) {
|
func createOrGetRelease(ctx *gha.GitHubContext, c *gitea.Client, owner, repo string, opts gitea.CreateReleaseOption) (*gitea.Release, error) {
|
||||||
// Create the release
|
// Get the release by tag
|
||||||
release, _, err := c.CreateRelease(owner, repo, opts)
|
release, resp, err := c.GetReleaseByTag(owner, repo, opts.TagName)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return nil, fmt.Errorf("failed to create release: %w", err)
|
return release, nil
|
||||||
|
}
|
||||||
|
errMessage := fmt.Errorf("failed to get release for tag: %s with error: %w", opts.TagName, err)
|
||||||
|
if resp.StatusCode != 404 {
|
||||||
|
return nil, errMessage
|
||||||
|
}
|
||||||
|
fmt.Printf("%s trying to create it\n", errMessage)
|
||||||
|
// Create the release
|
||||||
|
release, _, err = c.CreateRelease(owner, repo, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create release: %w and %s", err, errMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
return release, nil
|
return release, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue