Skip to content

Commit e2a7a3e

Browse files
authored
add shellcheck to CI (#1423)
* add shellcheck to CI * fix shellcheck warnings * rename shellcheck to shell in workflow
1 parent f7141b4 commit e2a7a3e

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

.github/workflows/shell.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Shell
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
shellcheck:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
- name: Run shellcheck
18+
uses: ludeeus/[email protected]

scripts/add_license.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#!/bin/bash
2+
#
3+
# Checks if the source code contains required license and adds it if necessary.
4+
# Returns 1 if there was a missing license, 0 otherwise.
25

3-
PAT_APA="^// Copyright 2019-2022 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT$"
6+
PAT_APA="^// Copyright 2019-2022 ChainSafe Systems// SPDX-License-Identifier: Apache-2.0, MIT$"
47

5-
valid=true
6-
for file in $(find . -type f -not -path "./target/*" -not -path "./blockchain/beacon/src/drand_api/*" -not -path "./ipld/graphsync/src/message/proto/message.rs" | egrep '\.(rs)$'); do
7-
header=$(echo $(head -3 $file))
8+
ret=0
9+
for file in $(find . -type f -not -path "./target/*" -not -path "./blockchain/beacon/src/drand_api/*" -not -path "./ipld/graphsync/src/message/proto/message.rs" | grep -E '\.(rs)$'); do
10+
header=$(head -2 "$file" | tr -d '\n')
811
if ! echo "$header" | grep -q "$PAT_APA"; then
912
echo "$file was missing header"
10-
cat ./scripts/copyright.txt $file > temp
11-
mv temp $file
12-
valid=false
13+
cat ./scripts/copyright.txt "$file" > temp
14+
mv temp "$file"
15+
ret=1
1316
fi
1417
done
1518

16-
# if a header is incorrect, return an OS exit code
17-
if [ "$valid" = false ] ; then
18-
exit 1
19-
fi
19+
exit $ret

scripts/smoke_test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ GREEN='\033[0;32m'
1515
NC='\033[0m'
1616

1717
# extract token from auth api-info output
18-
TOKEN="$(cut -d':' -f1 <<< $FULL_ADDR)"
18+
TOKEN="$(cut -d':' -f1 <<< "$FULL_ADDR")"
1919
TOKEN=${TOKEN#"FULLNODE_API_INFO=\""}
2020

2121
# set headers for http requests
@@ -59,15 +59,15 @@ RPC_ENDPOINTS+=("StateMinerInitialPledgeCollateral" "MinerGetBaseInfo")
5959

6060

6161
# send requests programmatically
62-
for endpoint in ${RPC_ENDPOINTS[@]}; do
62+
for endpoint in "${RPC_ENDPOINTS[@]}"; do
6363
METHOD="Filecoin.${endpoint}"
6464
REQUEST_BODY="{\"jsonrpc\": \"2.0\", \"method\": \"$METHOD\", \"params\":[], \"id\": 0}"
6565

6666
RESPONSE_CODE=$(curl -w "%{http_code}" -s -o /dev/null -X POST -H "$CONTENT_TYPE_HEADER" -H "$AUTH_HEADER" -d "$REQUEST_BODY" http://127.0.0.1:1234/rpc/v0)
6767

6868
# a response is a response and considered a passing test
6969
# we are not passing params to endpoints so some methods will fail due to lack of params
70-
if [ $RESPONSE_CODE = '200' ] || [ $RESPONSE_CODE = '500' ]; then
70+
if [ "$RESPONSE_CODE" = '200' ] || [ "$RESPONSE_CODE" = '500' ]; then
7171
echo -e "${METHOD} ${GREEN} OK ${NC}"
7272
else
7373
echo -e "${METHOD} ${RED} FAIL ${RESPONSE_CODE} ${NC}"
@@ -76,4 +76,4 @@ for endpoint in ${RPC_ENDPOINTS[@]}; do
7676
done
7777

7878
# Kill forest daemon
79-
ps -ef | grep forest | grep -v grep | awk '{print $2}' | xargs kill
79+
pgrep forest | xargs kill

0 commit comments

Comments
 (0)