Skip to content

Commit 9293acd

Browse files
committed
Output appropriate arduino-lint --library-manager setting
When a submission URL is modified, it must also be checked. In this case, the `arduino/arduino-lint-action`'s `library-manager` input setting must be "update" instead of "submit", since the library is already in the index. Since, manual testing of GitHub Actions workflows is not well supported, it's best to keep as much of the logic as possible in the Go code of the parser. For this reason, the parser should determine the appropriate `library-manager` setting and pass that to the workflow.
1 parent a236281 commit 9293acd

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

main.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ var recommendedOrganizations []string = []string{
6060

6161
// request is the type of the request data.
6262
type request struct {
63-
Type string `json:"type"` // Request type.
64-
Submissions []submissionType `json:"submissions"` // Data for submitted libraries.
65-
IndexEntry string `json:"indexEntry"` // Entry that will be made to the Library Manager index source file when the submission is accepted.
66-
IndexerLogsURLs string `json:"indexerLogsURLs"` // List of URLs where the logs from the Library Manager indexer for each submission are available for view.
63+
Type string `json:"type"` // Request type.
64+
ArduinoLintLibraryManagerSetting string `json:"arduinoLintLibraryManagerSetting"` // Argument to pass to Arduino Lint's --library-manager flag.
65+
Submissions []submissionType `json:"submissions"` // Data for submitted libraries.
66+
IndexEntry string `json:"indexEntry"` // Entry that will be made to the Library Manager index source file when the submission is accepted.
67+
IndexerLogsURLs string `json:"indexerLogsURLs"` // List of URLs where the logs from the Library Manager indexer for each submission are available for view.
6768
}
6869

6970
// submissionType is the type of the data for each individual library submitted in the request.
@@ -116,7 +117,7 @@ func main() {
116117
}
117118
var req request
118119
var submissionURLs []string
119-
req.Type, submissionURLs = parseDiff(rawDiff, *listNameArgument)
120+
req.Type, req.ArduinoLintLibraryManagerSetting, submissionURLs = parseDiff(rawDiff, *listNameArgument)
120121

121122
// Process the submissions.
122123
var indexEntries []string
@@ -155,8 +156,8 @@ func errorExit(message string) {
155156
os.Exit(1)
156157
}
157158

158-
// parseDiff parses the request diff and returns the request type and list of submission URLs.
159-
func parseDiff(rawDiff []byte, listName string) (string, []string) {
159+
// parseDiff parses the request diff and returns the request type, `arduino-lint --library-manager` setting, and list of submission URLs.
160+
func parseDiff(rawDiff []byte, listName string) (string, string, []string) {
160161
var submissionURLs []string
161162

162163
diffs, err := diff.ParseMultiFileDiff(rawDiff)
@@ -166,7 +167,7 @@ func parseDiff(rawDiff []byte, listName string) (string, []string) {
166167

167168
if (len(diffs) != 1) || (diffs[0].OrigName[2:] != listName) || (diffs[0].OrigName[2:] != diffs[0].NewName[2:]) { // Git diffs have a a/ or b/ prefix on file names.
168169
// This is not a Library Manager submission.
169-
return "other", nil
170+
return "other", "", nil
170171
}
171172

172173
var addedCount int
@@ -193,15 +194,19 @@ func parseDiff(rawDiff []byte, listName string) (string, []string) {
193194
}
194195

195196
var requestType string
197+
var arduinoLintLibraryManagerSetting string
196198
if addedCount > 0 && deletedCount == 0 {
197199
requestType = "submission"
200+
arduinoLintLibraryManagerSetting = "submit"
198201
} else if addedCount == 0 && deletedCount > 0 {
199202
requestType = "removal"
203+
arduinoLintLibraryManagerSetting = ""
200204
} else {
201205
requestType = "modification"
206+
arduinoLintLibraryManagerSetting = "update"
202207
}
203208

204-
return requestType, submissionURLs
209+
return requestType, arduinoLintLibraryManagerSetting, submissionURLs
205210
}
206211

207212
// populateSubmission does the checks on the submission that aren't provided by Arduino Lint and gathers the necessary data on it.

main_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ index cff484d..e14c179 100644
3737
+https://github.com/foo/bar
3838
`)
3939

40-
requestType, submissionURLs := parseDiff(diff, "repositories.txt")
40+
requestType, arduinoLintLibraryManagerSetting, submissionURLs := parseDiff(diff, "repositories.txt")
4141
assert.Equal(t, "other", requestType, testName)
42+
assert.Equal(t, "", arduinoLintLibraryManagerSetting, testName)
4243
assert.Nil(t, submissionURLs, testName)
4344

4445
testName = "Not list"
@@ -52,8 +53,9 @@ index d4edde0..807b76d 100644
5253
+hello
5354
`)
5455

55-
requestType, submissionURLs = parseDiff(diff, "repositories.txt")
56+
requestType, arduinoLintLibraryManagerSetting, submissionURLs = parseDiff(diff, "repositories.txt")
5657
assert.Equal(t, "other", requestType, testName)
58+
assert.Equal(t, "", arduinoLintLibraryManagerSetting, testName)
5759
assert.Nil(t, submissionURLs, testName)
5860

5961
testName = "List filename change"
@@ -69,8 +71,9 @@ index cff484d..e14c179 100644
6971
+https://github.com/foo/bar
7072
`)
7173

72-
requestType, submissionURLs = parseDiff(diff, "repositories.txt")
74+
requestType, arduinoLintLibraryManagerSetting, submissionURLs = parseDiff(diff, "repositories.txt")
7375
assert.Equal(t, "other", requestType, testName)
76+
assert.Equal(t, "", arduinoLintLibraryManagerSetting, testName)
7477
assert.Nil(t, submissionURLs, testName)
7578

7679
testName = "Submission"
@@ -84,8 +87,9 @@ index cff484d..9f67763 100644
8487
+https://github.com/foo/baz
8588
`)
8689

87-
requestType, submissionURLs = parseDiff(diff, "repositories.txt")
90+
requestType, arduinoLintLibraryManagerSetting, submissionURLs = parseDiff(diff, "repositories.txt")
8891
assert.Equal(t, "submission", requestType, testName)
92+
assert.Equal(t, "submit", arduinoLintLibraryManagerSetting, testName)
8993
assert.ElementsMatch(t, submissionURLs, []string{"https://github.com/foo/bar", "https://github.com/foo/baz"}, testName)
9094

9195
testName = "Submission w/ no newline at end of file"
@@ -99,8 +103,9 @@ index cff484d..1b0b80b 100644
99103
\ No newline at end of file
100104
`)
101105

102-
requestType, submissionURLs = parseDiff(diff, "repositories.txt")
106+
requestType, arduinoLintLibraryManagerSetting, submissionURLs = parseDiff(diff, "repositories.txt")
103107
assert.Equal(t, "submission", requestType, testName)
108+
assert.Equal(t, "submit", arduinoLintLibraryManagerSetting, testName)
104109
assert.ElementsMatch(t, submissionURLs, []string{"https://github.com/foo/bar"}, testName)
105110

106111
testName = "Submission w/ blank line"
@@ -114,8 +119,9 @@ index cff484d..1b0b80b 100644
114119
\ No newline at end of file
115120
`)
116121

117-
requestType, submissionURLs = parseDiff(diff, "repositories.txt")
122+
requestType, arduinoLintLibraryManagerSetting, submissionURLs = parseDiff(diff, "repositories.txt")
118123
assert.Equal(t, "submission", requestType, testName)
124+
assert.Equal(t, "submit", arduinoLintLibraryManagerSetting, testName)
119125
assert.ElementsMatch(t, submissionURLs, []string{"https://github.com/foo/bar"}, testName)
120126

121127
testName = "Removal"
@@ -128,8 +134,9 @@ index cff484d..38e11d8 100644
128134
-https://github.com/arduino-libraries/Ethernet
129135
`)
130136

131-
requestType, submissionURLs = parseDiff(diff, "repositories.txt")
137+
requestType, arduinoLintLibraryManagerSetting, submissionURLs = parseDiff(diff, "repositories.txt")
132138
assert.Equal(t, "removal", requestType, testName)
139+
assert.Equal(t, "", arduinoLintLibraryManagerSetting, testName)
133140
assert.Nil(t, submissionURLs, testName)
134141

135142
testName = "Modification"
@@ -143,8 +150,9 @@ index cff484d..8b401a1 100644
143150
+https://github.com/foo/bar
144151
`)
145152

146-
requestType, submissionURLs = parseDiff(diff, "repositories.txt")
153+
requestType, arduinoLintLibraryManagerSetting, submissionURLs = parseDiff(diff, "repositories.txt")
147154
assert.Equal(t, "modification", requestType, testName)
155+
assert.Equal(t, "update", arduinoLintLibraryManagerSetting, testName)
148156
assert.Equal(t, submissionURLs, []string{"https://github.com/foo/bar"}, testName)
149157
}
150158

0 commit comments

Comments
 (0)