diff --git a/.github/hooks/pre-commit.sh b/.github/hooks/pre-commit.sh index cc318d7..d5a1ce5 100755 --- a/.github/hooks/pre-commit.sh +++ b/.github/hooks/pre-commit.sh @@ -10,3 +10,4 @@ exec 1>&2 .github/lint-disallowed-functions-in-library.sh +.github/lint-no-trailing-newline-in-log-messages.sh diff --git a/.github/lint-no-trailing-newline-in-log-messages.sh b/.github/lint-no-trailing-newline-in-log-messages.sh new file mode 100755 index 0000000..29cd4a2 --- /dev/null +++ b/.github/lint-no-trailing-newline-in-log-messages.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# +# DO NOT EDIT THIS FILE +# +# It is automatically copied from https://github.com/pion/.goassets repository. +# +# If you want to update the shared CI config, send a PR to +# https://github.com/pion/.goassets instead of this repository. +# + +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 + . ${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 + break + fi + done + $excluded || echo "$file" + done +) + +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 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 18641ca..69bef30 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -18,6 +18,14 @@ jobs: - name: Checkout repo uses: actions/checkout@v3 + # The code in examples/ might intentionally do things like log credentials + # in order to show how the library is used, aid in debugging etc. We + # should ignore those for CodeQL scanning, and only focus on the package + # itself. + - name: Remove example code + run: | + rm -rf examples/ + - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index d284b19..3858008 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -36,6 +36,9 @@ jobs: - name: Functions run: .github/lint-disallowed-functions-in-library.sh + - name: Logging messages should not have trailing newlines + run: .github/lint-no-trailing-newline-in-log-messages.sh + lint-go: name: Go runs-on: ubuntu-latest diff --git a/AUTHORS.txt b/AUTHORS.txt index 301f3f4..e1f9e55 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -44,6 +44,7 @@ Sean DuBois Sean DuBois Sebastian Waisbrot Sidney San Martín +Steffen Vogel Will Forcey Woodrow Douglass Yutaka Takeda