From a284a0e4bfdb24ea5e1df7c58cb1dd6d6c839097 Mon Sep 17 00:00:00 2001 From: Pion <59523206+pionbot@users.noreply.github.com> Date: Wed, 16 Nov 2022 12:01:35 +0000 Subject: [PATCH] Update CI configs to v0.8.1 Update lint scripts and CI configs. --- .github/generate-authors.sh | 23 +++++++-------- .github/install-hooks.sh | 6 ++-- .github/lint-commit-message.sh | 4 +-- .../lint-disallowed-functions-in-library.sh | 29 ++++++++----------- .github/lint-filename.sh | 8 ++--- ...int-no-trailing-newline-in-log-messages.sh | 24 +++++++-------- 6 files changed, 41 insertions(+), 53 deletions(-) diff --git a/.github/generate-authors.sh b/.github/generate-authors.sh index 182e4f5..6152721 100755 --- a/.github/generate-authors.sh +++ b/.github/generate-authors.sh @@ -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 @@ -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 @@ -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 diff --git a/.github/install-hooks.sh b/.github/install-hooks.sh index 73d20a4..cd899d4 100755 --- a/.github/install-hooks.sh +++ b/.github/install-hooks.sh @@ -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" diff --git a/.github/lint-commit-message.sh b/.github/lint-commit-message.sh index 010a332..2beb31d 100755 --- a/.github/lint-commit-message.sh +++ b/.github/lint-commit-message.sh @@ -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 diff --git a/.github/lint-disallowed-functions-in-library.sh b/.github/lint-disallowed-functions-in-library.sh index 8ce5d09..9dd988f 100755 --- a/.github/lint-disallowed-functions-in-library.sh +++ b/.github/lint-disallowed-functions-in-library.sh @@ -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 diff --git a/.github/lint-filename.sh b/.github/lint-filename.sh index 81b3f14..3e7d1b9 100755 --- a/.github/lint-filename.sh +++ b/.github/lint-filename.sh @@ -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 diff --git a/.github/lint-no-trailing-newline-in-log-messages.sh b/.github/lint-no-trailing-newline-in-log-messages.sh index 29cd4a2..f0dad59 100755 --- a/.github/lint-no-trailing-newline-in-log-messages.sh +++ b/.github/lint-no-trailing-newline-in-log-messages.sh @@ -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 \ No newline at end of file