-
-
Notifications
You must be signed in to change notification settings - Fork 4
Some cleanups to the codebase #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
faa0572
Removed unused libraries package.
cmaglie 936a6e6
Cleaned up linter warnings
cmaglie dbbced5
Simplified os-env management
cmaglie 87ff500
Other linter warnings fixed
cmaglie 2d95155
Updated testdata
cmaglie 14e1576
Added new command check-registry
cmaglie 53a8751
Added unit tests from library-registry repo
cmaglie 1b2372d
Fixed unit-test
cmaglie 9258f47
Trimmed error string
cmaglie a613262
Moved check-registry implementation in the right directory
cmaglie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// This file is part of libraries-repository-engine. | ||
// | ||
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/) | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published | ||
// by the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
// You can be released from the requirements of the above licenses by purchasing | ||
// a commercial license. Buying such a license is mandatory if you want to | ||
// modify or otherwise use the software for commercial activities involving the | ||
// Arduino software without disclosing the source code of your own applications. | ||
// To purchase a commercial license, send an email to license@arduino.cc. | ||
|
||
package checkregistry | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"reflect" | ||
|
||
"github.com/arduino/libraries-repository-engine/internal/libraries" | ||
) | ||
|
||
// CheckRegistry runs the check-registry action | ||
func CheckRegistry(reposFile string) { | ||
if err := runcheck(reposFile); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error()) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func runcheck(reposFile string) error { | ||
info, err := os.Stat(reposFile) | ||
if err != nil { | ||
return fmt.Errorf("while loading registry data file: %w", err) | ||
} | ||
|
||
if info.IsDir() { | ||
return fmt.Errorf("registry data file argument %s is a folder, not a file", reposFile) | ||
} | ||
|
||
rawRepos, err := libraries.LoadRepoListFromFile(reposFile) | ||
if err != nil { | ||
return fmt.Errorf("while loading registry data file: %w", err) | ||
} | ||
|
||
filteredRepos, err := libraries.ListRepos(reposFile) | ||
if err != nil { | ||
return fmt.Errorf("while filtering registry data file: %w", err) | ||
} | ||
|
||
if !reflect.DeepEqual(rawRepos, filteredRepos) { | ||
return errors.New("registry data file contains duplicate URLs") | ||
} | ||
|
||
validTypes := map[string]bool{ | ||
"Arduino": true, | ||
"Contributed": true, | ||
"Partner": true, | ||
"Recommended": true, | ||
"Retired": true, | ||
} | ||
|
||
nameMap := make(map[string]bool) | ||
for _, entry := range rawRepos { | ||
// Check entry types | ||
if len(entry.Types) == 0 { | ||
return fmt.Errorf("type not specified for library '%s'", entry.LibraryName) | ||
} | ||
for _, entryType := range entry.Types { | ||
if _, valid := validTypes[entryType]; !valid { | ||
return fmt.Errorf("invalid type '%s' used by library '%s'", entryType, entry.LibraryName) | ||
} | ||
} | ||
|
||
// Check library name of the entry | ||
if _, found := nameMap[entry.LibraryName]; found { | ||
return fmt.Errorf("registry data file contains duplicates of name '%s'", entry.LibraryName) | ||
} | ||
nameMap[entry.LibraryName] = true | ||
} | ||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// This file is part of libraries-repository-engine. | ||
// | ||
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/) | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published | ||
// by the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
// You can be released from the requirements of the above licenses by purchasing | ||
// a commercial license. Buying such a license is mandatory if you want to | ||
// modify or otherwise use the software for commercial activities involving the | ||
// Arduino software without disclosing the source code of your own applications. | ||
// To purchase a commercial license, send an email to license@arduino.cc. | ||
|
||
package checkregistry | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRegistryValidation(t *testing.T) { | ||
type testcase struct { | ||
Name string | ||
TestFile string | ||
ExpectedResult string | ||
} | ||
tests := []testcase{ | ||
{"EmptyArg", "", "registry data file argument testdata is a folder, not a file"}, | ||
{"NonExistentFile", "nonexistent.txt", "while loading registry data file: stat testdata/nonexistent.txt: no such file or directory"}, | ||
{"InvalidDataFormat", "invalid-data-format.txt", "while loading registry data file: invalid line format (3 fields are required): https://github.com/arduino-libraries/SD.git|Partner;SD"}, | ||
{"InvalidUrlFormat", "invalid-url-format.txt", "while filtering registry data file: Following URL are unknown or unsupported git repos:\nhttps://github.com/arduino-libraries/SD"}, | ||
{"MissingType", "no-type.txt", "invalid type '' used by library 'SD'"}, | ||
{"InvalidType", "invalid-type.txt", "invalid type 'foo' used by library 'SD'"}, | ||
{"DuplicateRepoURL", "duplicate-url.txt", "registry data file contains duplicate URLs"}, | ||
{"DuplicateLibName", "duplicate-name.txt", "registry data file contains duplicates of name 'SD'"}, | ||
{"ValidList", "valid.txt", ""}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.Name, func(t *testing.T) { | ||
err := runcheck(filepath.Join("testdata", test.TestFile)) | ||
if test.ExpectedResult == "" { | ||
require.NoError(t, err) | ||
} else { | ||
require.EqualError(t, err, test.ExpectedResult) | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler | ||
https://github.com/arduino-libraries/SD.git|Partner|SD | ||
https://github.com/arduino-libraries/Servo.git|Recommended|Servo | ||
https://github.com/arduino-libraries/Foo.git|Contributed|SD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler | ||
https://github.com/arduino-libraries/SD.git|Partner|SD | ||
https://github.com/arduino-libraries/Servo.git|Recommended|Servo | ||
https://github.com/arduino-libraries/SD.git|Contributed|Foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler | ||
https://github.com/arduino-libraries/SD.git|Partner;SD | ||
https://github.com/arduino-libraries/Servo.git|Recommended|Servo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler | ||
https://github.com/arduino-libraries/SD.git|foo|SD | ||
https://github.com/arduino-libraries/Servo.git|Recommended|Servo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler | ||
https://github.com/arduino-libraries/SD|Partner|SD | ||
https://github.com/arduino-libraries/Servo.git|Recommended|Servo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler | ||
https://github.com/arduino-libraries/SD.git||SD | ||
https://github.com/arduino-libraries/Servo.git|Recommended|Servo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
https://github.com/arduino-libraries/Scheduler.git|Arduino|Scheduler | ||
https://github.com/arduino-libraries/SD.git|Partner|SD | ||
https://github.com/arduino-libraries/Servo.git|Recommended|Servo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.