Merge pull request #6064 from zmstone/style-check-newline-at-eof
Style: check newline at EOF
This commit is contained in:
commit
3b02366a5b
|
@ -0,0 +1,27 @@
|
|||
name: Code style check
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 1000
|
||||
- name: Set git token
|
||||
if: endsWith(github.repository, 'enterprise')
|
||||
run: |
|
||||
echo "https://ci%40emqx.io:${{ secrets.CI_GIT_TOKEN }}@github.com" > $HOME/.git-credentials
|
||||
git config --global credential.helper store
|
||||
- name: Run elvis check
|
||||
run: |
|
||||
set -e
|
||||
if [ -f EMQX_ENTERPRISE ]; then
|
||||
./scripts/elvis-check.sh $GITHUB_BASE_REF emqx-enterprise
|
||||
else
|
||||
./scripts/elvis-check.sh $GITHUB_BASE_REF emqx
|
||||
fi
|
||||
- name: Check line-break at EOF
|
||||
- run: |
|
||||
./scripts/check-nl-at-eof.sh
|
|
@ -1,16 +0,0 @@
|
|||
name: Elvis Linter
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set git token
|
||||
if: endsWith(github.repository, 'enterprise')
|
||||
run: |
|
||||
echo "https://ci%40emqx.io:${{ secrets.CI_GIT_TOKEN }}@github.com" > $HOME/.git-credentials
|
||||
git config --global credential.helper store
|
||||
- run: |
|
||||
./scripts/elvis-check.sh $GITHUB_BASE_REF
|
|
@ -112,7 +112,8 @@ t_out(_) ->
|
|||
t_out_2(_) ->
|
||||
{empty, {pqueue, [{-1, {queue, [a], [], 1}}]}} = ?PQ:out(0, ?PQ:from_list([{1, a}])),
|
||||
{{value, a}, {queue, [], [], 0}} = ?PQ:out(1, ?PQ:from_list([{1, a}])),
|
||||
{{value, a}, {pqueue, [{-1, {queue, [], [b], 1}}]}} = ?PQ:out(1, ?PQ:from_list([{1, a}, {1, b}])),
|
||||
{{value, a}, {pqueue, [{-1, {queue, [], [b], 1}}]}} =
|
||||
?PQ:out(1, ?PQ:from_list([{1, a}, {1, b}])),
|
||||
{{value, a}, {queue, [b], [], 1}} = ?PQ:out(1, ?PQ:from_list([{1, a}, {0, b}])).
|
||||
|
||||
t_out_p(_) ->
|
||||
|
|
|
@ -100,7 +100,8 @@ on_start(InstId, #{redis_type := Type,
|
|||
Options = case maps:get(enable, SSL) of
|
||||
true ->
|
||||
[{ssl, true},
|
||||
{ssl_options, emqx_plugin_libs_ssl:save_files_return_opts(SSL, "connectors", InstId)}
|
||||
{ssl_options,
|
||||
emqx_plugin_libs_ssl:save_files_return_opts(SSL, "connectors", InstId)}
|
||||
];
|
||||
false -> [{ssl, false}]
|
||||
end ++ [{sentinel, maps:get(sentinel, Config, undefined)}],
|
||||
|
|
|
@ -131,10 +131,10 @@ setnth(tail, List, Val) when is_list(List) -> List ++ [Val];
|
|||
setnth(tail, _List, Val) -> [Val];
|
||||
setnth(I, List, _Val) when not is_integer(I) -> List;
|
||||
setnth(0, List, _Val) -> List;
|
||||
setnth(I, List, _Val) when is_integer(I), I > 0 ->
|
||||
do_setnth(I, List, _Val);
|
||||
setnth(I, List, _Val) when is_integer(I), I < 0 ->
|
||||
lists:reverse(do_setnth(-I, lists:reverse(List), _Val)).
|
||||
setnth(I, List, Val) when is_integer(I), I > 0 ->
|
||||
do_setnth(I, List, Val);
|
||||
setnth(I, List, Val) when is_integer(I), I < 0 ->
|
||||
lists:reverse(do_setnth(-I, lists:reverse(List), Val)).
|
||||
|
||||
do_setnth(1, [_ | Rest], Val) -> [Val | Rest];
|
||||
do_setnth(I, [E | Rest], Val) -> [E | setnth(I-1, Rest, Val)];
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
cd -P -- "$(dirname -- "$0")/.."
|
||||
|
||||
nl_at_eof() {
|
||||
local file="$1"
|
||||
if ! [ -f "$file" ]; then
|
||||
return
|
||||
fi
|
||||
case "$file" in
|
||||
*.png|*rebar3)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
local lastbyte
|
||||
lastbyte="$(tail -c 1 "$file" 2>&1)"
|
||||
if [ "$lastbyte" != '' ]; then
|
||||
echo "$file"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
n=0
|
||||
while read -r file; do
|
||||
if ! nl_at_eof "$file"; then
|
||||
n=$(( n + 1 ))
|
||||
fi
|
||||
done < <(git ls-files)
|
||||
|
||||
exit $n
|
|
@ -5,16 +5,16 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
ELVIS_VERSION='1.0.0-emqx-2'
|
||||
elvis_version='1.0.0-emqx-2'
|
||||
|
||||
base="${1:-}"
|
||||
repo="${2:-emqx}"
|
||||
REPO="${GITHUB_REPOSITORY:-${repo}}"
|
||||
if [ "${base}" = "" ]; then
|
||||
echo "Usage $0 <git-compare-base-ref>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
elvis_version="${2:-$ELVIS_VERSION}"
|
||||
|
||||
echo "elvis -v: $elvis_version"
|
||||
echo "git diff base: $base"
|
||||
|
||||
|
@ -27,11 +27,7 @@ if [[ "$base" =~ [0-9a-f]{8,40} ]]; then
|
|||
# base is a commit sha1
|
||||
compare_base="$base"
|
||||
else
|
||||
if [[ $CI == true ]];then
|
||||
remote="$(git remote -v | grep -E "github\.com(.|/)$GITHUB_REPOSITORY" | grep fetch | awk '{print $1}')"
|
||||
else
|
||||
remote="$(git remote -v | grep -E 'github\.com(.|/)emqx' | grep fetch | awk '{print $1}')"
|
||||
fi
|
||||
remote="$(git remote -v | grep -E "github\.com(:|/)emqx/$REPO((\.git)|(\s))" | grep fetch | awk '{print $1}')"
|
||||
git fetch "$remote" "$base"
|
||||
compare_base="$remote/$base"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue