Skip to content

Commit

Permalink
Update CI configs to v0.3.1
Browse files Browse the repository at this point in the history
Update lint scripts and CI configs.


Former-commit-id: a1f290d
  • Loading branch information
pionbot authored and tarrencev committed May 14, 2020
1 parent 7c3003a commit 32009e0
Show file tree
Hide file tree
Showing 12 changed files with 435 additions and 6 deletions.
56 changes: 56 additions & 0 deletions .github/assert-contributors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

#
# DO NOT EDIT THIS FILE DIRECTLY
#
# It is automatically copied from https://github.com/pion/.goassets repository.
#

set -e

# Unshallow the repo, this check doesn't work with this enabled
# https://github.com/travis-ci/travis-ci/issues/3412
if [ -f $(git rev-parse --git-dir)/shallow ]; then
git fetch --unshallow || true
fi

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

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

EXCLUDED_CONTRIBUTORS+=('John R. Bradley' 'renovate[bot]' 'Renovate Bot' 'Pion Bot')
MISSING_CONTRIBUTORS=()

shouldBeIncluded () {
for i in "${EXCLUDED_CONTRIBUTORS[@]}"
do
if [ "$i" == "$1" ] ; then
return 1
fi
done
return 0
}


IFS=$'\n' #Only split on newline
for contributor in $(git log --format='%aN' | sort -u)
do
if shouldBeIncluded $contributor; then
if ! grep -q "$contributor" "$SCRIPT_PATH/../README.md"; then
MISSING_CONTRIBUTORS+=("$contributor")
fi
fi
done
unset IFS

if [ ${#MISSING_CONTRIBUTORS[@]} -ne 0 ]; then
echo "Please add the following contributors to the README"
for i in "${MISSING_CONTRIBUTORS[@]}"
do
echo "$i"
done
exit 1
fi
11 changes: 11 additions & 0 deletions .github/hooks/commit-msg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

#
# DO NOT EDIT THIS FILE DIRECTLY
#
# It is automatically copied from https://github.com/pion/.goassets repository.
#

set -e

.github/lint-commit-message.sh $1
12 changes: 12 additions & 0 deletions .github/hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

#
# DO NOT EDIT THIS FILE DIRECTLY
#
# It is automatically copied from https://github.com/pion/.goassets repository.
#

# Redirect output to stderr.
exec 1>&2

.github/lint-disallowed-functions-in-library.sh
13 changes: 13 additions & 0 deletions .github/hooks/pre-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

#
# DO NOT EDIT THIS FILE DIRECTLY
#
# It is automatically copied from https://github.com/pion/.goassets repository.
#

set -e

.github/assert-contributors.sh

exit 0
13 changes: 13 additions & 0 deletions .github/install-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

#
# DO NOT EDIT THIS FILE DIRECTLY
#
# It is automatically copied from https://github.com/pion/.goassets repository.
#

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"
67 changes: 67 additions & 0 deletions .github/lint-commit-message.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

#
# DO NOT EDIT THIS FILE DIRECTLY
#
# It is automatically copied from https://github.com/pion/.goassets repository.
#

set -e

display_commit_message_error() {
cat << EndOfMessage
$1
-------------------------------------------------
The preceding commit message is invalid
it failed '$2' of the following checks
* Separate subject from body with a blank line
* Limit the subject line to 50 characters
* Capitalize the subject line
* Do not end the subject line with a period
* Wrap the body at 72 characters
EndOfMessage

exit 1
}

lint_commit_message() {
if [[ "$(echo "$1" | awk 'NR == 2 {print $1;}' | wc -c)" -ne 1 ]]; then
display_commit_message_error "$1" 'Separate subject from body with a blank line'
fi

if [[ "$(echo "$1" | head -n1 | awk '{print length}')" -gt 50 ]]; then
display_commit_message_error "$1" 'Limit the subject line to 50 characters'
fi

if [[ ! $1 =~ ^[A-Z] ]]; then
display_commit_message_error "$1" 'Capitalize the subject line'
fi

if [[ "$(echo "$1" | awk 'NR == 1 {print substr($0,length($0),1)}')" == "." ]]; then
display_commit_message_error "$1" 'Do not end the subject line with a period'
fi

if [[ "$(echo "$1" | awk '{print length}' | sort -nr | head -1)" -gt 72 ]]; then
display_commit_message_error "$1" 'Wrap the body at 72 characters'
fi
}

if [ "$#" -eq 1 ]; then
if [ ! -f "$1" ]; then
echo "$0 was passed one argument, but was not a valid file"
exit 1
fi
lint_commit_message "$(sed -n '/# Please enter the commit message for your changes. Lines starting/q;p' "$1")"
else
# TRAVIS_COMMIT_RANGE is empty for initial branch commit
if [[ "${TRAVIS_COMMIT_RANGE}" != *"..."* ]]; then
parent=$(git log -n 1 --format="%P" ${TRAVIS_COMMIT_RANGE})
TRAVIS_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE}...$parent"
fi

for commit in $(git rev-list ${TRAVIS_COMMIT_RANGE}); do
lint_commit_message "$(git log --format="%B" -n 1 $commit)"
done
fi
45 changes: 45 additions & 0 deletions .github/lint-disallowed-functions-in-library.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

#
# DO NOT EDIT THIS FILE DIRECTLY
#
# It is automatically copied from https://github.com/pion/.goassets 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

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(')

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
break
fi
done
$excluded || echo "$file"
done
)

for disallowedFunction in "${DISALLOWED_FUNCTIONS[@]}"
do
if grep -e "$disallowedFunction" $files | grep -v -e 'nolint'; then
echo "$disallowedFunction may only be used in example code"
exit 1
fi
done
21 changes: 21 additions & 0 deletions .github/lint-filename.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

#
# DO NOT EDIT THIS FILE DIRECTLY
#
# It is automatically copied from https://github.com/pion/.goassets repository.
#

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")

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
30 changes: 30 additions & 0 deletions .github/workflows/renovate-go-mod-fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# DO NOT EDIT THIS FILE DIRECTLY
#
# It is automatically copied from https://github.com/pion/.goassets repository.
# If this repository should have package specific CI config,
# remove the repository name from .goassets/.github/workflows/assets-sync.yml.
#

name: go-mod-fix
on:
push:
branches:
- renovate/*

jobs:
go-mod-fix:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: fix
uses: at-wat/go-sum-fix-action@v0
with:
git_user: Pion Bot
git_email: [email protected]
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_style: squash
push: force
Loading

0 comments on commit 32009e0

Please sign in to comment.