You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2023/06/28 13:21:55 UTC

[camel-k] branch main updated: feat/coverage report workflow (#4495)

This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 437e503e7 feat/coverage report workflow (#4495)
437e503e7 is described below

commit 437e503e7acbdd432af2365276105cdcf87e1843
Author: Martin Olšiak <56...@users.noreply.github.com>
AuthorDate: Wed Jun 28 15:21:49 2023 +0200

    feat/coverage report workflow (#4495)
    
    * feat/coverage report workflow
    
    - workflow creating comment on PR detailing code coverage  change
    
    ---------
    
    Co-authored-by: Martin Olsiak <ma...@gmail.com>
---
 .github/workflows/coverage-report.yml | 150 ++++++++++++++++++++++++++++++++++
 1 file changed, 150 insertions(+)

diff --git a/.github/workflows/coverage-report.yml b/.github/workflows/coverage-report.yml
new file mode 100644
index 000000000..878d7c104
--- /dev/null
+++ b/.github/workflows/coverage-report.yml
@@ -0,0 +1,150 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License. 
+# ---------------------------------------------------------------------------
+
+name: coverage report
+
+on:
+  pull_request_target:
+
+jobs:
+  report:
+    runs-on: ubuntu-latest
+
+    permissions:
+      pull-requests: write
+      issues: write
+
+    steps:
+
+      - name: Setup go
+        uses: actions/setup-go@v3
+        with:
+          go-version: '1.18'
+          check-latest: true
+
+      - name: Get Old Coverage
+        shell: bash
+        run: |
+          git clone https://github.com/apache/camel-k.git
+          cd camel-k
+          old_coverage="$(grep -o -P '(?<=Coverage-)(.*)(?=%)' README.adoc)"
+          cd ..
+          rm -rf camel-k
+
+      - name: Checkout
+        shell: bash
+        run: |
+          git clone ${{github.server_url}}/${{ github.repository }}.git
+          cd camel-k
+          git checkout ${{ github.event.pull_request.head.ref }}
+
+      - name: Fetch
+        shell: bash
+        working-directory: ./camel-k
+        env:
+          CI_USER: "github-actions[bot]"
+          CI_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
+        run: |
+          git config --local user.email "$CI_EMAIL"
+          git config --local user.name "$CI_USER"
+          git remote add upstream https://github.com/apache/camel-k.git
+          git fetch upstream
+          
+      - name: Rebase
+        shell: bash
+        working-directory: ./camel-k
+        env:
+          CI_USER: "github-actions[bot]"
+          CI_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
+          CI_TOKEN: ${{ inputs.secretGithubToken }}
+        run: |
+          git pull --rebase upstream main || git rebase --abort && echo "rebaseAborted=1" >> $GITHUB_ENV
+
+      - name: Get New Coverage
+        shell: bash
+        working-directory: ./camel-k
+        if: env.rebaseAborted != 1
+        env:
+          CI_USER: "github-actions[bot]"
+          CI_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
+          CI_TOKEN: ${{ inputs.secretGithubToken }}
+        run: |
+          go test -v ./... -covermode=count -coverprofile=coverage.out
+          go tool cover -func=coverage.out -o=coverage.out
+
+          new_coverage="$(grep -o -P '(?<=\(statements\))(.+)(?=%)' coverage.out | xargs)"
+
+          echo "OLD - $old_coverage"
+          echo "NEW - $new_coverage"
+
+          coverage_difference=$(bc <<< $new_coverage-$old_coverage)
+
+          if (( $(echo "$coverage_difference > 0" |bc -l) )); then
+          echo "POS_DIFF=POS" >> $GITHUB_ENV
+          elif (( $(echo "$coverage_difference < 0" |bc -l) )); then
+          echo "POS_DIFF=NEG" >> $GITHUB_ENV
+          else
+          echo "POS_DIFF=ZERO" >> $GITHUB_ENV
+          fi
+
+          echo "NEW_COV=$new_coverage" >> $GITHUB_ENV
+          echo "OLD_COV=$old_coverage" >> $GITHUB_ENV
+          echo "COV_DIFF=$coverage_difference" >> $GITHUB_ENV
+         
+
+      - name: Comment Coverage
+        if: env.rebaseAborted != 1
+        uses: actions/github-script@v6
+        with:
+          github-token: ${{secrets.GITHUB_TOKEN}}
+          script: |
+
+            if(${{env.POS_DIFF  == 'POS'}}){
+              github.rest.issues.createComment({
+                issue_number: context.issue.number,
+                owner: context.repo.owner,
+                repo: context.repo.repo,
+                body: ':camel: **Thank You for contributing!** :camel: \n\n  **Code Coverage Report** :heavy_check_mark:\n - Coverage changed from: **${{env.OLD_COV}}%** -> **${{env.NEW_COV}}%**\n- Coverage difference: +**${{env.COV_DIFF}}%**'
+              })
+            }else if(${{env.POS_DIFF == 'NEG'}}){
+              github.rest.issues.createComment({
+              issue_number: context.issue.number,
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              body: ':camel: **Thank You for contributing!** :camel: \n\n  **Code Coverage Report** :warning:\n - Coverage changed from: **${{env.OLD_COV}}%** -> **${{env.NEW_COV}}%**\n- Coverage difference: **${{env.COV_DIFF}}%**'
+              })
+            }else{
+              github.rest.issues.createComment({
+              issue_number: context.issue.number,
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              body: ':camel: **Thank You for contributing!** :camel: \n\n  **Code Coverage Report** :heavy_check_mark:\n - Coverage unchanged.'
+              })
+            }
+
+      - name: Comment Merge Conflicts
+        if: env.rebaseAborted == 1
+        uses: actions/github-script@v6
+        with:
+          github-token: ${{secrets.GITHUB_TOKEN}}
+          script: |
+            github.rest.issues.createComment({
+                issue_number: context.issue.number,
+                owner: context.repo.owner,
+                repo: context.repo.repo,
+                body: ':camel: **Thank You for contributing!** :camel: \n\n  Unable to create **Coverage Report** :warning:. \n Merge conflicts found.'
+              })
\ No newline at end of file