Merge pull request #1325 from colobot/dev-gh-actions-lint

Send colobot-lint results to GitHub using annotations
1164-fix
krzys_h 2020-07-09 20:14:05 +02:00 committed by GitHub
commit 1c8c01ad96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 153 additions and 110 deletions

View File

@ -18,15 +18,15 @@ jobs:
fail-fast: false fail-fast: false
steps: steps:
- name: Install Colobot dependencies - name: Install Colobot dependencies
run: sudo apt-get install -y --no-install-recommends build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsndfile1-dev libvorbis-dev libogg-dev libpng-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools librsvg2-bin xmlstarlet run: sudo apt-get update && sudo apt-get install -y --no-install-recommends build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsndfile1-dev libvorbis-dev libogg-dev libpng-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools librsvg2-bin xmlstarlet
if: matrix.container == '' if: matrix.container == ''
- uses: actions/checkout@v1 - uses: actions/checkout@v2
- name: Create build directory - name: Create build directory
run: cmake -E make_directory build run: cmake -E make_directory build
- name: Run CMake (for Windows using MXE) - name: Run CMake (for Windows using MXE)
working-directory: build working-directory: build
# FIXME: without -lsetupapi linking sdl2 fails # FIXME: without -lsetupapi linking sdl2 fails
run: /opt/mxe/usr/bin/i686-w64-mingw32.static-cmake -DCMAKE_CXX_STANDARD_LIBRARIES="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -lsetupapi" -DCMAKE_INSTALL_PREFIX=/install -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=0 .. run: /opt/mxe/usr/bin/i686-w64-mingw32.static-cmake -DCMAKE_CXX_STANDARD_LIBRARIES="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -lsetupapi" -DCMAKE_INSTALL_PREFIX=/install -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=0 -DMXE_USE_CCACHE=0 ..
if: matrix.target_os == 'windows' if: matrix.target_os == 'windows'
- name: Run CMake (for Linux) - name: Run CMake (for Linux)
working-directory: build working-directory: build
@ -87,8 +87,8 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Install Colobot dependencies - name: Install Colobot dependencies
run: sudo apt-get install -y --no-install-recommends build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsndfile1-dev libvorbis-dev libogg-dev libpng-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools librsvg2-bin xmlstarlet doxygen graphviz run: sudo apt-get update && sudo apt-get install -y --no-install-recommends build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsndfile1-dev libvorbis-dev libogg-dev libpng-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools librsvg2-bin xmlstarlet doxygen graphviz
- uses: actions/checkout@v1 - uses: actions/checkout@v2
- name: Create build directory - name: Create build directory
run: cmake -E make_directory build run: cmake -E make_directory build
- name: Run CMake - name: Run CMake

View File

@ -12,7 +12,7 @@ jobs:
CLANG_PREFIX: /usr/lib/llvm-3.6 CLANG_PREFIX: /usr/lib/llvm-3.6
steps: steps:
- name: Download Colobot dependencies - name: Download Colobot dependencies
run: sudo apt-get install -y --no-install-recommends build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsndfile1-dev libvorbis-dev libogg-dev libpng-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools librsvg2-bin xmlstarlet run: sudo apt-get update && sudo apt-get install -y --no-install-recommends build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsndfile1-dev libvorbis-dev libogg-dev libpng-dev libglew-dev libopenal-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev libphysfs-dev gettext git po4a vorbis-tools librsvg2-bin xmlstarlet
# TODO: migrate colobot-lint to GitHub Actions # TODO: migrate colobot-lint to GitHub Actions
- name: Download colobot-lint - name: Download colobot-lint
run: | run: |
@ -20,9 +20,19 @@ jobs:
mkdir -p /tmp/colobot-lint mkdir -p /tmp/colobot-lint
cd /tmp/colobot-lint cd /tmp/colobot-lint
wget -O colobot-lint.zip "https://compiled.colobot.info/job/colobot/job/colobot-lint/job/dev/lastSuccessfulBuild/artifact/*zip*/archive.zip" wget -O colobot-lint.zip "https://compiled.colobot.info/job/colobot/job/colobot-lint/job/dev/lastSuccessfulBuild/artifact/*zip*/archive.zip"
unzip colobot-lint.zip
chmod +x archive/Tools/count_errors.py # TODO: ??? # Unzip the archive
- uses: actions/checkout@v1 unzip ./colobot-lint.zip
# Workaround for Clang not finding system headers
mkdir ./bin
mv ./archive/build/colobot-lint ./bin/
chmod +x ./bin/colobot-lint
ln -s ${CLANG_PREFIX}/lib ./lib
# Unpack HtmlReport
tar -zxf ./archive/build/html_report.tar.gz
# Clean up
rm -r ./archive
- uses: actions/checkout@v2
- name: Create build directory - name: Create build directory
run: cmake -E make_directory build run: cmake -E make_directory build
- name: Run CMake - name: Run CMake
@ -32,22 +42,12 @@ jobs:
shell: bash shell: bash
run: | run: |
set -e +x set -e +x
# Run colobot-lint WORKSPACE="$GITHUB_WORKSPACE"
WORKSPACE=$PWD
COLOBOT_DIR="$WORKSPACE" COLOBOT_DIR="$WORKSPACE"
COLOBOT_BUILD_DIR="$WORKSPACE/build" COLOBOT_BUILD_DIR="$WORKSPACE/build"
COLOBOT_LINT_BUILD_DIR="/tmp/colobot-lint/archive/build"
COLOBOT_LINT_REPORT_FILE="$WORKSPACE/build/colobot_lint_report.xml" COLOBOT_LINT_REPORT_FILE="$WORKSPACE/build/colobot_lint_report.xml"
# CLANG_PREFIX="/usr/lib/llvm-3.6" # Set in top-level environment block
cd "$COLOBOT_LINT_BUILD_DIR" cd "/tmp/colobot-lint"
chmod +x ./colobot-lint
# Workaround for Clang not finding system headers
rm -rf bin/
mkdir -p bin
mv ./colobot-lint ./bin/
rm -f ./lib
ln -s ${CLANG_PREFIX}/lib ./lib
echo "Running colobot-lint"
find "$WORKSPACE" \( -wholename "$COLOBOT_DIR/src/*.cpp" \ find "$WORKSPACE" \( -wholename "$COLOBOT_DIR/src/*.cpp" \
-or -wholename "$COLOBOT_DIR/test/unit/*.cpp" \ -or -wholename "$COLOBOT_DIR/test/unit/*.cpp" \
-or -wholename "$COLOBOT_BUILD_DIR/fake_header_sources/src/*.cpp" \ -or -wholename "$COLOBOT_BUILD_DIR/fake_header_sources/src/*.cpp" \
@ -67,96 +67,139 @@ jobs:
path: build/colobot_lint_report.xml path: build/colobot_lint_report.xml
- name: Generate HTML report - name: Generate HTML report
shell: bash shell: bash
run: | run: /tmp/colobot-lint/HtmlReport/generate.py --xml-report "build/colobot_lint_report.xml" --output-dir "build/html_report"
set -e +x
# Generate HTML report
WORKSPACE=$PWD
COLOBOT_LINT_BUILD_DIR="/tmp/colobot-lint/archive/build"
COLBOT_LINT_REPORT_FILE="$WORKSPACE/build/colobot_lint_report.xml"
HTML_REPORT_DIR="$WORKSPACE/build/html_report"
echo "Generating HTML report"
cd "$COLOBOT_LINT_BUILD_DIR"
rm -rf HtmlReport/
tar -zxf html_report.tar.gz
HtmlReport/generate.py --xml-report "$COLBOT_LINT_REPORT_FILE" --output-dir "$HTML_REPORT_DIR"
- name: Upload results (HTML) - name: Upload results (HTML)
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: HTML results name: HTML results
path: build/html_report path: build/html_report
- name: Update stable/unstable build status - run: pip install requests
shell: bash - name: Send linter results to GitHub
shell: python
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
set -e +x import os
# Update stable/unstable build status import sys
ret=0 import requests
WORKSPACE=$PWD import xml.etree.ElementTree as ET
COLOBOT_LINT_REPORT_FILE="$WORKSPACE/build/colobot_lint_report.xml"
COLOBOT_LINT_DIR="/tmp/colobot-lint/archive" OVERALL_STABLE_RULES=[
OVERALL_STABLE_RULES=( "class naming",
"class naming" "code block placement",
"code block placement" "compile error",
"compile error" # "compile warning",
# "compile warning" # "enum naming",
# "enum naming" # "function naming",
# "function naming" "header file not self-contained",
"header file not self-contained" # "implicit bool cast",
# "implicit bool cast" # "include style",
# "include style" # "inconsistent declaration parameter name",
# "inconsistent declaration parameter name" "license header",
"license header" # "naked delete",
# "naked delete" # "naked new",
# "naked new" # "old style function",
# "old style function" "old-style null pointer",
"old-style null pointer" # "possible forward declaration",
# "possible forward declaration" "undefined function",
"undefined function" # "uninitialized field",
# "uninitialized field" # "uninitialized local variable",
# "uninitialized local variable" # "unused forward declaration",
# "unused forward declaration" # "variable naming",
# "variable naming" "whitespace",
"whitespace" ]
)
echo "Checking rule stability (overall)" STABLE_RULES_WITHOUT_CBOT=[
for ((i = 0; i < ${#OVERALL_STABLE_RULES[@]}; i++)); do "class naming",
rule="${OVERALL_STABLE_RULES[$i]}" "code block placement",
count="$("$COLOBOT_LINT_DIR/Tools/count_errors.py" --rule-filter="$rule" --xml-report-file "$COLOBOT_LINT_REPORT_FILE")" "compile error",
if [ "$count" != "0" ]; then "compile warning",
echo "UNSTABLE RULE: $rule ($count occurences)" # "enum naming",
ret=1 # "function naming",
fi "header file not self-contained",
done # "implicit bool cast",
STABLE_RULES_WITHOUT_CBOT=( "include style",
"class naming" "inconsistent declaration parameter name",
"code block placement" "license header",
"compile error" "naked delete",
"compile warning" "naked new",
# "enum naming" # "old style function",
# "function naming" "old-style null pointer",
"header file not self-contained" # "possible forward declaration",
# "implicit bool cast" "undefined function",
"include style" "uninitialized field",
"inconsistent declaration parameter name" # "uninitialized local variable",
"license header" "unused forward declaration",
"naked delete" # "variable naming",
"naked new" "whitespace",
# "old style function" ]
"old-style null pointer"
# "possible forward declaration" # None of the available actions seem to do what I want, they all do stupid things like adding another check... let's just do it manually
"undefined function" # GitHub also doesn't seem to provide you with the check suite or check run ID, so we have to get it from the action ID via the API
"uninitialized field" s = requests.Session()
# "uninitialized local variable" s.headers.update({
"unused forward declaration" 'Authorization': 'token ' + os.environ['GITHUB_TOKEN'],
# "variable naming" 'Accept': 'application/vnd.github.antiope-preview+json' # Annotations are still technically a preview feature of the API
"whitespace" })
) action_run = s.get(os.environ['GITHUB_API_URL'] + "/repos/" + os.environ['GITHUB_REPOSITORY'] + "/actions/runs/" + os.environ['GITHUB_RUN_ID']).json()
echo "Checking rule stability (without CBOT)" check_suite = s.get(action_run['check_suite_url']).json()
for ((i = 0; i < ${#STABLE_RULES_WITHOUT_CBOT[@]}; i++)); do check_suite_runs = s.get(check_suite['check_runs_url']).json()
rule="${STABLE_RULES_WITHOUT_CBOT[$i]}" check_run = check_suite_runs['check_runs'][0] # NOTE: This assumes that the 'lint' job is the first one in the workflow. You could find it by name if you really wanted.
count="$("$COLOBOT_LINT_DIR/Tools/count_errors.py" --rule-filter="$rule" --file-filter="-.*CBot.*" --xml-report-file "$COLOBOT_LINT_REPORT_FILE")"
if [ "$count" != "0" ]; then def we_care_about(file_name, type):
echo "UNSTABLE RULE: $rule (without CBOT, $count occurences)" if 'CBot' in file_name:
ret=1 return type in OVERALL_STABLE_RULES
fi else:
done return type in STABLE_RULES_WITHOUT_CBOT
exit $ret
results = ET.parse('build/colobot_lint_report.xml')
annotations = []
for error in results.find('errors').findall('error'):
location = error.find('location')
file_name = os.path.relpath(location.get('file'), os.environ['GITHUB_WORKSPACE'])
line_num = int(location.get('line'))
type = error.get('id')
severity = error.get('severity')
msg = error.get('msg')
gh_severity = 'warning'
if severity == 'error':
gh_severity = 'failure'
elif severity == 'information':
gh_severity = 'notice'
if not we_care_about(file_name, type):
# don't send the unstable rules to github at all as there are way too many of them and it would overload the API rate limit
continue
print('{}:{}: [{}] {}'.format(file_name, line_num, type, msg))
annotations.append({
'path': file_name,
'start_line': line_num,
'end_line': line_num,
'annotation_level': gh_severity,
'title': type,
'message': msg
})
summary = 'colobot-lint found {} issues'.format(len(annotations))
all_ok = len(annotations) == 0
# Annotations have to be sent in batches of 50
first = True
while first or len(annotations) > 0:
first = False
to_send = annotations[:50]
annotations = annotations[50:]
data = {
'output': {
'title': summary,
'summary': summary,
'annotations': to_send
}
}
r = s.patch(check_run['url'], json=data)
r.raise_for_status()
sys.exit(0 if all_ok else 1)

2
Jenkinsfile vendored
View File

@ -31,7 +31,7 @@ pipeline {
/opt/mxe/usr/bin/i686-w64-mingw32.static-cmake \ /opt/mxe/usr/bin/i686-w64-mingw32.static-cmake \
-DCMAKE_CXX_STANDARD_LIBRARIES="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -lsetupapi" \ -DCMAKE_CXX_STANDARD_LIBRARIES="-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -lsetupapi" \
-DCMAKE_INSTALL_PREFIX=/install \ -DCMAKE_INSTALL_PREFIX=/install \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=0 ../.. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=0 -DMXE_USE_CCACHE=0 ../..
make make
rm -rf install rm -rf install
DESTDIR=. make install DESTDIR=. make install