Skip to content

Commit b56ebc3

Browse files
authored
Merge pull request #242 from chainguard-dev/arturo-846-package-type-check
package-type-check: introduce check for -dev packages
2 parents f229118 + a01e810 commit b56ebc3

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

package-type-check/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func main() {
2727
rootCmd.AddCommand(CheckVirtualCommand())
2828
rootCmd.AddCommand(CheckStaticCommand())
2929
rootCmd.AddCommand(CheckByProductCommand())
30+
rootCmd.AddCommand(CheckDevCommand())
3031

3132
if err := rootCmd.Execute(); err != nil {
3233
fmt.Println(err)
@@ -104,3 +105,14 @@ func CheckByProductCommand() *cobra.Command {
104105
},
105106
}
106107
}
108+
109+
func CheckDevCommand() *cobra.Command {
110+
return &cobra.Command{
111+
Use: "dev <PACKAGE>",
112+
Short: "Check and verify the package is a dev package",
113+
Args: cobra.ExactArgs(1),
114+
RunE: func(cmd *cobra.Command, args []string) error {
115+
return checkers.CheckDevPackage(args[0])
116+
},
117+
}
118+
}
3.63 MB
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package checkers
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/chainguard-dev/cg-tw/package-type-check/pkg/utils"
7+
)
8+
9+
func CheckDevPackage(pkg string) error {
10+
fmt.Printf("Checking if package %s is a valid dev package\n", pkg)
11+
12+
// Check 1: Package name must end with -dev or -devel
13+
if !utils.IsDevPackage(pkg) {
14+
return fmt.Errorf("FAIL [1/3]: Dev package [%s] name does not end with -dev or -devel", pkg)
15+
}
16+
fmt.Printf("PASS [1/3]: Dev package [%s] has correct naming convention\n", pkg)
17+
18+
// Check 2: Package should not be empty
19+
isEmpty, err := utils.IsEmptyPackage(pkg)
20+
if err != nil {
21+
return err
22+
}
23+
if isEmpty {
24+
return fmt.Errorf("FAIL [2/3]: Dev package [%s] is completely empty (installs no files)", pkg)
25+
}
26+
fmt.Printf("PASS [2/3]: Dev package [%s] is not empty\n", pkg)
27+
28+
// Check 3: Package should contain .h files under /usr
29+
hasHeaders, err := utils.HasHeaderFiles(pkg)
30+
if err != nil {
31+
return err
32+
}
33+
if !hasHeaders {
34+
return fmt.Errorf("FAIL [3/3]: Dev package [%s] does not contain any .h files under /usr", pkg)
35+
}
36+
fmt.Printf("PASS [3/3]: Dev package [%s] contains header files under /usr\n", pkg)
37+
38+
return nil
39+
}

package-type-check/pkg/utils/package_utils.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,23 @@ func TestReadableFile(path string) bool {
184184
cmd.Stderr = nil
185185
return cmd.Run() == nil
186186
}
187+
188+
// IsDevPackage checks if package name ends with -dev or -devel
189+
func IsDevPackage(pkg string) bool {
190+
return strings.HasSuffix(pkg, "-dev") || strings.HasSuffix(pkg, "-devel")
191+
}
192+
193+
// HasHeaderFiles checks if package contains .h files under /usr
194+
func HasHeaderFiles(pkg string) (bool, error) {
195+
files, err := GetPackageFiles(pkg)
196+
if err != nil {
197+
return false, err
198+
}
199+
200+
for _, file := range files {
201+
if strings.HasPrefix(file, "usr/") && strings.HasSuffix(file, ".h") {
202+
return true, nil
203+
}
204+
}
205+
return false, nil
206+
}

pipelines/test/tw/devpackage.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Dev Package Check
2+
3+
needs:
4+
packages:
5+
- package-type-check
6+
7+
pipeline:
8+
- name: Check if the package is a Dev Package
9+
runs: |
10+
package-type-check dev "${{context.name}}"

0 commit comments

Comments
 (0)