Skip to content

Commit

Permalink
Template GitHub Url in goreleaser.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Sep 4, 2024
1 parent 185324f commit d846b1a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/ghworkflow/workflow_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@
package ghworkflow

import (
"bytes"
"net/url"
"os"
"strings"
"text/template"

"github.com/sapcc/go-bits/must"

"github.com/sapcc/go-makefile-maker/internal/core"
)

const enterpriseGoReleaserConfig string = `github_urls:
api: https://github.wdf.sap.corp/api/v3/
upload: https://github.wdf.sap.corp/api/uploads/
download: https://github.wdf.sap.corp/
api: https://{{ . }}/api/v3/
upload: https://{{ . }}/api/uploads/
download: https://{{ . }}/
`

func releaseWorkflow(cfg core.Configuration) {
Expand Down Expand Up @@ -71,10 +74,15 @@ func releaseWorkflow(cfg core.Configuration) {
w.Jobs = map[string]job{"release": j}

writeWorkflowToFile(w)
isInternal := strings.HasPrefix(cfg.Metadata.URL, "https://github.wdf.sap.corp")

isInternal := !strings.HasPrefix(cfg.Metadata.URL, "https://github.com")
if !isInternal {
return
}
err := os.WriteFile(".goreleaser.yaml", []byte(enterpriseGoReleaserConfig), 0644)
must.Succeed(err)
ghURL := must.Return(url.Parse(cfg.Metadata.URL))
tpl := template.New("")
must.Return(tpl.Parse(enterpriseGoReleaserConfig))
var buf bytes.Buffer
must.Succeed(tpl.Execute(&buf, ghURL.Host))
must.Succeed(os.WriteFile(".goreleaser.yaml", buf.Bytes(), 0644))
}

0 comments on commit d846b1a

Please sign in to comment.