Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Linter Github Actions Reporting #4864

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- name: Run code quality check suite
run: ./tools/check/check_code_quality.sh

# ktlint for all the modules
ktlint:
name: Kotlin Linter
runs-on: ubuntu-latest
Expand All @@ -23,12 +24,55 @@ jobs:
run: |
./gradlew ktlintCheck --continue
- name: Upload reports
if: always()
uses: actions/upload-artifact@v2
with:
name: ktlinting-report
path: vector/build/reports/ktlint/*.*
path: |
*/build/reports/ktlint/ktlint*/ktlint*.txt
- name: Handle Results
if: always()
id: get-comment-body
run: |
results="$(cat */*/build/reports/ktlint/ktlint*/ktlint*.txt */build/reports/ktlint/ktlint*/ktlint*.txt | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")"
if [ -z "$results" ]; then
body="👍 ✅ 👍"
else
body="👎 ❌ 👎 \`Failed${results}\`"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
body="$( echo $body | sed 's/\/home\/runner\/work\/element-android\/element-android\//\`<br\/>\`/g')"
body="$( echo $body | sed 's/\/src\/main\/java\// 🔸 /g')"
body="$( echo $body | sed 's/im\/vector\/app\///g')"
body="$( echo $body | sed 's/im\/vector\/lib\/attachmentviewer\///g')"
body="$( echo $body | sed 's/im\/vector\/lib\/multipicker\///g')"
body="$( echo $body | sed 's/im\/vector\/lib\///g')"
body="$( echo $body | sed 's/org\/matrix\/android\/sdk\///g')"
body="$( echo $body | sed 's/\/src\/androidTest\/java\// 🔸 /g')"
fi
echo "::set-output name=body::$body"
- name: Find Comment
if: always()
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Ktlint Results
- name: Publish ktlint results to PR
if: always()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOI, is there a necessity to add this line?

Copy link
Contributor Author

@ariskotsomitopoulos ariskotsomitopoulos Jan 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is an important line, while when ktlint fails thats when we should publish the results, also that was the fix for the artifacts. The problem was that the jobs was killed so nothing happened after that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, understood, thanks!

uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
### Ktlint Results

# Lint for main module and all the other modules
${{ steps.get-comment-body.outputs.body }}
edit-mode: replace

# Lint for main module
android-lint:
name: Android Linter
runs-on: ubuntu-latest
Expand Down Expand Up @@ -74,7 +118,6 @@ jobs:
run: ./gradlew clean lint${{ matrix.target }}Release --stacktrace
- name: Upload ${{ matrix.target }} linting report
uses: actions/upload-artifact@v2
if: always()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a last remark, will the lint report be uplodoad if the command fails (so if there are lint issue) if you remove this line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@ariskotsomitopoulos ariskotsomitopoulos Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit:
Here is a different case than before because the way command ./gradlew clean lint run needs to be succeed in order to generate the report! So there is no need to upload an artifact without the report. In comparison to ktlint that the report is generated when the build fails. Is it clear now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks!

with:
name: release-lint-report-${{ matrix.target }}
path: |
Expand Down
1 change: 1 addition & 0 deletions changelog.d/4864.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix github actions ktlint reports and publish results on PR as comment
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,4 @@ public static <T> LiveDataTestObserver<T> test(LiveData<T> liveData) {
liveData.observeForever(observer);
return observer;
}
}
}