1
0

fix: 修复发布流水线 LFS 资产校验

This commit is contained in:
2026-05-05 09:57:02 +08:00
parent 235efb0e62
commit 6181923d8d
6 changed files with 183 additions and 5 deletions

View File

@@ -0,0 +1,69 @@
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
}