Skip to content

Commit ec9ec96

Browse files
authored
Merge pull request #268 from per1234/production-check-type
Add library type check to registry data file validator
2 parents 85753d6 + fd85f87 commit ec9ec96

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

.github/workflows/assets/validate-registry/main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,29 @@ func main() {
4343
os.Exit(1)
4444
}
4545

46+
validTypes := map[string]bool{
47+
"Arduino": true,
48+
"Contributed": true,
49+
"Partner": true,
50+
"Recommended": true,
51+
"Retired": true,
52+
}
53+
4654
nameMap := make(map[string]bool)
4755
for _, entry := range rawRepos {
56+
// Check entry types
57+
if len(entry.Types) == 0 {
58+
fmt.Fprintf(os.Stderr, "error: Type not specified for library \"%s\"\n", entry.LibraryName)
59+
os.Exit(1)
60+
}
61+
for _, entryType := range entry.Types {
62+
if _, valid := validTypes[entryType]; !valid {
63+
fmt.Fprintf(os.Stderr, "error: Invalid type \"%s\" used by library \"%s\"\n", entryType, entry.LibraryName)
64+
os.Exit(1)
65+
}
66+
}
67+
68+
// Check library name of the entry
4869
if _, found := nameMap[entry.LibraryName]; found {
4970
fmt.Fprintf(os.Stderr, "error: Registry data file contains duplicates of name %s\n", entry.LibraryName)
5071
os.Exit(1)

.github/workflows/assets/validate-registry/tests/test_all.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
("nonexistent.txt", False),
3131
("invalid-data-format.txt", False),
3232
("invalid-url-format.txt", False),
33+
("no-type.txt", False),
34+
("invalid-type.txt", False),
3335
("duplicate-url.txt", False),
3436
("duplicate-name.txt", False),
3537
("valid.txt", True),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler
2+
https://github.com/arduino-libraries/SD.git|foo|SD
3+
https://github.com/arduino-libraries/Servo.git|Recommended|Servo
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler
2+
https://github.com/arduino-libraries/SD.git||SD
3+
https://github.com/arduino-libraries/Servo.git|Recommended|Servo

0 commit comments

Comments
 (0)