fix(ops/besadii): Replace slashes in branch names

Submitting a build with a branch containing a slash (which is common
for my branches) returns this error:

    Invalid tag name, tags must use lowercase alphanumeric characters,
    underscores, dashes, or dots

This commit replaces all slashes with underscores to work around that.
This commit is contained in:
Vincent Ambo 2020-02-21 23:01:42 +00:00
parent 21b76cb023
commit c689df0dc7

View file

@ -96,7 +96,9 @@ func triggerBuild(log *syslog.Writer, token, branch, commit string) {
Manifest: prepareManifest(commit),
Note: fmt.Sprintf("Build of 'master' at '%s'", commit),
Tags: []string{
"depot", branch,
// my branch names tend to contain slashes, which are not valid
// identifiers in sourcehut.
"depot", strings.ReplaceAll(branch, "/", "_"),
},
}
@ -122,8 +124,8 @@ func triggerBuild(log *syslog.Writer, token, branch, commit string) {
defer resp.Body.Close()
if resp.StatusCode != 200 {
respBody, err := ioutil.ReadAll(resp.Body)
log.Err(fmt.Sprintf("received non-success response from builds.sr.ht: %s (%v)[%s]", respBody, resp.Status, err))
respBody, _ := ioutil.ReadAll(resp.Body)
log.Err(fmt.Sprintf("received non-success response from builds.sr.ht: %s (%v)", respBody, resp.Status))
} else {
fmt.Fprintf(log, "triggered builds.sr.ht job for branch '%s' at commit '%s'", branch, commit)
}
@ -165,10 +167,10 @@ func main() {
// Before triggering builds, it is important that git
// update-server-info is run so that cgit correctly serves the
// repository.
err := exec.Command(gitBin, "update-server-info").Run()
err = exec.Command(gitBin, "update-server-info").Run()
if err != nil {
log.Alert("failed to run 'git update-server-info' for depot!")
os.Exit()
os.Exit(1)
}
token, err := ioutil.ReadFile("/etc/secrets/srht-token")