Consolidate artifact declarations
This commit is contained in:
@@ -7,8 +7,8 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/artifact"
|
||||
internalbuild "gitea.maximumdirect.net/eric/ReleaseKit/internal/build"
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/gitea"
|
||||
)
|
||||
@@ -23,30 +23,26 @@ func declaredBuildAssets(result internalbuild.Result) ([]gitea.ExpectedAsset, er
|
||||
if len(result.Artifacts) != len(result.Targets) {
|
||||
return nil, fmt.Errorf("build result must contain one artifact for each selected target")
|
||||
}
|
||||
wantByTarget := make(map[string]string, len(result.Targets))
|
||||
for _, target := range result.Targets {
|
||||
if target.OS == "" || target.Arch == "" || strings.ContainsAny(target.OS+target.Arch, "/\\\r\n") {
|
||||
declarations := artifact.ExpectedBuild(result.BinaryName, result.Version, result.Targets)
|
||||
wantByTarget := make(map[artifact.Target]string, len(declarations))
|
||||
for _, declaration := range declarations {
|
||||
target := declaration.Target
|
||||
if !artifact.ValidComponent(target.OS) || !artifact.ValidComponent(target.Arch) {
|
||||
return nil, fmt.Errorf("build result contains an invalid target")
|
||||
}
|
||||
key := target.OS + "/" + target.Arch
|
||||
if _, exists := wantByTarget[key]; exists {
|
||||
return nil, fmt.Errorf("build result repeats target %q", key)
|
||||
if _, exists := wantByTarget[target]; exists {
|
||||
return nil, fmt.Errorf("build result repeats target %q", target.OS+"/"+target.Arch)
|
||||
}
|
||||
name := result.BinaryName + "-" + result.Version + "-" + target.OS + "-" + target.Arch
|
||||
if target.OS == "windows" {
|
||||
name += ".exe"
|
||||
}
|
||||
wantByTarget[key] = name
|
||||
wantByTarget[target] = declaration.Filename
|
||||
}
|
||||
assets := make([]gitea.ExpectedAsset, 0, len(result.Artifacts)+1)
|
||||
seenTargets := make(map[string]bool, len(result.Artifacts))
|
||||
seenTargets := make(map[artifact.Target]bool, len(result.Artifacts))
|
||||
for _, artifact := range result.Artifacts {
|
||||
key := artifact.Target.OS + "/" + artifact.Target.Arch
|
||||
wantName, ok := wantByTarget[key]
|
||||
if !ok || seenTargets[key] || artifact.Filename != wantName {
|
||||
wantName, ok := wantByTarget[artifact.Target]
|
||||
if !ok || seenTargets[artifact.Target] || artifact.Filename != wantName {
|
||||
return nil, fmt.Errorf("build artifact %q does not match a selected target and its declared name", artifact.Filename)
|
||||
}
|
||||
seenTargets[key] = true
|
||||
seenTargets[artifact.Target] = true
|
||||
if filepath.Base(artifact.Path) != artifact.Filename {
|
||||
return nil, fmt.Errorf("build artifact path %q does not end with filename %q", artifact.Path, artifact.Filename)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user