Skip to content

Commit

Permalink
Add new analysis action
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
AndyScherzinger committed Oct 10, 2022
1 parent 2051588 commit 9fdc1c2
Show file tree
Hide file tree
Showing 11 changed files with 369 additions and 77 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "Analysis"

on:
pull_request:
branches: [ master, stable-* ]
push:
branches: [ master, stable-* ]

permissions:
pull-requests: write
contents: write

jobs:
analysis:
runs-on: ubuntu-latest
steps:
- name: Setup variables
id: get-vars
run: |
if [ -z "$GITHUB_HEAD_REF" ]; then
# push
echo "::set-output name=branch::$GITHUB_REF_NAME"
echo "::set-output name=pr::$GITHUB_RUN_ID"
echo "::set-output name=repo::${{ github.repository }}"
else
# pull request
echo "::set-output name=branch::$GITHUB_HEAD_REF"
echo "::set-output name=pr::${{ github.event.pull_request.number }}"
echo "::set-output name=repo::${{ github.event.pull_request.head.repo.full_name }}"
fi
- uses: actions/checkout@v3
with:
repository: ${{ steps.get-vars.outputs.repo }}
ref: ${{ steps.get-vars.outputs.branch }}
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: 11
- name: Install dependencies
run: |
python3 -m pip install defusedxml
- name: Run analysis wrapper
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p $HOME/.gradle
echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > $HOME/.gradle/gradle.properties
scripts/analysis/analysis-wrapper.sh ${{ steps.get-vars.outputs.branch }} ${{ secrets.LOG_USERNAME }} ${{ secrets.LOG_PASSWORD }} $GITHUB_RUN_NUMBER ${{ steps.get-vars.outputs.pr }}
35 changes: 32 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Built application files
*.apk
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex
Expand All @@ -10,25 +11,36 @@

# Generated files
bin/
build/
*.iml
gen/
out/
target/

# Local configuration file (sdk path, etc)
# Local configuration files (sdk path, etc)
local.properties
tests/local.properties

# Mac .DS_Store files
.DS_Store

# Proguard folder generated by Eclipse
proguard/
proguard-project.txt
tests/proguard-project.txt

# Log Files
*.log

# Android Studio and Gradle specific entries
*.iml
.gradle
.idea/*
!.idea/codeStyles/
.idea
build
/gradle.properties
.attach_pid*
fastlane/Fastfile
*.hprof
captures/
.navigation/
app/gplay/
Expand All @@ -55,4 +67,21 @@ freeline/
freeline_project_description.json
.DS_Store

# fastlane specific
**/fastlane/report.xml

# deliver temporary files
**/fastlane/Preview.html

# snapshot generated screenshots
**/fastlane/screenshots

# scan temporary files
**/fastlane/test_output
/fastlane/vendor/
/.bundle/
/fastlane/.bundle

# python
**/__pycache__/

9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,13 @@ android {
excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")

reports {
xml.enabled = false
xml {
required = true
}
html {
enabled = true
destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
required = true
outputLocation = file("$project.buildDir/reports/spotbugs/spotbugs.html")
stylesheet = 'fancy.xsl'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
classpath "org.jetbrains.kotlin:kotlin-serialization:${kotlinVersion}"
classpath 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.5'
classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.11'
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.21.0"
classpath "org.jlleitschuh.gradle:ktlint-gradle:11.0.0"

Expand Down
105 changes: 60 additions & 45 deletions scripts/analysis/analysis-wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,66 +1,59 @@
#!/usr/bin/env bash

#1: GIT_USERNAME
#2: GIT_TOKEN
#3: BRANCH
#4: LOG_USERNAME
#5: LOG_PASSWORD
#6: DRONE_BUILD_NUMBER
#7: PULL_REQUEST_NUMBER
BRANCH=$1
LOG_USERNAME=$2
LOG_PASSWORD=$3
BUILD_NUMBER=$4
PR_NUMBER=$5


stableBranch="master"
repository="talk"

stableBranch=$(git branch | grep '*' | cut -d' ' -f2)
if [[ $stableBranch = \stable-* ]] ; then
stableBranch=$3
else
stableBranch="master"
fi

ruby scripts/analysis/lint-up.rb $1 $2 $3
ruby scripts/analysis/lint-up.rb
lintValue=$?

ruby scripts/analysis/findbugs-up.rb $1 $2 $3
findbugsValue=$?
curl "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.xml" -o "/tmp/$stableBranch.xml"
ruby scripts/analysis/spotbugs-up.rb "$stableBranch"
spotbugsValue=$?

# exit codes:
# 0: count was reduced
# 1: count was increased
# 2: count stayed the same

echo "Branch: $3"
source scripts/lib.sh

if [ $3 = $stableBranch ]; then
echo "New findbugs result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html"
curl -k -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.html --upload-file app/build/reports/spotbugs/spotbugs.html
echo "Branch: $BRANCH"

summary=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" app/build/reports/spotbugs/spotbugs.html | head -n-1 | sed s'/<\/a>//'g | sed s'/<a.*>//'g | sed s"/Summary/SpotBugs ($stableBranch)/" | tr "\"" "\'" | tr -d "\r\n")
curl -k -u $4:$5 -X PUT -d "$summary" https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/findbugs-summary-$stableBranch.html
if [ "$BRANCH" = $stableBranch ]; then
echo "New spotbugs result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html"
curl -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.html --upload-file app/build/reports/spotbugs/spotbugs.html
curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.xml" --upload-file app/build/reports/spotbugs/gplayDebug.xml

if [ $lintValue -ne 1 ]; then
echo "New lint result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-lint/$stableBranch.html"
curl -k -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$stableBranch.html --upload-file app/build/reports/lint/lint.html
curl -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$stableBranch.html --upload-file app/build/reports/lint/lint.html
exit 0
fi
else
if [ -e $6 ]; then
if [ -e "${BUILD_NUMBER}" ]; then
6=$stableBranch"-"$(date +%F)
fi
echo "New lint results at https://www.kaminsky.me/nc-dev/$repository-lint/$6.html"
curl -k -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/$6.html --upload-file app/build/reports/lint/lint.html
echo "New lint results at https://www.kaminsky.me/nc-dev/$repository-lint/${BUILD_NUMBER}.html"
curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-lint/${BUILD_NUMBER}.html" --upload-file app/build/reports/lint/lint.html

echo "New findbugs results at https://www.kaminsky.me/nc-dev/$repository-findbugs/$6.html"
curl -k -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$6.html --upload-file app/build/reports/spotbugs/spotbugs.html
echo "New spotbugs results at https://www.kaminsky.me/nc-dev/$repository-findbugs/${BUILD_NUMBER}.html"
curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/${BUILD_NUMBER}.html" --upload-file app/build/reports/spotbugs/spotbugs.html

# delete all old comments
oldComments=$(curl -k 2>/dev/null -u $1:$2 -X GET https://api.github.com/repos/nextcloud/talk-android/issues/$7/comments | jq '.[] | (.id |tostring) + "|" + (.user.login | test("nextcloud-android-bot") | tostring) ' | grep true | tr -d "\"" | cut -f1 -d"|")
# delete all old comments, starting with Codacy
oldComments=$(curl_gh -X GET "https://api.github.com/repos/nextcloud/$repository/issues/${PR_NUMBER}/comments" | jq '.[] | select((.user.login | contains("github-actions")) and (.body | test("<h1>Codacy.*"))) | .id')

echo $oldComments | while read comment ; do
curl -k 2>/dev/null -u $1:$2 -X DELETE https://api.github.com/repos/nextcloud/talk-android/issues/comments/$comment
echo "$oldComments" | while read -r comment ; do
curl_gh -X DELETE "https://api.github.com/repos/nextcloud/$repository-android/issues/comments/$comment"
done

# lint and findbugs file must exist
# lint and spotbugs file must exist
if [ ! -s app/build/reports/lint/lint.html ] ; then
echo "lint.html file is missing!"
exit 1
Expand All @@ -84,7 +77,7 @@ else
lintWarningNew=0
fi

lintResultOld=$(curl -k 2>/dev/null https://raw.githubusercontent.com/nextcloud/talk-android/$stableBranch/scripts/analysis/lint-results.txt)
lintResultOld=$(curl 2>/dev/null "https://raw.githubusercontent.com/nextcloud/$repository-android/$stableBranch/scripts/analysis/lint-results.txt")
lintErrorOld=$(echo $lintResultOld | grep "[0-9]* error" -o | cut -f1 -d" ")
if ( [ -z $lintErrorOld ] ); then
lintErrorOld=0
Expand All @@ -95,37 +88,59 @@ else
lintWarningOld=0
fi

lintResult="<h1>Lint</h1><table width='500' cellpadding='5' cellspacing='2'><tr class='tablerow0'><td>Type</td><td><a href='https://www.kaminsky.me/nc-dev/"$repository"-lint/"$stableBranch".html'>$stableBranch</a></td><td><a href='https://www.kaminsky.me/nc-dev/"$repository"-lint/"$6".html'>PR</a></td></tr><tr class='tablerow1'><td>Warnings</td><td>"$lintWarningOld"</td><td>"$lintWarningNew"</td></tr><tr class='tablerow0'><td>Errors</td><td>"$lintErrorOld"</td><td>"$lintErrorNew"</td></tr></table>"
findbugsResultNew=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" app/build/reports/spotbugs/spotbugs.html |head -n-1 | sed s'/<\/a>//'g | sed s'/<a.*>//'g | sed s"#Summary#<a href=\"https://www.kaminsky.me/nc-dev/$repository-findbugs/$6.html\">SpotBugs</a> (new)#" | tr "\"" "\'" | tr -d "\n")
findbugsResultOld=$(curl -k 2>/dev/null https://www.kaminsky.me/nc-dev/$repository-findbugs/findbugs-summary-$stableBranch.html | tr "\"" "\'" | tr -d "\r\n" | sed s"#SpotBugs#<a href=\"https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html\">SpotBugs</a>#" | tr "\"" "\'" | tr -d "\n")
if [ $stableBranch = "master" ] ; then
codacyValue=$(curl 2>/dev/null https://app.codacy.com/gh/nextcloud/$repository-android/dashboard | grep "total issues" | cut -d">" -f3 | cut -d"<" -f1)
codacyResult="<h1>Codacy</h1>$codacyValue"
else
codacyResult=""
fi

lintResult="<h1>Lint</h1><table width='500' cellpadding='5' cellspacing='2'><tr class='tablerow0'><td>Type</td><td><a href='https://www.kaminsky.me/nc-dev/$repository-lint/$stableBranch.html'>$stableBranch</a></td><td><a href='https://www.kaminsky.me/nc-dev/$repository-lint/${BUILD_NUMBER}.html'>PR</a></td></tr><tr class='tablerow1'><td>Warnings</td><td>$lintWarningOld</td><td>$lintWarningNew</td></tr><tr class='tablerow0'><td>Errors</td><td>$lintErrorOld</td><td>$lintErrorNew</td></tr></table>"

spotbugsResult="<h1>SpotBugs</h1>$(scripts/analysis/spotbugsComparison.py "/tmp/$stableBranch.xml" app/build/reports/spotbugs/gplayDebug.xml --link-new "https://www.kaminsky.me/nc-dev/$repository-findbugs/${BUILD_NUMBER}.html" --link-base "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html")"

if ( [ $lintValue -eq 1 ] ) ; then
lintMessage="<h1>Lint increased!</h1>"
fi

if ( [ $findbugsValue -eq 1 ] ) ; then
findbugsMessage="<h1>SpotBugs increased!</h1>"
if ( [ $spotbugsValue -eq 1 ] ) ; then
spotbugsMessage="<h1>SpotBugs increased!</h1>"
fi

# check gplay limitation: all changelog files must only have 500 chars
gplayLimitation=$(scripts/checkGplayLimitation.sh)

if [ ! -z "$gplayLimitation" ]; then
gplayLimitation="<h1>Following files are beyond 500 char limit:</h1><br><br>"$gplayLimitation
fi

# check for NotNull
if [[ $(grep org.jetbrains.annotations src/main/* -ir -c) -gt 0 ]] ; then
if [[ $(grep org.jetbrains.annotations app/src/main/* -irl | wc -l) -gt 0 ]] ; then
notNull="org.jetbrains.annotations.NotNull is used. Please use androidx.annotation.NonNull instead.<br><br>"
fi

curl -k -u $1:$2 -X POST https://api.github.com/repos/nextcloud/talk-android/issues/$7/comments -d "{ \"body\" : \"$lintResult $findbugsResultNew $findbugsResultOld $lintMessage $findbugsMessage $notNull\" }"
payload="{ \"body\" : \"$codacyResult $lintResult $spotbugsResult $checkLibraryMessage $lintMessage $spotbugsMessage $gplayLimitation $notNull\" }"
curl_gh -X POST "https://api.github.com/repos/nextcloud/$repository-android/issues/${PR_NUMBER}/comments" -d "$payload"

if [ ! -z "$gplayLimitation" ]; then
exit 1
fi

if [ $checkLibrary -eq 1 ]; then
exit 1
fi

if [ ! $lintValue -eq 2 ]; then
exit $lintValue
fi

if [[ -n $notNull ]]; then
if [ -n "$notNull" ]; then
exit 1
fi

if [ $findbugsValue -eq 2 ]; then
if [ $spotbugsValue -eq 2 ]; then
exit 0
else
exit $findbugsValue
exit $spotbugsValue
fi
fi
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
begin
gem "xml-simple"
rescue LoadError
system("gem install xml-simple")
system("gem install --user-install xml-simple")
Gem.clear_paths
end

Expand Down
Loading

0 comments on commit 9fdc1c2

Please sign in to comment.