Skip to content

Commit ce9a8c4

Browse files
authored
chore: use submodule nph in CI to check lint (#3027)
1 parent a3cd2a1 commit ce9a8c4

File tree

15 files changed

+57
-70
lines changed

15 files changed

+57
-70
lines changed

.github/workflows/ci.yml

+24-13
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
118118
export MAKEFLAGS="-j1"
119119
export NIMFLAGS="--colors:off -d:chronicles_colors:none"
120-
120+
121121
make V=1 LOG_LEVEL=DEBUG QUICK_AND_DIRTY_COMPILER=1 POSTGRES=$postgres_enabled test testwakunode2
122122
123123
build-docker-image:
@@ -141,25 +141,36 @@ jobs:
141141
nim_wakunode_image: ${{ needs.build-docker-image.outputs.image }}
142142
test_type: node-optional
143143
debug: waku*
144-
144+
145145
lint:
146146
name: "Lint"
147147
runs-on: ubuntu-latest
148+
needs: build
148149
steps:
149-
- name: Checkout
150-
uses: actions/checkout@v4
150+
- name: Checkout code
151+
uses: actions/checkout@v3
152+
153+
- name: Get submodules hash
154+
id: submodules
155+
run: |
156+
echo "hash=$(git submodule status | awk '{print $1}' | sort | shasum -a 256 | sed 's/[ -]*//g')" >> $GITHUB_OUTPUT
157+
158+
- name: Cache submodules
159+
uses: actions/cache@v3
151160
with:
152-
fetch-depth: 2 # In PR, has extra merge commit: ^1 = PR, ^2 = base
161+
path: |
162+
vendor/
163+
.git/modules
164+
key: ${{ runner.os }}-vendor-modules-${{ steps.submodules.outputs.hash }}
165+
166+
- name: Build nph
167+
run: |
168+
make build-nph
153169
154170
- name: Check nph formatting
155-
# Pin nph to a specific version to avoid sudden style differences.
156-
# Updating nph version should be accompanied with running the new
157-
# version on the fluffy directory.
158171
run: |
159-
VERSION="v0.5.1"
160-
ARCHIVE="nph-linux_x64.tar.gz"
161-
curl -L "https://github.com/arnetheduck/nph/releases/download/${VERSION}/${ARCHIVE}" -o ${ARCHIVE}
162-
tar -xzf ${ARCHIVE}
163172
shopt -s extglob # Enable extended globbing
164-
./nph examples waku tests tools apps *.@(nim|nims|nimble)
173+
NPH=$(make print-nph-path)
174+
echo "using nph at ${NPH}"
175+
"${NPH}" examples waku tests tools apps *.@(nim|nims|nimble)
165176
git diff --exit-code

Makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,10 @@ networkmonitor: | build deps librln
270270
############
271271
## Format ##
272272
############
273-
.PHONY: build-nph clean-nph install-nph
273+
.PHONY: build-nph install-nph clean-nph print-nph-path
274274

275275
build-nph:
276-
ifeq ("$(wildcard $(NPH))","")
277-
$(ENV_SCRIPT) nim c vendor/nph/src/nph.nim
278-
endif
276+
$(ENV_SCRIPT) nim c vendor/nph/src/nph.nim
279277

280278
GIT_PRE_COMMIT_HOOK := .git/hooks/pre-commit
281279

@@ -294,6 +292,10 @@ nph/%: build-nph
294292
clean-nph:
295293
rm -f $(NPH)
296294

295+
# To avoid hardcoding nph binary location in several places
296+
print-nph-path:
297+
echo "$(NPH)"
298+
297299
clean: | clean-nph
298300

299301
###################

apps/liteprotocoltester/liteprotocoltester.nim

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ when isMainModule:
7575
wnconf: WakuNodeConf, sources: auto
7676
) {.gcsafe, raises: [ConfigurationError].} =
7777
echo "Loading secondary configuration file into WakuNodeConf"
78-
sources.addConfigFile(Toml, configFile)
79-
,
78+
sources.addConfigFile(Toml, configFile),
8079
)
8180
except CatchableError:
8281
error "Loading Waku configuration failed", error = getCurrentExceptionMsg()

apps/liteprotocoltester/tester_config.nim

+1-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ proc load*(T: type LiteProtocolTesterConf, version = ""): ConfResult[T] =
159159
secondarySources = proc(
160160
conf: LiteProtocolTesterConf, sources: auto
161161
) {.gcsafe, raises: [ConfigurationError].} =
162-
sources.addConfigFile(Envvar, InputFile("liteprotocoltester"))
163-
,
162+
sources.addConfigFile(Envvar, InputFile("liteprotocoltester")),
164163
)
165164
ok(conf)
166165
except CatchableError:

tests/testlib/wakunode.nim

+2-4
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,12 @@ proc newTestWakuNode*(
137137
if secureKey != "":
138138
some(secureKey)
139139
else:
140-
none(string)
141-
,
140+
none(string),
142141
secureCert =
143142
if secureCert != "":
144143
some(secureCert)
145144
else:
146-
none(string)
147-
,
145+
none(string),
148146
agentString = agentString,
149147
)
150148

tests/wakunode_rest/test_rest_store.nim

+4-8
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ procSuite "Waku Rest API - Store v3":
297297
if reqHash.isSome():
298298
reqHash.get().toRestStringWakuMessageHash()
299299
else:
300-
""
301-
, # base64-encoded digest. Empty ignores the field.
300+
"", # base64-encoded digest. Empty ignores the field.
302301
"true", # ascending
303302
"7", # page size. Empty implies default page size.
304303
)
@@ -790,8 +789,7 @@ procSuite "Waku Rest API - Store v3":
790789
if reqHash.isSome():
791790
reqHash.get().toRestStringWakuMessageHash()
792791
else:
793-
""
794-
, # base64-encoded digest. Empty ignores the field.
792+
"", # base64-encoded digest. Empty ignores the field.
795793
"true", # ascending
796794
"3", # page size. Empty implies default page size.
797795
)
@@ -827,8 +825,7 @@ procSuite "Waku Rest API - Store v3":
827825
if reqHash.isSome():
828826
reqHash.get().toRestStringWakuMessageHash()
829827
else:
830-
""
831-
, # base64-encoded digest. Empty ignores the field.
828+
"", # base64-encoded digest. Empty ignores the field.
832829
)
833830

834831
check:
@@ -850,8 +847,7 @@ procSuite "Waku Rest API - Store v3":
850847
if reqHash.isSome():
851848
reqHash.get().toRestStringWakuMessageHash()
852849
else:
853-
""
854-
, # base64-encoded digest. Empty ignores the field.
850+
"", # base64-encoded digest. Empty ignores the field.
855851
"true", # ascending
856852
"5", # page size. Empty implies default page size.
857853
)

waku/node/peer_manager/waku_peer_store.nim

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ proc get*(peerStore: PeerStore, peerId: PeerID): RemotePeerInfo =
5555
if peerStore[ENRBook][peerId] != default(enr.Record):
5656
some(peerStore[ENRBook][peerId])
5757
else:
58-
none(enr.Record)
59-
,
58+
none(enr.Record),
6059
protocols: peerStore[ProtoBook][peerId],
6160
agent: peerStore[AgentBook][peerId],
6261
protoVersion: peerStore[ProtoVersionBook][peerId],

waku/waku_api/rest/filter/types.nim

+4-8
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ proc toFilterWakuMessage*(msg: WakuMessage): FilterWakuMessage =
5858
if msg.meta.len > 0:
5959
some(base64.encode(msg.meta))
6060
else:
61-
none(Base64String)
62-
,
61+
none(Base64String),
6362
ephemeral: some(msg.ephemeral),
6463
)
6564

@@ -239,8 +238,7 @@ proc readValue*(
239238
if pubsubTopic.isNone() or pubsubTopic.get() == "":
240239
none(string)
241240
else:
242-
some(pubsubTopic.get())
243-
,
241+
some(pubsubTopic.get()),
244242
contentFilters: contentFilters.get(),
245243
)
246244

@@ -315,8 +313,7 @@ proc readValue*(
315313
if pubsubTopic.isNone() or pubsubTopic.get() == "":
316314
none(string)
317315
else:
318-
some(pubsubTopic.get())
319-
,
316+
some(pubsubTopic.get()),
320317
contentFilters: contentFilters.get(),
321318
)
322319

@@ -364,8 +361,7 @@ proc readValue*(
364361
if pubsubTopic.isNone() or pubsubTopic.get() == "":
365362
none(string)
366363
else:
367-
some(pubsubTopic.get())
368-
,
364+
some(pubsubTopic.get()),
369365
contentFilters: contentFilters.get(),
370366
)
371367

waku/waku_api/rest/legacy_store/types.nim

+1-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ proc toStoreResponseRest*(histResp: HistoryResponse): StoreResponseRest =
110110
if message.meta.len > 0:
111111
some(base64.encode(message.meta))
112112
else:
113-
none(Base64String)
114-
,
113+
none(Base64String),
115114
)
116115

117116
var storeWakuMsgs: seq[StoreWakuMessage]

waku/waku_api/rest/lightpush/types.nim

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ proc readValue*(
6262
if pubsubTopic.isNone() or pubsubTopic.get() == "":
6363
none(string)
6464
else:
65-
some(pubsubTopic.get())
66-
,
65+
some(pubsubTopic.get()),
6766
message: message.get(),
6867
)

waku/waku_api/rest/relay/types.nim

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ proc toRelayWakuMessage*(msg: WakuMessage): RelayWakuMessage =
3434
if msg.meta.len > 0:
3535
some(base64.encode(msg.meta))
3636
else:
37-
none(Base64String)
38-
,
37+
none(Base64String),
3938
ephemeral: some(msg.ephemeral),
4039
)
4140

waku/waku_archive/driver/sqlite_driver/queries.nim

+4-8
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ proc createTable*(db: SqliteDatabase): DatabaseResult[void] =
8282
?db.query(
8383
query,
8484
proc(s: ptr sqlite3_stmt) =
85-
discard
86-
,
85+
discard,
8786
)
8887
return ok()
8988

@@ -98,8 +97,7 @@ proc createOldestMessageTimestampIndex*(db: SqliteDatabase): DatabaseResult[void
9897
?db.query(
9998
query,
10099
proc(s: ptr sqlite3_stmt) =
101-
discard
102-
,
100+
discard,
103101
)
104102
return ok()
105103

@@ -184,8 +182,7 @@ proc deleteMessagesOlderThanTimestamp*(
184182
?db.query(
185183
query,
186184
proc(s: ptr sqlite3_stmt) =
187-
discard
188-
,
185+
discard,
189186
)
190187
return ok()
191188

@@ -206,8 +203,7 @@ proc deleteOldestMessagesNotWithinLimit*(
206203
?db.query(
207204
query,
208205
proc(s: ptr sqlite3_stmt) =
209-
discard
210-
,
206+
discard,
211207
)
212208
return ok()
213209

waku/waku_archive_legacy/driver/sqlite_driver/queries.nim

+5-10
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ proc createTable*(db: SqliteDatabase): DatabaseResult[void] =
9696
?db.query(
9797
query,
9898
proc(s: ptr sqlite3_stmt) =
99-
discard
100-
,
99+
discard,
101100
)
102101
return ok()
103102

@@ -112,8 +111,7 @@ proc createOldestMessageTimestampIndex*(db: SqliteDatabase): DatabaseResult[void
112111
?db.query(
113112
query,
114113
proc(s: ptr sqlite3_stmt) =
115-
discard
116-
,
114+
discard,
117115
)
118116
return ok()
119117

@@ -127,8 +125,7 @@ proc createHistoryQueryIndex*(db: SqliteDatabase): DatabaseResult[void] =
127125
?db.query(
128126
query,
129127
proc(s: ptr sqlite3_stmt) =
130-
discard
131-
,
128+
discard,
132129
)
133130
return ok()
134131

@@ -226,8 +223,7 @@ proc deleteMessagesOlderThanTimestamp*(
226223
?db.query(
227224
query,
228225
proc(s: ptr sqlite3_stmt) =
229-
discard
230-
,
226+
discard,
231227
)
232228
return ok()
233229

@@ -248,8 +244,7 @@ proc deleteOldestMessagesNotWithinLimit*(
248244
?db.query(
249245
query,
250246
proc(s: ptr sqlite3_stmt) =
251-
discard
252-
,
247+
discard,
253248
)
254249
return ok()
255250

waku/waku_keystore/utils.nim

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ proc hasKeys*(data: JsonNode, keys: openArray[string]): bool =
99
return all(
1010
keys,
1111
proc(key: string): bool =
12-
return data.hasKey(key)
13-
,
12+
return data.hasKey(key),
1413
)
1514

1615
# Safely saves a Keystore's JsonNode to disk.

0 commit comments

Comments
 (0)