Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(ci): revert coverage report to comment #4562

Merged
merged 2 commits into from
Jul 12, 2023
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
86 changes: 0 additions & 86 deletions .github/workflows/coverage-report-comment.yml

This file was deleted.

132 changes: 92 additions & 40 deletions .github/workflows/coverage-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# 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

name: Coverage report

on:
pull_request_target:
Expand All @@ -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

- 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
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!**\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.'
})
3 changes: 1 addition & 2 deletions pkg/cmd/source/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down