File tree Expand file tree Collapse file tree 5 files changed +81
-0
lines changed Expand file tree Collapse file tree 5 files changed +81
-0
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 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}}"
You can’t perform that action at this time.
0 commit comments