Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add a check to make sure unit tests are considered when changing code #10337

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Changes from 2 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
46 changes: 46 additions & 0 deletions .github/workflows/unittest-existence.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should refactor https://github.com/dbt-labs/actions/blob/main/.github/workflows/changelog-existence.yml#L2 a bit to make it more generalized and use it here.
@emmyoop WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@


# **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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new action things should look much easier.
@emmyoop thoughts on this refactor and how to best test it?

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/**'
Loading