diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 44e868225..86598985a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,6 +46,8 @@ jobs: checks: runs-on: ubuntu-20.04 needs: preBuild + outputs: + warnings: ${{ steps.cppcheck.outputs.warnings }} steps: - name: Checkout repository @@ -53,17 +55,21 @@ jobs: with: submodules: true - name: Run cppcheck + id: cppcheck run: | sudo apt install cppcheck + sudo cpan Path::Class cppcheck --template=gcc --inline-suppr --std=c++14 --enable=style,unusedFunction -i externals \ --suppressions-list=cppcheck.supp --library=qt.cfg --library=posix.cfg . | tee error.log - ls -l error.log + perl scripts/warnings.pl error.log buildLinux: runs-on: ubuntu-16.04 needs: preBuild env: BITROCK_BUILDER: ~/installbuilder/bin/builder + outputs: + warnings: ${{ steps.warnings.outputs.warnings }} steps: - name: Install Qt @@ -80,6 +86,7 @@ jobs: run: | sudo apt install doxygen graphviz libglu1-mesa-dev libopus-dev libsodium-dev libpulse-dev libdbus-1-dev libevent-dev pip3 install tee + sudo cpan Path::Class - name: Checkout repository uses: actions/checkout@v2 with: @@ -99,12 +106,14 @@ jobs: if: ${{ ! (env.do_symbols == 'true' && env.do_vatsim_key == 'true') }} run: | python3 -u scripts/build.py -w 64 -t gcc -d -j2 -e $eol_months -q "SWIFT_CONFIG_JSON+=$vatsim_key_file" - ls -l error.log - name: Build swift (with symbols) if: ${{ env.do_symbols == 'true' && env.do_vatsim_key == 'true' }} run: | python3 -u scripts/build.py -w 64 -t gcc -d -j2 -e $eol_months -q "SWIFT_CONFIG_JSON+=$vatsim_key_file" --upload - ls -l error.log + - name: Check warnings + id: warnings + run: | + perl scripts/warnings.pl error.log - name: Upload installer uses: actions/upload-artifact@v2 with: @@ -127,6 +136,8 @@ jobs: needs: preBuild env: BITROCK_BUILDER: "$(USERPROFILE)/installbuilder/bin/builder-cli.exe" + outputs: + warnings: ${{ steps.warnings.outputs.warnings }} steps: - name: Install Qt @@ -162,12 +173,14 @@ jobs: if: ${{ ! (env.do_symbols == 'true' && env.do_vatsim_key == 'true') }} run: | python.exe -u scripts\build.py -w 64 -t msvc -d -e $env:eol_months -q "SWIFT_CONFIG_JSON+=$env:vatsim_key_file" - dir error.log - name: Build swift (with symbols) if: ${{ env.do_symbols == 'true' && env.do_vatsim_key == 'true' }} run: | python.exe -u scripts\build.py -w 64 -t msvc -d -e $env:eol_months -q "SWIFT_CONFIG_JSON+=$env:vatsim_key_file" --upload - dir error.log + - name: Check warnings + id: warnings + run: | + perl scripts/warnings.pl error.log - name: Upload installer uses: actions/upload-artifact@v2 with: @@ -190,6 +203,8 @@ jobs: needs: preBuild env: BITROCK_BUILDER: "$(USERPROFILE)/installbuilder/bin/builder-cli.exe" + outputs: + warnings: ${{ steps.warnings.outputs.warnings }} steps: - name: Install Qt @@ -225,12 +240,14 @@ jobs: if: ${{ ! (env.do_symbols == 'true' && env.do_vatsim_key == 'true') }} run: | python.exe -u scripts\build.py -w 32 -t msvc -d -e $env:eol_months -q "SWIFT_CONFIG_JSON+=$env:vatsim_key_file" - dir error.log - name: Build swift (with symbols) if: ${{ env.do_symbols == 'true' && env.do_vatsim_key == 'true' }} run: | python.exe -u scripts\build.py -w 32 -t msvc -d -e $env:eol_months -q "SWIFT_CONFIG_JSON+=$env:vatsim_key_file" --upload - dir error.log + - name: Check warnings + id: warnings + run: | + perl scripts/warnings.pl error.log - name: Upload installer uses: actions/upload-artifact@v2 with: @@ -253,6 +270,8 @@ jobs: needs: preBuild env: BITROCK_BUILDER: /Applications/installbuilder/bin/Builder.app/Contents/MacOS/installbuilder.sh + outputs: + warnings: ${{ steps.warnings.outputs.warnings }} steps: - name: Install Qt @@ -274,6 +293,7 @@ jobs: run: | pip3 install requests pip3 install tee + cpan Path::Class - name: Checkout repository uses: actions/checkout@v2 with: @@ -293,12 +313,14 @@ jobs: if: ${{ ! (env.do_symbols == 'true' && env.do_vatsim_key == 'true') }} run: | python3 -u scripts/build.py -w 64 -t clang -d -j2 -e $eol_months -q "SWIFT_CONFIG_JSON+=$vatsim_key_file" - ls -l error.log - name: Build swift (with symbols) if: ${{ env.do_symbols == 'true' && env.do_vatsim_key == 'true' }} run: | python3 -u scripts/build.py -w 64 -t clang -d -j2 -e $eol_months -q "SWIFT_CONFIG_JSON+=$vatsim_key_file" --upload - ls -l error.log + - name: Check warnings + id: warnings + run: | + perl scripts/warnings.pl error.log - name: Upload installer uses: actions/upload-artifact@v2 with: @@ -351,11 +373,13 @@ jobs: - name: Prepare Discord message run: | result=SUCCESS - echo ${{ join(needs.*.result, ' ') }} | grep -q cancel && result=CANCELLED + expr ${{ join(needs.*.outputs.warnings, ' + ') }} && result=WARNING echo ${{ join(needs.*.result, ' ') }} | grep -q fail && result=FAILED + echo ${{ join(needs.*.result, ' ') }} | grep -q cancel && result=CANCELLED [[ $result = SUCCESS ]] && emoji=white_check_mark - [[ $result = CANCELLED ]] && emoji=grey_question + [[ $result = WARNING ]] && emoji=warning [[ $result = FAILED ]] && emoji=x + [[ $result = CANCELLED ]] && emoji=grey_question echo "::set-env name=result::$result" echo "::set-env name=emoji::$emoji" - name: Send Discord message diff --git a/scripts/warnings.pl b/scripts/warnings.pl new file mode 100644 index 000000000..d1adb0b41 --- /dev/null +++ b/scripts/warnings.pl @@ -0,0 +1,74 @@ +#!/usr/bin/perl +# +# Convert C++ compiler warnings into Github Actions workflow commands +# +# Copyright (C) 2020 swift Project Community / contributors +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +use strict; +use warnings; +use Path::Class; + +my %cmds; +while (<<>>) +{ + chomp; + my %result = extractWarning($_); + next if not %result; + $result{file} = toRelativePath($result{file})->as_foreign('Unix'); + if (exists $result{line}) { + ++$cmds{"::warning file=$result{file},line=$result{line}::$result{msg}"}; + } else { + ++$cmds{"::warning file=$result{file}::$result{msg}"}; + } +} +my @cmds = sort keys %cmds; +my $count = scalar @cmds; +print "$_\n" for @cmds; +print "::set-output name=warnings::$count\n"; + +sub extractWarning +{ + my $line = shift; + my %result = extractGccWarning($line); + return %result if %result; + return extractMsvcWarning($line); +} + +sub extractGccWarning +{ + my $line = shift; + $line =~ m(^\s*(?.*?): warning: (?.*)$) or return (); + my ($loc, $msg) = @+{ qw(loc msg) }; + $loc =~ m(^(?.*?):(?[0-9:]+)$) or return (file => $loc, msg => $msg); + my ($file, $loc) = ($+{file}, split ':', $+{loc}); + return (file => $file, line => $loc, msg => $msg); +} + +sub extractMsvcWarning +{ + my $line = shift; + $line =~ m(^\s*(?.*?): warning (?[A-Z]+[0-9]+: .*)$) or return (); + my ($loc, $msg) = @+{ qw(loc msg) }; + $loc =~ m(^(?.*)\((?[0-9,]+)\)$) or return (file => $loc, msg => $msg); + my ($file, $loc) = ($+{file}, split ',', $+{loc}); + return (file => $file, line => $loc, msg => $msg); +} + +sub toRelativePath +{ + my $path = shift; + my $file = file($path); + return $file if $file->is_relative; + return $file->relative if dir()->absolute()->subsumes($file); + return $file; +}