Merge pull request #40335 from aaronfranke/formatting-gh-actions

Use GitHub Actions for file formatting and style checks
This commit is contained in:
Rémi Verschelde 2020-07-14 08:40:32 +02:00 committed by GitHub
commit 41802d8397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
758 changed files with 999 additions and 1017 deletions

31
.github/workflows/static_checks.yml vendored Normal file
View File

@ -0,0 +1,31 @@
name: Static checks
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -qq dos2unix recode clang-format
pip3 install --user black pygments
- name: File formatting checks (file_format.sh)
run: |
bash ./misc/scripts/file_format.sh
- name: Style checks via clang-format (clang_format.sh)
run: |
bash ./misc/scripts/clang_format.sh
- name: Python style checks via black (black_format.sh)
run: |
bash ./misc/scripts/black_format.sh
- name: Documentation checks
run: |
doc/tools/makerst.py --dry-run doc/classes modules

View File

@ -19,16 +19,6 @@ cache:
matrix:
include:
- name: Static checks (clang-format) + Documentation checks
stage: build
env: STATIC_CHECKS=yes
os: linux
compiler: gcc
addons:
apt:
packages:
- clang-format-8
- name: Linux editor (debug, GCC 9, with Mono)
stage: build
env: PLATFORM=linuxbsd TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-mono-gcc-9 MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" EXTRA_ARGS="module_mono_enabled=yes mono_glue=no warnings=extra werror=yes"
@ -130,10 +120,6 @@ install:
./emsdk/emsdk install latest;
./emsdk/emsdk activate --no-embedded latest;
fi
- if [ "$STATIC_CHECKS" = "yes" ]; then
unset SCONS_CACHE;
pip3 install --user black pygments;
fi
before_script:
- if [ "$PLATFORM" = "android" ]; then
@ -142,15 +128,9 @@ before_script:
fi
script:
- if [ "$STATIC_CHECKS" = "yes" ]; then
sh ./misc/travis/clang-format.sh &&
sh ./misc/travis/black-format.sh &&
doc/tools/makerst.py --dry-run doc/classes modules;
else
scons -j2 CC=$CC CXX=$CXX platform=$PLATFORM tools=$TOOLS target=$TARGET $OPTIONS $EXTRA_ARGS &&
- scons -j2 CC=$CC CXX=$CXX platform=$PLATFORM tools=$TOOLS target=$TARGET $OPTIONS $EXTRA_ARGS &&
if [ "$TEST_PROJECT" = "yes" ]; then
git clone --depth 1 "https://github.com/godotengine/godot-tests.git";
sed -i "s:custom_template/release=\"\":custom_template/release=\"$(readlink -e bin/godot_server.linuxbsd.opt.tools.64)\":" godot-tests/tests/project_export/export_presets.cfg;
godot-tests/tests/project_export/test_project.sh "bin/godot_server.linuxbsd.opt.tools.64";
fi
fi

View File

@ -227,10 +227,10 @@
<description>
Returns [code]true[/code] if the array contains the given value.
[codeblock]
["inside", 7].has("inside") == true
["inside", 7].has("outside") == false
["inside", 7].has(7) == true
["inside", 7].has("7") == false
print(["inside", 7].has("inside")) # True
print(["inside", 7].has("outside")) # False
print(["inside", 7].has(7)) # True
print(["inside", 7].has("7")) # False
[/codeblock]
[b]Note:[/b] This is equivalent to using the [code]in[/code] operator as follows:
[codeblock]

View File

@ -44,7 +44,7 @@
</return>
<description>
Updates the collision information for the ray. Use this method to update the collision information immediately instead of waiting for the next [code]_physics_process[/code] call, for example if the ray or its parent has changed state.
[b]Note:[/b] [code]enabled == true[/code] is not required for this to work.
[b]Note:[/b] [member enabled] does not need to be [code]true[/code] for this to work.
</description>
</method>
<method name="get_collider" qualifiers="const">

View File

@ -45,7 +45,7 @@
<description>
Updates the collision information for the ray.
Use this method to update the collision information immediately instead of waiting for the next [code]_physics_process[/code] call, for example if the ray or its parent has changed state.
[b]Note:[/b] [code]enabled == true[/code] is not required for this to work.
[b]Note:[/b] [member enabled] does not need to be [code]true[/code] for this to work.
</description>
</method>
<method name="get_collider" qualifiers="const">

View File

@ -102,9 +102,9 @@ bool test_add_remove() {
a.connect_points(1, 3, true);
a.connect_points(1, 4, false);
ok = ok && (a.are_points_connected(2, 1) == true);
ok = ok && (a.are_points_connected(4, 1) == true);
ok = ok && (a.are_points_connected(2, 1, false) == true);
ok = ok && (a.are_points_connected(2, 1));
ok = ok && (a.are_points_connected(4, 1));
ok = ok && (a.are_points_connected(2, 1, false));
ok = ok && (a.are_points_connected(4, 1, false) == false);
a.disconnect_points(1, 2, true);
@ -179,7 +179,7 @@ bool test_add_remove() {
if (Math::rand() % 2 == 1) {
// Add a (possibly existing) directed edge and confirm connectivity
a.connect_points(u, v, false);
ok = ok && (a.are_points_connected(u, v, false) == true);
ok = ok && (a.are_points_connected(u, v, false));
} else {
// Remove a (possibly nonexistent) directed edge and confirm disconnectivity
a.disconnect_points(u, v, false);

35
misc/scripts/black_format.sh Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
# This script runs black on all Python files in the repo.
set -uo pipefail
# Apply black.
echo -e "Formatting Python files..."
PY_FILES=$(find \( -path "./.git" \
-o -path "./thirdparty" \
\) -prune \
-o \( -name "SConstruct" \
-o -name "SCsub" \
-o -name "*.py" \
\) -print)
black -l 120 $PY_FILES
git diff > patch.patch
FILESIZE="$(stat -c%s patch.patch)"
MAXSIZE=5
# If no patch has been generated all is OK, clean up, and exit.
if (( FILESIZE < MAXSIZE )); then
printf "Files in this commit comply with the black style rules.\n"
rm -f patch.patch
exit 0
fi
# A patch has been created, notify the user, clean up, and exit.
printf "\n*** The following differences were found between the code "
printf "and the formatting rules:\n\n"
cat patch.patch
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
rm -f patch.patch
exit 1

58
misc/scripts/clang_format.sh Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env bash
# This script runs clang-format and fixes copyright headers on all relevant files in the repo.
# This is the primary script responsible for fixing style violations.
set -uo pipefail
IFS=$'\n\t'
CLANG_FORMAT_FILE_EXTS=(".c" ".h" ".cpp" ".hpp" ".cc" ".hh" ".cxx" ".m" ".mm" ".inc" ".java" ".glsl")
# Loops through all text files tracked by Git.
git grep -zIl '' |
while IFS= read -rd '' f; do
# Exclude some files.
if [[ "$f" == "thirdparty"* ]]; then
continue
elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then
continue
fi
for extension in ${CLANG_FORMAT_FILE_EXTS[@]}; do
if [[ "$f" == *"$extension" ]]; then
# Run clang-format.
clang-format -i "$f"
# Fix copyright headers, but not all files get them.
if [[ "$f" == *"inc" ]]; then
continue 2
elif [[ "$f" == *"glsl" ]]; then
continue 2
elif [[ "$f" == *"theme_data.h" ]]; then
continue 2
elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/input/InputManager"* ]]; then
continue 2
fi
python misc/scripts/copyright_headers.py "$f"
continue 2
fi
done
done
git diff > patch.patch
FILESIZE="$(stat -c%s patch.patch)"
MAXSIZE=5
# If no patch has been generated all is OK, clean up, and exit.
if (( FILESIZE < MAXSIZE )); then
printf "Files in this commit comply with the clang-format style rules.\n"
rm -f patch.patch
exit 0
fi
# A patch has been created, notify the user, clean up, and exit.
printf "\n*** The following differences were found between the code "
printf "and the formatting rules:\n\n"
cat patch.patch
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
rm -f patch.patch
exit 1

View File

@ -1,6 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
header = """\
/*************************************************************************/
/* $filename */
@ -33,11 +35,7 @@ header = """\
/*************************************************************************/
"""
files = open("files", "r")
fname = files.readline()
while fname != "":
fname = sys.argv[1]
# Handle replacing $filename with actual filename and keep alignment
fsingle = fname.strip()
@ -95,8 +93,3 @@ while fname != "":
filewrite = open(fname.strip(), "w")
filewrite.write(text)
filewrite.close()
# Next file
fname = files.readline()
files.close()

59
misc/scripts/file_format.sh Executable file
View File

@ -0,0 +1,59 @@
#!/usr/bin/env bash
# This script ensures proper POSIX text file formatting and a few other things.
# This is supplementary to clang-black-format.sh, but should be run before it.
set -uo pipefail
IFS=$'\n\t'
# Loops through all text files tracked by Git.
git grep -zIl '' |
while IFS= read -rd '' f; do
# Exclude some types of files.
if [[ "$f" == *"csproj" ]]; then
continue
elif [[ "$f" == *"sln" ]]; then
continue
elif [[ "$f" == *"patch" ]]; then
continue
elif [[ "$f" == *"pot" ]]; then
continue
elif [[ "$f" == *"po" ]]; then
continue
elif [[ "$f" == "thirdparty"* ]]; then
continue
elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then
continue
fi
# Ensures that files are UTF-8 formatted.
recode UTF-8 "$f" 2> /dev/null
# Ensures that files have LF line endings.
dos2unix "$f" 2> /dev/null
# Ensures that files do not contain a BOM.
sed -i '1s/^\xEF\xBB\xBF//' "$f"
# Ensures that files end with newline characters.
tail -c1 < "$f" | read -r _ || echo >> "$f";
# Remove trailing space characters.
sed -z -i 's/\x20\x0A/\x0A/g' "$f"
# Remove the character sequence "== true" if it has a leading space.
sed -z -i 's/\x20== true//g' "$f"
done
git diff > patch.patch
FILESIZE="$(stat -c%s patch.patch)"
MAXSIZE=5
# If no patch has been generated all is OK, clean up, and exit.
if (( FILESIZE < MAXSIZE )); then
printf "Files in this commit comply with the formatting rules.\n"
rm -f patch.patch
exit 0
fi
# A patch has been created, notify the user, clean up, and exit.
printf "\n*** The following differences were found between the code "
printf "and the formatting rules:\n\n"
cat patch.patch
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
rm -f patch.patch
exit 1

View File

@ -1,78 +0,0 @@
#!/usr/bin/env bash
# Command line arguments
run_black=false
run_clang_format=false
run_fix_headers=false
usage="Invalid argument. Usage:\n$0 <option>\n\t--black|-b\n\t--clang-format|-c\n\t--headers|-h\n\t--all|-a"
if [ -z "$1" ]; then
echo -e $usage
exit 0
fi
while [ $# -gt 0 ]; do
case "$1" in
--black|-b)
run_black=true
;;
--clang-format|-c)
run_clang_format=true
;;
--headers|-h)
run_fix_headers=true
;;
--all|-a)
run_black=true
run_clang_format=true
run_fix_headers=true
;;
*)
echo -e $usage
exit 0
esac
shift
done
echo "Removing generated files, some have binary data and make clang-format freeze."
find -name "*.gen.*" -delete
# Apply black
if $run_black; then
echo -e "Formatting Python files..."
PY_FILES=$(find \( -path "./.git" \
-o -path "./thirdparty" \
\) -prune \
-o \( -name "SConstruct" \
-o -name "SCsub" \
-o -name "*.py" \
\) -print)
black -l 120 $PY_FILES
fi
# Apply clang-format
if $run_clang_format; then
# Sync list with pre-commit hook
FILE_EXTS=".c .h .cpp .hpp .cc .hh .cxx .m .mm .inc .java .glsl"
for extension in ${FILE_EXTS}; do
echo -e "Formatting ${extension} files..."
find \( -path "./.git" \
-o -path "./thirdparty" \
-o -path "./platform/android/java/lib/src/com/google" \
\) -prune \
-o -name "*${extension}" \
-exec clang-format -i {} \;
done
fi
# Add missing copyright headers
if $run_fix_headers; then
echo "Fixing copyright headers in Godot code files..."
find \( -path "./.git" -o -path "./thirdparty" \) -prune \
-o -regex '.*\.\(c\|h\|cpp\|hpp\|cc\|hh\|cxx\|m\|mm\|java\)' \
> tmp-files
cat tmp-files | grep -v ".git\|thirdparty\|theme_data.h\|platform/android/java/lib/src/com/google\|platform/android/java/lib/src/org/godotengine/godot/input/InputManager" > files
python misc/scripts/fix_headers.py
rm -f tmp-files files
fi

View File

@ -1,48 +0,0 @@
#!/bin/sh
BLACK=black
BLACK_OPTIONS="-l 120"
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
# Travis only clones the PR branch and uses its HEAD commit as detached HEAD,
# so it's problematic when we want an exact commit range for format checks.
# We fetch upstream to ensure that we have the proper references to resolve.
# Ideally we would use $TRAVIS_COMMIT_RANGE but it doesn't play well with PR
# updates, as it only includes changes since the previous state of the PR.
if [ -z "$(git remote | grep upstream)" ]; then
git remote add upstream https://github.com/godotengine/godot \
--no-tags -f -t $TRAVIS_BRANCH
fi
RANGE="upstream/$TRAVIS_BRANCH HEAD"
else
# Test only the last commit, since $TRAVIS_COMMIT_RANGE wouldn't support
# force pushes.
RANGE=HEAD
fi
FILES=$(git diff-tree --no-commit-id --name-only -r $RANGE | grep -v thirdparty/| grep -E "(SConstruct|SCsub|\.py)$")
echo "Checking files:\n$FILES"
# create a random filename to store our generated patch
prefix="static-check-black"
suffix="$(date +%s)"
patch="/tmp/$prefix-$suffix.patch"
for file in $FILES; do
"$BLACK" "$BLACK_OPTIONS" --diff "$file" | \
sed -e "1s|--- |--- a/|" -e "2s|+++ |+++ b/|" >> "$patch"
done
# if no patch has been generated all is ok, clean up the file stub and exit
if [ ! -s "$patch" ] ; then
printf "Files in this commit comply with the black formatting rules.\n"
rm -f "$patch"
exit 0
fi
# a patch has been created, notify the user and exit
printf "\n*** The following differences were found between the code to commit "
printf "and the black formatting rules:\n\n"
pygmentize -l diff "$patch"
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
exit 1

View File

@ -1,48 +0,0 @@
#!/bin/sh
CLANG_FORMAT=clang-format-8
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
# Travis only clones the PR branch and uses its HEAD commit as detached HEAD,
# so it's problematic when we want an exact commit range for format checks.
# We fetch upstream to ensure that we have the proper references to resolve.
# Ideally we would use $TRAVIS_COMMIT_RANGE but it doesn't play well with PR
# updates, as it only includes changes since the previous state of the PR.
if [ -z "$(git remote | grep upstream)" ]; then
git remote add upstream https://github.com/godotengine/godot \
--no-tags -f -t $TRAVIS_BRANCH
fi
RANGE="upstream/$TRAVIS_BRANCH HEAD"
else
# Test only the last commit, since $TRAVIS_COMMIT_RANGE wouldn't support
# force pushes.
RANGE=HEAD
fi
FILES=$(git diff-tree --no-commit-id --name-only -r $RANGE | grep -v thirdparty/ | grep -v platform/android/java/lib/src/com/ | grep -E "\.(c|h|cpp|hpp|cc|hh|cxx|m|mm|inc|java|glsl)$")
echo "Checking files:\n$FILES"
# create a random filename to store our generated patch
prefix="static-check-clang-format"
suffix="$(date +%s)"
patch="/tmp/$prefix-$suffix.patch"
for file in $FILES; do
"$CLANG_FORMAT" -style=file "$file" | \
diff -u "$file" - | \
sed -e "1s|--- |--- a/|" -e "2s|+++ -|+++ b/$file|" >> "$patch"
done
# if no patch has been generated all is ok, clean up the file stub and exit
if [ ! -s "$patch" ] ; then
printf "Files in this commit comply with the clang-format rules.\n"
rm -f "$patch"
exit 0
fi
# a patch has been created, notify the user and exit
printf "\n*** The following differences were found between the code to commit "
printf "and the clang-format rules:\n\n"
pygmentize -l diff "$patch"
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
exit 1

View File

@ -1963,7 +1963,7 @@ MonoObject *CSharpInstance::_internal_new_managed() {
bool die = _unreference_owner_unsafe();
// Not ok for the owner to die here. If there is a situation where this can happen, it will be considered a bug.
CRASH_COND(die == true);
CRASH_COND(die);
owner = nullptr;
@ -2298,7 +2298,7 @@ CSharpInstance::~CSharpInstance() {
// Unreference the owner here, before the new "instance binding" references it.
// Otherwise, the unsafe reference debug checks will incorrectly detect a bug.
bool die = _unreference_owner_unsafe();
CRASH_COND(die == true); // `owner_keep_alive` holds a reference, so it can't die
CRASH_COND(die); // `owner_keep_alive` holds a reference, so it can't die
void *data = owner->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index());
CRASH_COND(data == nullptr);
@ -3136,7 +3136,7 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg
bool die = instance->_unreference_owner_unsafe();
// Not ok for the owner to die here. If there is a situation where this can happen, it will be considered a bug.
CRASH_COND(die == true);
CRASH_COND(die);
p_owner->set_script_instance(nullptr);
r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;

View File

@ -320,7 +320,7 @@ void OS_OSX::run() {
}
joypad_osx->process_joypads();
if (Main::iteration() == true) {
if (Main::iteration()) {
quit = true;
}
} @catch (NSException *exception) {