Skip to content

Commit

Permalink
Update CI configs to v0.8.1
Browse files Browse the repository at this point in the history
Update lint scripts and CI configs.
  • Loading branch information
pionbot authored and at-wat committed Jan 4, 2023
1 parent a33fda5 commit 994fbcd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 53 deletions.
23 changes: 10 additions & 13 deletions .github/generate-authors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
set -e

SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
AUTHORS_PATH="$GITHUB_WORKSPACE/AUTHORS.txt"
GIT_WORKDIR=${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel)}
AUTHORS_PATH="${GIT_WORKDIR}/AUTHORS.txt"

if [ -f ${SCRIPT_PATH}/.ci.conf ]
then
if [ -f ${SCRIPT_PATH}/.ci.conf ]; then
. ${SCRIPT_PATH}/.ci.conf
fi

Expand All @@ -31,8 +31,7 @@ EXCLUDED_CONTRIBUTORS+=('John R. Bradley' 'renovate[bot]' 'Renovate Bot' 'Pion B
CONTRIBUTORS=()

shouldBeIncluded () {
for i in "${EXCLUDED_CONTRIBUTORS[@]}"
do
for i in "${EXCLUDED_CONTRIBUTORS[@]}"; do
if [[ $1 =~ "$i" ]]; then
return 1
fi
Expand All @@ -42,25 +41,23 @@ shouldBeIncluded () {


IFS=$'\n' #Only split on newline
for contributor in $(git log --format='%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf)
do
if shouldBeIncluded $contributor; then
CONTRIBUTORS+=("$contributor")
for CONTRIBUTOR in $(git log --format='%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf); do
if shouldBeIncluded ${CONTRIBUTOR}; then
CONTRIBUTORS+=("${CONTRIBUTOR}")
fi
done
unset IFS

if [ ${#CONTRIBUTORS[@]} -ne 0 ]; then
cat >$AUTHORS_PATH <<-'EOH'
cat >${AUTHORS_PATH} <<-'EOH'
# Thank you to everyone that made Pion possible. If you are interested in contributing
# we would love to have you https://github.com/pion/webrtc/wiki/Contributing
#
# This file is auto generated, using git to list all individuals contributors.
# see `.github/generate-authors.sh` for the scripting
EOH
for i in "${CONTRIBUTORS[@]}"
do
echo "$i" >> $AUTHORS_PATH
for i in "${CONTRIBUTORS[@]}"; do
echo "$i" >> ${AUTHORS_PATH}
done
exit 0
fi
6 changes: 3 additions & 3 deletions .github/install-hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )

cp "$SCRIPT_PATH/hooks/commit-msg.sh" "$SCRIPT_PATH/../.git/hooks/commit-msg"
cp "$SCRIPT_PATH/hooks/pre-commit.sh" "$SCRIPT_PATH/../.git/hooks/pre-commit"
cp "$SCRIPT_PATH/hooks/pre-push.sh" "$SCRIPT_PATH/../.git/hooks/pre-push"
cp "${SCRIPT_PATH}/hooks/commit-msg.sh" "${SCRIPT_PATH}/../.git/hooks/commit-msg"
cp "${SCRIPT_PATH}/hooks/pre-commit.sh" "${SCRIPT_PATH}/../.git/hooks/pre-commit"
cp "${SCRIPT_PATH}/hooks/pre-push.sh" "${SCRIPT_PATH}/../.git/hooks/pre-push"
4 changes: 2 additions & 2 deletions .github/lint-commit-message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if [ "$#" -eq 1 ]; then
fi
lint_commit_message "$(sed -n '/# Please enter the commit message for your changes. Lines starting/q;p' "$1")"
else
for commit in $(git rev-list --no-merges origin/master..); do
lint_commit_message "$(git log --format="%B" -n 1 $commit)"
for COMMIT in $(git rev-list --no-merges origin/master..); do
lint_commit_message "$(git log --format="%B" -n 1 ${COMMIT})"
done
fi
29 changes: 12 additions & 17 deletions .github/lint-disallowed-functions-in-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,31 @@ set -e

# Disallow usages of functions that cause the program to exit in the library code
SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
if [ -f ${SCRIPT_PATH}/.ci.conf ]
then
if [ -f ${SCRIPT_PATH}/.ci.conf ]; then
. ${SCRIPT_PATH}/.ci.conf
fi

EXCLUDE_DIRECTORIES=${DISALLOWED_FUNCTIONS_EXCLUDED_DIRECTORIES:-"examples"}
DISALLOWED_FUNCTIONS=('os.Exit(' 'panic(' 'Fatal(' 'Fatalf(' 'Fatalln(' 'fmt.Println(' 'fmt.Printf(' 'log.Print(' 'log.Println(' 'log.Printf(' 'print(' 'println(')

files=$(
find "$SCRIPT_PATH/.." -name "*.go" \
FILES=$(
find "${SCRIPT_PATH}/.." -name "*.go" \
| grep -v -e '^.*_test.go$' \
| while read file
do
excluded=false
for ex in $EXCLUDE_DIRECTORIES
do
if [[ $file == */$ex/* ]]
then
excluded=true
| while read FILE; do
EXCLUDED=false
for EXCLUDE_DIRECTORY in ${EXCLUDE_DIRECTORIES}; do
if [[ ${FILE} == */${EXCLUDE_DIRECTORY}/* ]]; then
EXCLUDED=true
break
fi
done
$excluded || echo "$file"
${EXCLUDED} || echo "${FILE}"
done
)

for disallowedFunction in "${DISALLOWED_FUNCTIONS[@]}"
do
if grep -e "\s$disallowedFunction" $files | grep -v -e 'nolint'; then
echo "$disallowedFunction may only be used in example code"
for DISALLOWED_FUNCTION in "${DISALLOWED_FUNCTIONS[@]}"; do
if grep -e "\s${DISALLOWED_FUNCTION}" ${FILES} | grep -v -e 'nolint'; then
echo "${DISALLOWED_FUNCTION} may only be used in example code"
exit 1
fi
done
8 changes: 4 additions & 4 deletions .github/lint-filename.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ set -e
SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
GO_REGEX="^[a-zA-Z][a-zA-Z0-9_]*\.go$"

find "$SCRIPT_PATH/.." -name "*.go" | while read fullpath; do
filename=$(basename -- "$fullpath")
find "${SCRIPT_PATH}/.." -name "*.go" | while read FULLPATH; do
FILENAME=$(basename -- "${FULLPATH}")

if ! [[ $filename =~ $GO_REGEX ]]; then
echo "$filename is not a valid filename for Go code, only alpha, numbers and underscores are supported"
if ! [[ ${FILENAME} =~ ${GO_REGEX} ]]; then
echo "${FILENAME} is not a valid filename for Go code, only alpha, numbers and underscores are supported"
exit 1
fi
done
24 changes: 10 additions & 14 deletions .github/lint-no-trailing-newline-in-log-messages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,25 @@ set -e

# Disallow usages of functions that cause the program to exit in the library code
SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
if [ -f ${SCRIPT_PATH}/.ci.conf ]
then
if [ -f ${SCRIPT_PATH}/.ci.conf ]; then
. ${SCRIPT_PATH}/.ci.conf
fi

files=$(
find "$SCRIPT_PATH/.." -name "*.go" \
| while read file
do
excluded=false
for ex in $EXCLUDE_DIRECTORIES
do
if [[ $file == */$ex/* ]]
then
excluded=true
FILES=$(
find "${SCRIPT_PATH}/.." -name "*.go" \
| while read FILE; do
EXCLUDED=false
for EXCLUDE_DIRECTORY in ${EXCLUDE_DIRECTORIES}; do
if [[ $file == */${EXCLUDE_DIRECTORY}/* ]]; then
EXCLUDED=true
break
fi
done
$excluded || echo "$file"
${EXCLUDED} || echo "${FILE}"
done
)

if grep -E '\.(Trace|Debug|Info|Warn|Error)f?\("[^"]*\\n"\)?' $files | grep -v -e 'nolint'; then
if grep -E '\.(Trace|Debug|Info|Warn|Error)f?\("[^"]*\\n"\)?' ${FILES} | grep -v -e 'nolint'; then
echo "Log format strings should have trailing new-line"
exit 1
fi

0 comments on commit 994fbcd

Please sign in to comment.