Add possibility to add custom string to filename
This commit is contained in:
parent
1c6656df35
commit
4d04a5e239
@ -19,6 +19,9 @@ inputs:
|
||||
insecure:
|
||||
description: 'Whether allow insecure Gitea instance'
|
||||
required: false
|
||||
file_key:
|
||||
description: 'An extra key that gets inserted into your filename (before the extension)'
|
||||
required: false
|
||||
outputs:
|
||||
status:
|
||||
description: 'The upload status'
|
||||
|
12
main.go
12
main.go
@ -29,7 +29,7 @@ func main() {
|
||||
preRelease, _ := strconv.ParseBool(gha.GetInput("pre_release"))
|
||||
draft, _ := strconv.ParseBool(gha.GetInput("draft"))
|
||||
if title == "" {
|
||||
title = ctx.RefName
|
||||
title = strings.Replace(ctx.RefName, "refs/tags/", "", 1)
|
||||
}
|
||||
if apiKey == "" {
|
||||
apiKey = os.Getenv("GITHUB_TOKEN")
|
||||
@ -148,6 +148,14 @@ func createOrGetRelease(ctx *gha.GitHubContext, c *gitea.Client, owner, repo str
|
||||
return release, nil
|
||||
}
|
||||
|
||||
func getFilename(ctx *gha.GitHubContext, path string) string {
|
||||
fileKey := gha.GetInput("file_key")
|
||||
fileName := filepath.Base(path)
|
||||
ext := filepath.Ext(fileName)
|
||||
filePath := strings.TrimSuffix(fileName, ext)
|
||||
return filePath + fileKey + ext
|
||||
}
|
||||
|
||||
func uploadFiles(ctx *gha.GitHubContext, c *gitea.Client, owner, repo string, releaseID int64, files []string) error {
|
||||
attachments, _, err := c.ListReleaseAttachments(owner, repo, releaseID, gitea.ListReleaseAttachmentsOptions{})
|
||||
if err != nil {
|
||||
@ -171,7 +179,7 @@ func uploadFiles(ctx *gha.GitHubContext, c *gitea.Client, owner, repo string, re
|
||||
}
|
||||
}
|
||||
|
||||
if _, _, err = c.CreateReleaseAttachment(owner, repo, releaseID, f, filepath.Base(file)); err != nil {
|
||||
if _, _, err = c.CreateReleaseAttachment(owner, repo, releaseID, f, getFilename(ctx, file)); err != nil {
|
||||
f.Close()
|
||||
return fmt.Errorf("failed to upload release attachment %s: %w", file, err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user