From d910c2317fc095c92e04976859366f1a5f794d48 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 27 Dec 2023 21:00:12 +0100 Subject: [PATCH] Allow maximum artifact count to be customized Falls back to 8 artifacts per job if the config key max-artifacts isn't set --- worker/tasks.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/worker/tasks.go b/worker/tasks.go index 354e571..31c3e2f 100644 --- a/worker/tasks.go +++ b/worker/tasks.go @@ -624,14 +624,27 @@ func (ctx *JobContext) UploadArtifacts() error { if len(ctx.Manifest.Artifacts) == 0 { return nil } - if len(ctx.Manifest.Artifacts) > 8 { + var ( + ok bool + err error + artifactCount string + maxArtifacts int + ) + + if artifactCount, ok = config.Get("builds.sr.ht::worker", "max-artifacts"); !ok { + // default to old hardcoded value if the key wasn't found in the config file + artifactCount = "8" + } + if maxArtifacts, err = strconv.Atoi(artifactCount); err != nil { + return errors.New("The maximum build-artifact count could not be read") + } + if len(ctx.Manifest.Artifacts) > maxArtifacts { ctx.Log.Println("Error: no more than 8 artifacts " + "per build are accepted.") return nil } var ( - ok bool upstream string accessKey string secretKey string @@ -639,7 +652,7 @@ func (ctx *JobContext) UploadArtifacts() error { prefix string location string ) - err := errors.New("Build artifacts were requested, but S3 " + + err = errors.New("Build artifacts were requested, but S3 " + "is not configured for this build runner.") if upstream, ok = config.Get("objects", "s3-upstream"); !ok || upstream == "" { return err -- 2.38.5