package projectversion import ( "bytes" "errors" "fmt" "os" "path/filepath" ) var releaseAssetChecks = []releaseAssetCheck{ { path: "assets/icon.ico", description: "Windows ICO 图标", magic: []byte{0x00, 0x00, 0x01, 0x00}, }, { path: "assets/icon.icns", description: "macOS ICNS 图标", magic: []byte("icns"), }, { path: "assets/icon.png", description: "PNG 图标", magic: []byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}, }, { path: "frontend/public/icon.png", description: "前端 PNG 图标", magic: []byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}, }, } var gitLFSPointerPrefix = []byte("version https://git-lfs.github.com/spec/v1") type releaseAssetCheck struct { path string description string magic []byte } func CheckReleaseAssets(root string) error { var errs []error for _, check := range releaseAssetChecks { if err := checkReleaseAsset(root, check); err != nil { errs = append(errs, err) } } return errors.Join(errs...) } func checkReleaseAsset(root string, check releaseAssetCheck) error { content, err := os.ReadFile(filepath.Join(root, check.path)) if err != nil { return fmt.Errorf("%s 不可读取: %w", check.path, err) } if bytes.HasPrefix(content, gitLFSPointerPrefix) { return fmt.Errorf("%s 是 Git LFS pointer,请先拉取 Git LFS 真实内容", check.path) } if !bytes.HasPrefix(content, check.magic) { return fmt.Errorf("%s 不是有效的%s", check.path, check.description) } return nil }