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/07/12 07:43:07 UTC

[camel-k] branch main updated (532296747 -> bf97f992e)

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

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


    from 532296747 chore(ci): echo some message
     new 2c52dd345 fix(ci): flaky unit test
     new bf97f992e fix(ci): revert coverage report to comment

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .github/workflows/coverage-report-comment.yml |  86 -----------------
 .github/workflows/coverage-report.yml         | 132 ++++++++++++++++++--------
 pkg/cmd/source/util_test.go                   |   3 +-
 3 files changed, 93 insertions(+), 128 deletions(-)
 delete mode 100644 .github/workflows/coverage-report-comment.yml


[camel-k] 01/02: fix(ci): flaky unit test

Posted by pc...@apache.org.
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

commit 2c52dd3453c3949a1bd6b41c4fabf86b58941831
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Jul 11 13:11:22 2023 +0200

    fix(ci): flaky unit test
---
 .github/workflows/coverage-report.yml | 8 ++++----
 pkg/cmd/source/util_test.go           | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/.github/workflows/coverage-report.yml b/.github/workflows/coverage-report.yml
index 96371e955..f87fb187f 100644
--- a/.github/workflows/coverage-report.yml
+++ b/.github/workflows/coverage-report.yml
@@ -12,7 +12,7 @@
 # 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. 
+# limitations under the License.
 # ---------------------------------------------------------------------------
 # test
 name: coverage-report
@@ -67,18 +67,18 @@ jobs:
 
           new_coverage="$(grep -o -P '(?<=\(statements\))(.+)(?=%)' coverage.out | xargs)"
           echo "NEW_COV=$new_coverage" >> $GITHUB_ENV
-          
+
           coverage_difference=`echo "$new_coverage-${{env.OLD_COV}}" | bc`
           echo "COV_DIFF=$coverage_difference" >> $GITHUB_ENV
 
           if (( $(echo "$coverage_difference > 0" |bc -l) )); then
-          echo "POS_DIFF=POS" >> $GITHUB_ENV  
+          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
-         
+
       - name: Save env variables
         run: |
           mkdir -p ./pr
diff --git a/pkg/cmd/source/util_test.go b/pkg/cmd/source/util_test.go
index 586743d2b..d04e8fd25 100644
--- a/pkg/cmd/source/util_test.go
+++ b/pkg/cmd/source/util_test.go
@@ -45,13 +45,12 @@ func isWindows() bool {
 }
 
 func TestPermissionDenied(t *testing.T) {
-	dir := "/tmp/filedir"
 
 	if isWindows() {
 		t.Skip("Test not reliably producing a result on a windows OS")
 	}
 
-	err := os.Mkdir(dir, 0700)
+	dir, err := os.MkdirTemp("/tmp", "camel-k-")
 	assert.Nil(t, err)
 
 	filename := filepath.Join(dir, "file.txt")


[camel-k] 02/02: fix(ci): revert coverage report to comment

Posted by pc...@apache.org.
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

commit bf97f992e6d0827d56c388e344d1b64360423942
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Wed Jul 12 08:24:27 2023 +0200

    fix(ci): revert coverage report to comment
    
    Closes #4555
---
 .github/workflows/coverage-report-comment.yml |  86 ------------------
 .github/workflows/coverage-report.yml         | 126 ++++++++++++++++++--------
 2 files changed, 89 insertions(+), 123 deletions(-)

diff --git a/.github/workflows/coverage-report-comment.yml b/.github/workflows/coverage-report-comment.yml
deleted file mode 100644
index a9c42d792..000000000
--- a/.github/workflows/coverage-report-comment.yml
+++ /dev/null
@@ -1,86 +0,0 @@
-# ---------------------------------------------------------------------------
-# 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-comment
-
-on:
-  workflow_run:
-    workflows: ["coverage-report"]
-    types:
-      - completed
-
-jobs:
-  comment:
-    runs-on: ubuntu-latest
-    if : ${{ github.event.workflow_run.conclusion == 'success' }}
-    steps:
-      - name: 'Download artifact'
-        uses: actions/github-script@v3.1.0
-        with:
-          script: |
-            var artifacts = await github.actions.listWorkflowRunArtifacts({
-               owner: context.repo.owner,
-               repo: context.repo.repo,
-               run_id: ${{github.event.workflow_run.id }},
-            });
-            var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
-              return artifact.name == "pr"
-            })[0];
-            var download = await github.actions.downloadArtifact({
-               owner: context.repo.owner,
-               repo: context.repo.repo,
-               artifact_id: matchArtifact.id,
-               archive_format: 'zip',
-            });
-            var fs = require('fs');
-            fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
-      - run: unzip pr.zip
-
-      - name: Comment Coverage
-        uses: actions/github-script@v6
-        with:
-          github-token: ${{secrets.GITHUB_TOKEN}}
-          script: |
-            var fs = require('fs');
-            var issue_number = Number(fs.readFileSync('./NR'));
-            var POS_DIFF = Number(fs.readFileSync('./POS_DIFF'));
-            var OLD_COV = Number(fs.readFileSync('./OLD_COV'));
-            var NEW_COV = Number(fs.readFileSync('./NEW_COV'));
-            var COV_DIFF = Number(fs.readFileSync('./COV_DIFF'));
-
-            if( POS_DIFF  == 'POS'){
-              github.rest.issues.createComment({
-                issue_number: 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: **${OLD_COV}%** -> **${NEW_COV}%**\n- Coverage difference: +**${COV_DIFF}%**`
-              })
-            }else if(POS_DIFF == 'NEG'){
-              github.rest.issues.createComment({
-              issue_number: 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: **${OLD_COV}%** -> **${NEW_COV}%**\n- Coverage difference: **${COV_DIFF}%**`
-              })
-            }else{
-              github.rest.issues.createComment({
-              issue_number: 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.`
-              })
-            }
\ No newline at end of file
diff --git a/.github/workflows/coverage-report.yml b/.github/workflows/coverage-report.yml
index f87fb187f..ddbbb0bc0 100644
--- a/.github/workflows/coverage-report.yml
+++ b/.github/workflows/coverage-report.yml
@@ -14,8 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # ---------------------------------------------------------------------------
-# test
-name: coverage-report
+
+name: Coverage report
 
 on:
   pull_request_target:
@@ -36,58 +36,110 @@ jobs:
           go-version: '1.18'
           check-latest: true
 
-      - name: Checkout apache repo
-        uses: actions/checkout@v3
-        with:
-          fetch-depth: 0
-          repository: apache/camel-k
-          path: old
-
-      - name: Get Old Coverage
+      - name: Prepare repo configuration
         shell: bash
+        env:
+          CI_USER: "github-actions[bot]"
+          CI_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
         run: |
-          cd old
-          old_coverage="$(grep -o -P '(?<=Coverage-)(.*)(?=%)' README.adoc)"
-          cd ..
-          echo "OLD_COV=$old_coverage" >> $GITHUB_ENV
+          git clone ${{ github.event.pull_request.head.repo.clone_url }}
+          cd ${{ github.event.pull_request.head.repo.name }}
+          git checkout ${{ github.event.pull_request.head.ref }}
 
-      - name: Checkout
-        uses: actions/checkout@v3
-        with:
-          persist-credentials: false
-          fetch-depth: 0
-          path: new
+          git config --local user.email "$CI_EMAIL"
+          git config --local user.name "$CI_USER"
+          git remote add upstream ${{ github.event.pull_request.base.repo.clone_url }}
+          git fetch upstream
+
+      - name: Rebase
+        shell: bash
+        working-directory: ./${{ github.event.pull_request.head.repo.name }}
+        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 ${{ github.event.pull_request.base.ref }} && echo "rebaseAborted=0" >> $GITHUB_ENV || echo "rebaseAborted=1" >> $GITHUB_ENV
 
       - name: Get New Coverage
         shell: bash
+        working-directory: ./${{ github.event.pull_request.head.repo.name }}
+        if: env.rebaseAborted != 1
         run: |
-          cd new
           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 "NEW_COV=$new_coverage" >> $GITHUB_ENV
 
-          coverage_difference=`echo "$new_coverage-${{env.OLD_COV}}" | bc`
-          echo "COV_DIFF=$coverage_difference" >> $GITHUB_ENV
+      - name: Get Old Coverage
+        shell: bash
+        working-directory: ./${{ github.event.pull_request.head.repo.name }}
+        if: env.rebaseAborted != 1
+        run: |
+          git checkout upstream/${{ github.event.pull_request.base.ref }}
+          go test -v ./... -covermode=count -coverprofile=coverage_old.out
+          go tool cover -func=coverage_old.out -o=coverage_old.out
+
+          old_coverage="$(grep -o -P '(?<=\(statements\))(.+)(?=%)' coverage_old.out | xargs)"
+          echo "OLD_COV=$old_coverage" >> $GITHUB_ENV
 
+      - name: Process results
+        shell: bash
+        working-directory: ./${{ github.event.pull_request.head.repo.name }}
+        if: env.rebaseAborted != 1
+        run: |
+          echo "OLD - $OLD_COV"
+          echo "NEW - $NEW_COV"
+          coverage_difference=$(bc <<< $NEW_COV-$OLD_COV)
           if (( $(echo "$coverage_difference > 0" |bc -l) )); then
-          echo "POS_DIFF=POS" >> $GITHUB_ENV
+            echo "POS_DIFF=POS" >> $GITHUB_ENV
           elif (( $(echo "$coverage_difference < 0" |bc -l) )); then
-          echo "POS_DIFF=NEG" >> $GITHUB_ENV
+            echo "POS_DIFF=NEG" >> $GITHUB_ENV
           else
-          echo "POS_DIFF=ZERO" >> $GITHUB_ENV
+            echo "POS_DIFF=ZERO" >> $GITHUB_ENV
           fi
+          echo "COV_DIFF=$coverage_difference" >> $GITHUB_ENV
 
-      - name: Save env variables
-        run: |
-          mkdir -p ./pr
-          echo ${{ github.event.number }} > ./pr/NR
-          echo ${{env.OLD_COV}} > ./pr/OLD_COV
-          echo ${{env.NEW_COV}} > ./pr/NEW_COV
-          echo ${{env.COV_DIFF}} > ./pr/COV_DIFF
-          echo ${{env.POS_DIFF}} > ./pr/POS_DIFF
-      - uses: actions/upload-artifact@v2
+      - 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!**\n\nCode Coverage Report :heavy_check_mark: - Coverage changed: ${{env.OLD_COV}}% --> ${{env.NEW_COV}}% (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!**\n\nCode Coverage Report :warning: - Coverage changed: ${{env.OLD_COV}}% --> ${{env.NEW_COV}}% (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!**\n\nCode Coverage Report :heavy_check_mark: - Coverage unchanged.'
+              })
+            }
+
+      - name: Comment Merge Conflicts
+        if: env.rebaseAborted == 1
+        uses: actions/github-script@v6
         with:
-          name: pr
-          path: pr/
+          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.'
+              })