Skip to content

Commit

Permalink
[CI] improvement of code coverage check (grafana#7428)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:
changed the check step to compare code coverage with `target` branch,
not with `main`.

Previously, it compared code coverage with coverage in the `main`
branch. to do this, Drone checked out `main` branch and tried to run the
tests to report the coverage. Also, Drone ran the tests on the current
branch, and after that compared the results and reported them to PR as a
comment.

However, if the PR is opened against not `main` branch, for example,
against `release-2.6.x` branch, drone tried to compare coverage between
the source branch from PR and `main`. However, `main` might contain
breaking changes that prevent Drone from compiling the sources or from
running the tests successfully.

Last time, it was Go version. Loki in `main` branch was migrated to
go1.19 and `loki-build-image` was updated. however, Drone CI on release
branch ran the pipeline on old `loki-build-image` that was not able to
compile the Loki from `main` branch.
  • Loading branch information
vlad-diachenko authored Nov 1, 2022
1 parent a508d69 commit 30fe6b9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
17 changes: 11 additions & 6 deletions .drone/drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -518,23 +518,28 @@ local manifest_ecr(apps, archs) = pipeline('manifest-ecr') {
steps: [
make('check-drone-drift', container=false) { depends_on: ['clone'] },
make('check-generated-files', container=false) { depends_on: ['clone'] },
run('clone-main', commands=['cd ..', 'git clone $CI_REPO_REMOTE loki-main', 'cd -']) { depends_on: ['clone'] },
make('test', container=false) { depends_on: ['clone', 'clone-main'] },
run('test-main', commands=['cd ../loki-main', 'BUILD_IN_CONTAINER=false make test']) { depends_on: ['clone-main'] },
run('clone-target-branch', commands=[
'cd ..',
'echo "cloning "$DRONE_TARGET_BRANCH ',
'git clone -b $DRONE_TARGET_BRANCH $CI_REPO_REMOTE loki-target-branch',
'cd -',
]) { depends_on: ['clone'], when: onPRs },
make('test', container=false) { depends_on: ['clone', 'clone-target-branch'] },
run('test-target-branch', commands=['cd ../loki-target-branch', 'BUILD_IN_CONTAINER=false make test']) { depends_on: ['clone-target-branch'], when: onPRs },
make('compare-coverage', container=false, args=[
'old=../loki-main/test_results.txt',
'old=../loki-target-branch/test_results.txt',
'new=test_results.txt',
'packages=ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki',
'> diff.txt',
]) { depends_on: ['test', 'test-main'] },
]) { depends_on: ['test', 'test-target-branch'], when: onPRs },
run('report-coverage', commands=[
"pull=$(echo $CI_COMMIT_REF | awk -F '/' '{print $3}')",
"body=$(jq -Rs '{body: . }' diff.txt)",
'curl -X POST -u $USER:$TOKEN -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/grafana/loki/issues/$pull/comments -d "$body" > /dev/null',
], env={
USER: 'grafanabot',
TOKEN: { from_secret: github_secret.name },
}) { depends_on: ['compare-coverage'] },
}) { depends_on: ['compare-coverage'], when: onPRs },
make('lint', container=false) { depends_on: ['clone', 'check-generated-files'] },
make('check-mod', container=false) { depends_on: ['clone', 'test', 'lint'] },
{
Expand Down
31 changes: 22 additions & 9 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,49 @@ steps:
name: check-generated-files
- commands:
- cd ..
- git clone $CI_REPO_REMOTE loki-main
- 'echo "cloning "$DRONE_TARGET_BRANCH '
- git clone -b $DRONE_TARGET_BRANCH $CI_REPO_REMOTE loki-target-branch
- cd -
depends_on:
- clone
environment: {}
image: grafana/loki-build-image:0.24.2
name: clone-main
name: clone-target-branch
when:
event:
- pull_request
- commands:
- make BUILD_IN_CONTAINER=false test
depends_on:
- clone
- clone-main
- clone-target-branch
environment: {}
image: grafana/loki-build-image:0.24.2
name: test
- commands:
- cd ../loki-main
- cd ../loki-target-branch
- BUILD_IN_CONTAINER=false make test
depends_on:
- clone-main
- clone-target-branch
environment: {}
image: grafana/loki-build-image:0.24.2
name: test-main
name: test-target-branch
when:
event:
- pull_request
- commands:
- make BUILD_IN_CONTAINER=false compare-coverage old=../loki-main/test_results.txt
- make BUILD_IN_CONTAINER=false compare-coverage old=../loki-target-branch/test_results.txt
new=test_results.txt packages=ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki
> diff.txt
depends_on:
- test
- test-main
- test-target-branch
environment: {}
image: grafana/loki-build-image:0.24.2
name: compare-coverage
when:
event:
- pull_request
- commands:
- pull=$(echo $CI_COMMIT_REF | awk -F '/' '{print $3}')
- 'body=$(jq -Rs ''{body: . }'' diff.txt)'
Expand All @@ -150,6 +160,9 @@ steps:
USER: grafanabot
image: grafana/loki-build-image:0.24.2
name: report-coverage
when:
event:
- pull_request
- commands:
- make BUILD_IN_CONTAINER=false lint
depends_on:
Expand Down Expand Up @@ -1597,6 +1610,6 @@ kind: secret
name: gpg_private_key
---
kind: signature
hmac: 63a2da744f6d908e4588aba33231bbe438a6c2438bd1f288af60404b137d5df7
hmac: 7103f179cdc3517cf3ddb2d31c3ead90a400dd5416558ef4cccf5d54063cc923

...

0 comments on commit 30fe6b9

Please sign in to comment.