From 38c3a8a10ee2135c9b710f3e0ca32e3eddfa4120 Mon Sep 17 00:00:00 2001 From: Chenyu Li Date: Tue, 18 Jun 2024 15:09:41 -0700 Subject: [PATCH 1/4] add a check to make sure unit tests are considered when changing code --- .github/workflows/unittest-existence.yml | 77 ++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .github/workflows/unittest-existence.yml diff --git a/.github/workflows/unittest-existence.yml b/.github/workflows/unittest-existence.yml new file mode 100644 index 00000000000..635a3b87465 --- /dev/null +++ b/.github/workflows/unittest-existence.yml @@ -0,0 +1,77 @@ + + +# **what?** +# Checks that a file has been committed under the /tests/unit directory +# as modification/addition to unit test. +# This workflow runs on pull_request_target because it requires +# secrets to post comments. + +# **why?** +# Gentle nudge to think about adding unit tests for new code. +# It also makes sure that we can filter PRs by tag to find out what type of changes are hard to unittest. + +# **when?** +# This will run for all PRs going into main. It will +# run when they are opened, reopened, when any label is added or removed +# and when new code is pushed to the branch. The action will then get +# skipped if the 'Hard to Unit Test' label or the 'Unit Test Not Needed' Label is present. + +name: Check Changelog Entry + +on: + pull_request_target: + types: [opened, reopened, labeled, unlabeled, synchronize] + branches: + - main + paths: ['core/dbt'] + + workflow_dispatch: + +defaults: + run: + shell: bash + +permissions: + contents: read + pull-requests: write + +env: + comment: "Thank you for your pull request! We could not find a unittest file for this change. Please consider adding some. If it is hard to unittest, please add the 'Hard to Unit Test' label. If unit tests are not needed, please add the 'Unit Test Not Needed' label." + + +jobs: + unittest: + name: Check if Unit Test being added. + if: ${{ !contains(github.event.pull_request.labels.*.name, 'Unit Test Not Needed') && !contains(github.event.pull_request.labels.*.name, 'Hard to Unit Test')}} + runs-on: ubuntu-latest + steps: + - name: Check if unittest file was added + uses: dorny/paths-filter@v3 + id: unittest_existence + with: + token: ${{ secrets.GITHUB_TOKEN }} + filters: | + exists: + - added|modified: 'tests/unit/**' + + - name: Check for existing comment + if: steps.unittest_existence.outputs.exists == 'false' + uses: peter-evans/find-comment@v3 + id: find_comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: "github-actions[bot]" + body-includes: ${{ env.comment }} + - name: Comment if no unittest file was added + if: steps.unittest_existence.outputs.exists == 'false' && + steps.find_comment.outputs.exists == 'false' + run: | + gh issue comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body "${{ env.comment }}" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Fail job if unittest is missing and required + if: steps.unittest_existence.outputs.exists == 'false' + uses: actions/github-script@v7 + with: + script: core.setFailed('Unit Test required to merge.') From df46e0101b8bc2accff015c099c29569264d2847 Mon Sep 17 00:00:00 2001 From: Chenyu Li Date: Tue, 18 Jun 2024 16:12:27 -0700 Subject: [PATCH 2/4] use new action --- .github/workflows/unittest-existence.yml | 39 +++--------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/.github/workflows/unittest-existence.yml b/.github/workflows/unittest-existence.yml index 635a3b87465..a5667692a78 100644 --- a/.github/workflows/unittest-existence.yml +++ b/.github/workflows/unittest-existence.yml @@ -35,43 +35,12 @@ permissions: contents: read pull-requests: write -env: - comment: "Thank you for your pull request! We could not find a unittest file for this change. Please consider adding some. If it is hard to unittest, please add the 'Hard to Unit Test' label. If unit tests are not needed, please add the 'Unit Test Not Needed' label." - - jobs: unittest: name: Check if Unit Test being added. if: ${{ !contains(github.event.pull_request.labels.*.name, 'Unit Test Not Needed') && !contains(github.event.pull_request.labels.*.name, 'Hard to Unit Test')}} - runs-on: ubuntu-latest - steps: - - name: Check if unittest file was added - uses: dorny/paths-filter@v3 - id: unittest_existence - with: - token: ${{ secrets.GITHUB_TOKEN }} - filters: | - exists: - - added|modified: 'tests/unit/**' - - - name: Check for existing comment - if: steps.unittest_existence.outputs.exists == 'false' - uses: peter-evans/find-comment@v3 - id: find_comment - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: "github-actions[bot]" - body-includes: ${{ env.comment }} - - name: Comment if no unittest file was added - if: steps.unittest_existence.outputs.exists == 'false' && - steps.find_comment.outputs.exists == 'false' - run: | - gh issue comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body "${{ env.comment }}" - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Fail job if unittest is missing and required - if: steps.unittest_existence.outputs.exists == 'false' - uses: actions/github-script@v7 - with: - script: core.setFailed('Unit Test required to merge.') + uses: dbt-labs/actions/.github/workflows/check-change-and-comment.yml@main + with: + comment: "Thank you for your pull request! We could not find a unittest file for this change. Please consider adding some. If it is hard to unittest, please add the 'Hard to Unit Test' label. If unit tests are not needed, please add the 'Unit Test Not Needed' label." + path_filter: 'tests/unit/**' From 442d0b174f3205fcd05a4903d1b63e85de57726b Mon Sep 17 00:00:00 2001 From: Chenyu Li Date: Fri, 21 Jun 2024 10:48:07 -0700 Subject: [PATCH 3/4] switch to better config codecove --- .github/workflows/unittest-existence.yml | 46 ------------------------ codecov.yml | 33 ++++++++++++----- 2 files changed, 24 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/unittest-existence.yml diff --git a/.github/workflows/unittest-existence.yml b/.github/workflows/unittest-existence.yml deleted file mode 100644 index a5667692a78..00000000000 --- a/.github/workflows/unittest-existence.yml +++ /dev/null @@ -1,46 +0,0 @@ - - -# **what?** -# Checks that a file has been committed under the /tests/unit directory -# as modification/addition to unit test. -# This workflow runs on pull_request_target because it requires -# secrets to post comments. - -# **why?** -# Gentle nudge to think about adding unit tests for new code. -# It also makes sure that we can filter PRs by tag to find out what type of changes are hard to unittest. - -# **when?** -# This will run for all PRs going into main. It will -# run when they are opened, reopened, when any label is added or removed -# and when new code is pushed to the branch. The action will then get -# skipped if the 'Hard to Unit Test' label or the 'Unit Test Not Needed' Label is present. - -name: Check Changelog Entry - -on: - pull_request_target: - types: [opened, reopened, labeled, unlabeled, synchronize] - branches: - - main - paths: ['core/dbt'] - - workflow_dispatch: - -defaults: - run: - shell: bash - -permissions: - contents: read - pull-requests: write - -jobs: - unittest: - name: Check if Unit Test being added. - if: ${{ !contains(github.event.pull_request.labels.*.name, 'Unit Test Not Needed') && !contains(github.event.pull_request.labels.*.name, 'Hard to Unit Test')}} - - uses: dbt-labs/actions/.github/workflows/check-change-and-comment.yml@main - with: - comment: "Thank you for your pull request! We could not find a unittest file for this change. Please consider adding some. If it is hard to unittest, please add the 'Hard to Unit Test' label. If unit tests are not needed, please add the 'Unit Test Not Needed' label." - path_filter: 'tests/unit/**' diff --git a/codecov.yml b/codecov.yml index 039a0715e32..a48db4c88cc 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,13 +1,28 @@ ignore: - ".github" - ".changes" -coverage: - status: - project: - default: + +comment: + layout: "header, diff, flags, components" # show component info in the PR comment + +component_management: + default_rules: # default rules that will be inherited by all components + statuses: + - type: project # in this case every component that doens't have a status defined will have a project type one target: auto - threshold: 0.1% # Reduce noise by ignoring rounding errors in coverage drops - patch: - default: - target: auto - threshold: 80% + threshold: 0.1% + - type: patch + target: 80% + individual_components: + - component_id: unittests + name: "Unit Tests" + flag_regexes: + - "unit" + statuses: + - type: patch + target: 80% + threshold: 5% + - component_id: integrationtests + name: "Integration Tests" + flag_regexes: + - "integration" From e06ed29804911ccff0c233f18eb8d82b48c3deec Mon Sep 17 00:00:00 2001 From: Chenyu Li Date: Fri, 21 Jun 2024 10:49:22 -0700 Subject: [PATCH 4/4] add back project level --- codecov.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/codecov.yml b/codecov.yml index a48db4c88cc..47ed944cf21 100644 --- a/codecov.yml +++ b/codecov.yml @@ -2,6 +2,17 @@ ignore: - ".github" - ".changes" +coverage: + status: + project: + default: + target: auto + threshold: 0.1% # Reduce noise by ignoring rounding errors in coverage drops + patch: + default: + target: auto + threshold: 80% + comment: layout: "header, diff, flags, components" # show component info in the PR comment