Skip to content

Commit 2c52d7c

Browse files
author
Eike vom Bauer
committed
add asset upload
1 parent 9f2401c commit 2c52d7c

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

gitcontroller/github.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import (
1313
)
1414

1515
type GitConfiguration struct {
16-
ApiUrl string
17-
Repository string
18-
AccessToken string
16+
ApiUrl string
17+
Repository string
18+
AccessToken string
19+
DefaultBranchName string
1920
}
2021

2122
type NewRelease struct {
@@ -105,7 +106,7 @@ func github_createNextGitHubRelease(conf GitConfiguration, newReleaseVersion str
105106

106107
requestBody, err := json.Marshal(NewRelease{
107108
TagName: newReleaseVersion,
108-
TargetCommitish: "master",
109+
TargetCommitish: conf.DefaultBranchName,
109110
Name: "Release " + newReleaseVersion,
110111
Body: "",
111112
Draft: false,
@@ -125,21 +126,23 @@ func github_createNextGitHubRelease(conf GitConfiguration, newReleaseVersion str
125126
}
126127

127128
if uploadArtifacts != "" {
128-
fmt.Printf("Uploading artifacts from: %s\n", uploadArtifacts)
129+
log.Printf("Uploading artifacts from: %s\n", uploadArtifacts)
129130

130131
file, err := ioutil.ReadFile(uploadArtifacts)
131132
if err != nil {
132133
log.Fatal(err)
133134
}
134135

135-
fmt.Println("Can read file")
136-
fmt.Println(result["id"])
137136
releaseFileName := uploadArtifacts[strings.LastIndex(uploadArtifacts, "/")+1:]
138137

139-
url := fmt.Sprintf("https://uploads.github.com/repos/%s/releases/%v/assets?name=%s", conf.Repository, result["id"], releaseFileName)
140-
fmt.Println(url)
141-
resultTwo := newPostRequest(url, conf.AccessToken, true, file)
138+
uploadUrl := fmt.Sprintf("%s", result["upload_url"])
139+
newUploadUrl := strings.Replace(uploadUrl, "{?name,label}", "?name="+releaseFileName, -1)
140+
resultTwo := newPostRequest(newUploadUrl, conf.AccessToken, true, file)
142141

143-
fmt.Println(resultTwo)
142+
if resultTwo["name"] == releaseFileName {
143+
fmt.Println(releaseFileName + " sucsessfully uploaded")
144+
} else {
145+
fmt.Println("Somethin went worng at uploading release!")
146+
}
144147
}
145148
}

gitcontroller/initsenv.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ func determanEnvironment(environment string) GitConfiguration {
2121
switch environment {
2222
case "Github":
2323
return GitConfiguration{
24-
ApiUrl: os.Getenv("GITHUB_API_URL"),
25-
Repository: os.Getenv("GITHUB_REPOSITORY"),
26-
AccessToken: os.Getenv("GITHUB_TOKEN"),
24+
ApiUrl: os.Getenv("GITHUB_API_URL"),
25+
Repository: os.Getenv("GITHUB_REPOSITORY"),
26+
AccessToken: os.Getenv("GITHUB_TOKEN"),
27+
DefaultBranchName: getEnv("GIT_DEFAULT_BRANCH_NAME", "main", false),
2728
}
2829

2930
case "Custom":

0 commit comments

Comments
 (0)