Skip to content

Commit

Permalink
fix: handle empty OS family (#2768)
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Aug 29, 2022
1 parent 77616be commit db67f16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Expand Up @@ -10,7 +10,7 @@ jobs:
uses: ./.github/workflows/reusable-release.yaml
with:
goreleaser_config: goreleaser.yml
goreleaser_options: '--rm-dist --timeout 60m'
goreleaser_options: '--rm-dist --timeout 90m'
secrets: inherit

deploy-packages:
Expand Down Expand Up @@ -54,4 +54,4 @@ jobs:
run: echo -e "${{ secrets.GPG_KEY }}" | gpg --import

- name: Create deb repository
run: ci/deploy-deb.sh
run: ci/deploy-deb.sh
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Expand Up @@ -113,7 +113,7 @@ jobs:
uses: goreleaser/goreleaser-action@v3
with:
version: v1.4.1
args: release --snapshot --rm-dist --skip-publish --timeout 60m
args: release --snapshot --rm-dist --skip-publish --timeout 90m

build-documents:
name: Documentation Test
Expand Down
13 changes: 8 additions & 5 deletions pkg/scanner/local/scan.go
Expand Up @@ -80,6 +80,11 @@ func (s Scanner) Scan(ctx context.Context, target, artifactKey string, blobKeys
case errors.Is(err, analyzer.ErrUnknownOS):
log.Logger.Debug("OS is not detected.")

// Packages may contain OS-independent binary information even though OS is not detected.
if len(artifactDetail.Packages) != 0 {
artifactDetail.OS = &ftypes.OS{Family: "none"}
}

// If OS is not detected and repositories are detected, we'll try to use repositories as OS.
if artifactDetail.Repository != nil {
log.Logger.Debugf("Package repository: %s %s", artifactDetail.Repository.Family, artifactDetail.Repository.Release)
Expand Down Expand Up @@ -167,12 +172,10 @@ func (s Scanner) Scan(ctx context.Context, target, artifactKey string, blobKeys
}

func (s Scanner) osPkgsToResult(target string, detail ftypes.ArtifactDetail, options types.ScanOptions) *types.Result {
if len(detail.Packages) == 0 {
if len(detail.Packages) == 0 || detail.OS == nil {
return nil
}
if detail.OS != nil {
target = fmt.Sprintf("%s (%s %s)", target, detail.OS.Family, detail.OS.Name)
}

pkgs := detail.Packages
if options.ScanRemovedPackages {
pkgs = mergePkgs(pkgs, detail.HistoryPackages)
Expand All @@ -181,7 +184,7 @@ func (s Scanner) osPkgsToResult(target string, detail ftypes.ArtifactDetail, opt
return strings.Compare(pkgs[i].Name, pkgs[j].Name) <= 0
})
return &types.Result{
Target: target,
Target: fmt.Sprintf("%s (%s %s)", target, detail.OS.Family, detail.OS.Name),
Class: types.ClassOSPkg,
Type: detail.OS.Family,
Packages: pkgs,
Expand Down

0 comments on commit db67f16

Please sign in to comment.