Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions package-type-check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
var rootCmd = &cobra.Command{
Use: "package-type-check",
Short: "A tool to check and verify the type of package in Wolfi",
Long: `This tool is used in wolfi melange test configuration to verify the kind of packages: : docs, meta, static, virtual, and by-product packages.`,
Long: `This tool is used in wolfi melange test configuration to verify the kind of packages: : docs, meta, static, virtual, empty, and by-product packages.`,
Run: func(cmd *cobra.Command, args []string) {
// Default help message if no command is provided
cmd.Help()
Expand All @@ -22,14 +22,14 @@ func main() {
}

// Add all subcommands
// TODO: Add other commands for static, byproduct
rootCmd.AddCommand(CheckDocsCommand())
rootCmd.AddCommand(CheckMetaCommand())
rootCmd.AddCommand(CheckVirtualCommand())
rootCmd.AddCommand(CheckStaticCommand())
rootCmd.AddCommand(CheckByProductCommand())
rootCmd.AddCommand(CheckDevCommand())
rootCmd.AddCommand(CheckDebugCommand())
rootCmd.AddCommand(CheckEmptyCommand())

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -129,3 +129,14 @@ func CheckDebugCommand() *cobra.Command {
},
}
}

func CheckEmptyCommand() *cobra.Command {
return &cobra.Command{
Use: "empty <PACKAGE>",
Short: "Check and verify the package is an empty package",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return checkers.CheckEmptyPackage(args[0])
},
}
}
30 changes: 30 additions & 0 deletions package-type-check/pkg/checkers/empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package checkers

import (
"fmt"
"strings"

"github.com/chainguard-dev/cg-tw/package-type-check/pkg/utils"
)

func CheckEmptyPackage(pkg string) error {
fmt.Printf("Checking if package %s is an empty package\n", pkg)

empty, err := utils.IsEmptyPackage(pkg)
if err != nil {
return err
}

if !empty {
files, err := utils.GetPackageFiles(pkg)
if err != nil {
return err
}
fileList := strings.Join(files, "\n ")
return fmt.Errorf("FAIL: Package [%s] is not empty: %s", pkg, fileList)
}

fmt.Printf("PASS: Package [%s] is empty", pkg)

return nil
}
10 changes: 10 additions & 0 deletions pipelines/test/tw/emptypackage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Empty Package Check

needs:
packages:
- package-type-check

pipeline:
- name: Check if the package is an Empty Package
runs: |
package-type-check empty "${{context.name}}"