Skip to content

Commit

Permalink
Merge pull request #934 from aquaproj/fix/generate-registry-windows
Browse files Browse the repository at this point in the history
fix(generate-registry): don't exclude ".exe"
  • Loading branch information
suzuki-shunsuke committed Jun 26, 2022
2 parents d3e5ad1 + 80b46f5 commit 3cc9925
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions pkg/controller/generate-registry/generate.go
Expand Up @@ -64,12 +64,21 @@ func (ctrl *Controller) genRegistry(ctx context.Context, param *config.Param, lo
return nil
}

func (ctrl *Controller) excludeAsset(assetName string) bool {
func (ctrl *Controller) excludeAsset(pkgName, assetName string) bool {
format := ctrl.getFormat(assetName)
allowedExts := map[string]struct{}{
".exe": {},
".sh": {},
".js": {},
".jar": {},
".py": {},
}
if format == formatRaw {
ext := filepath.Ext(assetName)
if len(ext) < 6 { //nolint:gomnd
return true
if len(ext) > 0 && len(ext) < 6 {
if _, ok := allowedExts[ext]; !ok {
return true
}
}
}
suffixes := []string{
Expand All @@ -82,12 +91,12 @@ func (ctrl *Controller) excludeAsset(assetName string) bool {
}
}
words := []string{
"readme", "license", "openbsd", "freebsd", "netbsd", "android", "386", "i386", "armv6", "armv7", "32bit",
"changelog", "readme", "license", "openbsd", "freebsd", "netbsd", "android", "386", "i386", "armv6", "armv7", "32bit",
"netbsd", "plan9", "solaris", "mips", "mips64", "mips64le", "mipsle", "ppc64", "ppc64le", "riscv64", "s390x", "wasm",
"checksum",
}
for _, s := range words {
if strings.Contains(asset, s) {
if strings.Contains(asset, s) && !strings.Contains(pkgName, s) {
return true
}
}
Expand Down Expand Up @@ -118,12 +127,15 @@ func (ctrl *Controller) getPackageInfo(ctx context.Context, logE *logrus.Entry,
"repo_name": pkgInfo.RepoName,
}).WithError(err).Warn("get the latest release")
} else {
logE.WithField("version", len(release.GetTagName())).Debug("got the latest release")
assets := ctrl.listReleaseAssets(ctx, logE, pkgInfo, release.GetID())
if len(assets) != 0 {
logE.WithField("num_of_assets", len(assets)).Debug("got assets")
assetInfos := make([]*AssetInfo, 0, len(assets))
for _, asset := range assets {
assetName := asset.GetName()
if ctrl.excludeAsset(assetName) {
if ctrl.excludeAsset(pkgName, assetName) {
logE.WithField("asset_name", assetName).Debug("exclude an asset")
continue
}
assetInfo := ctrl.parseAssetName(asset.GetName(), release.GetTagName())
Expand Down

0 comments on commit 3cc9925

Please sign in to comment.