Skip to content

Commit 5e7442f

Browse files
committed
package-type-check: add empty package check
Add new check to check if a package is empty. We have similar pipelines copied into the melange repos. Signed-off-by: Arturo Borrero Gonzalez <[email protected]>
1 parent a608a1e commit 5e7442f

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

package-type-check/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func main() {
1313
var rootCmd = &cobra.Command{
1414
Use: "package-type-check",
1515
Short: "A tool to check and verify the type of package in Wolfi",
16-
Long: `This tool is used in wolfi melange test configuration to verify the kind of packages: : docs, meta, static, virtual, and by-product packages.`,
16+
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.`,
1717
Run: func(cmd *cobra.Command, args []string) {
1818
// Default help message if no command is provided
1919
cmd.Help()
@@ -22,14 +22,14 @@ func main() {
2222
}
2323

2424
// Add all subcommands
25-
// TODO: Add other commands for static, byproduct
2625
rootCmd.AddCommand(CheckDocsCommand())
2726
rootCmd.AddCommand(CheckMetaCommand())
2827
rootCmd.AddCommand(CheckVirtualCommand())
2928
rootCmd.AddCommand(CheckStaticCommand())
3029
rootCmd.AddCommand(CheckByProductCommand())
3130
rootCmd.AddCommand(CheckDevCommand())
3231
rootCmd.AddCommand(CheckDebugCommand())
32+
rootCmd.AddCommand(CheckEmptyCommand())
3333

3434
if err := rootCmd.Execute(); err != nil {
3535
fmt.Println(err)
@@ -129,3 +129,14 @@ func CheckDebugCommand() *cobra.Command {
129129
},
130130
}
131131
}
132+
133+
func CheckEmptyCommand() *cobra.Command {
134+
return &cobra.Command{
135+
Use: "empty <PACKAGE>",
136+
Short: "Check and verify the package is an empty package",
137+
Args: cobra.ExactArgs(1),
138+
RunE: func(cmd *cobra.Command, args []string) error {
139+
return checkers.CheckEmptyPackage(args[0])
140+
},
141+
}
142+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package checkers
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/chainguard-dev/cg-tw/package-type-check/pkg/utils"
8+
)
9+
10+
func CheckEmptyPackage(pkg string) error {
11+
fmt.Printf("Checking if package %s is an empty package\n", pkg)
12+
13+
empty, err := utils.IsEmptyPackage(pkg)
14+
if err != nil {
15+
return err
16+
}
17+
18+
if !empty {
19+
files, err := utils.GetPackageFiles(pkg)
20+
if err != nil {
21+
return err
22+
}
23+
fileList := strings.Join(files, "\n ")
24+
return fmt.Errorf("FAIL: Package [%s] is not empty: %s", pkg, fileList)
25+
}
26+
27+
fmt.Printf("PASS: Package [%s] is empty", pkg)
28+
29+
return nil
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Empty Package Check
2+
3+
needs:
4+
packages:
5+
- package-type-check
6+
7+
pipeline:
8+
- name: Check if the package is an Empty Package
9+
runs: |
10+
package-type-check empty "${{context.name}}"

0 commit comments

Comments
 (0)