40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package releasekit
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"gitea.maximumdirect.net/eric/ReleaseKit/internal/gitea"
|
|
)
|
|
|
|
func declaredBuildAssets(result BuildResult) ([]gitea.ExpectedAsset, error) {
|
|
assets := make([]gitea.ExpectedAsset, 0, len(result.Artifacts)+1)
|
|
for _, artifact := range result.Artifacts {
|
|
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)
|
|
}
|
|
info, err := os.Stat(artifact.Path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("inspect build artifact %q: %w", artifact.Filename, err)
|
|
}
|
|
if !info.Mode().IsRegular() {
|
|
return nil, fmt.Errorf("build artifact %q is not a regular file", artifact.Filename)
|
|
}
|
|
assets = append(assets, gitea.ExpectedAsset{
|
|
Filename: artifact.Filename,
|
|
SHA256: artifact.SHA256,
|
|
Size: info.Size(),
|
|
Path: artifact.Path,
|
|
})
|
|
}
|
|
manifest, err := gitea.BuildManifest(assets)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("build checksum manifest: %w", err)
|
|
}
|
|
if manifest.Filename != "" {
|
|
assets = append(assets, manifest)
|
|
}
|
|
return assets, nil
|
|
}
|