-
Notifications
You must be signed in to change notification settings - Fork 12
Only testing doc when only doc is modified #49
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
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
927d6a3
Added git diff
mehtamohit013 43758d8
test modified
mehtamohit013 f9977da
Fix
mehtamohit013 3a8f70a
Format
mehtamohit013 8f0a825
Changed API
mehtamohit013 ce8a4f9
Fix
mehtamohit013 8e8e409
tmp package
mehtamohit013 18a1814
Fix tests
mehtamohit013 242cf1a
Fix test
mehtamohit013 92533de
Changed args
mehtamohit013 f4de4d4
Added sys exit
mehtamohit013 c928988
Revert sys.exit
mehtamohit013 99dc484
Lint
mehtamohit013 8f880a8
Added test case
mehtamohit013 b2667bb
Renaming
mehtamohit013 8c09d1b
Added Pathlib implementation
mehtamohit013 34853e5
tmp deleted workdlow tag check
mehtamohit013 3a7a615
Re added workflow edits
mehtamohit013 631c27c
Fix CI
mehtamohit013 f867bb1
Commented Tests
mehtamohit013 ce3ee64
Format
mehtamohit013 539c7eb
Commented some more
mehtamohit013 0fdbc34
more comments
mehtamohit013 9be7f6d
Fix conftest
mehtamohit013 86989b9
Format
mehtamohit013 c03a61a
Fix conftest
mehtamohit013 5486626
Format
mehtamohit013 4a056eb
Verbose testing
mehtamohit013 51e382f
Revert back CI changes
mehtamohit013 c7e2d47
Moved to sys.exit
mehtamohit013 8cfd99a
Minor
mehtamohit013 a5998cc
Minor
mehtamohit013 7c264f7
Merge branch 'doc' of github.com:mehtamohit013/pkgmt into doc
mehtamohit013 fe85854
Minor
mehtamohit013 83ced20
Format
mehtamohit013 20c65e0
Fix
mehtamohit013 b7f0147
Windows CI
mehtamohit013 988f1d3
Revert back Windows CI
mehtamohit013 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import subprocess | ||
| import argparse | ||
| import sys | ||
|
|
||
|
|
||
| def check_modified(base_branch, exclude_path, debug=False): | ||
| # https://stackoverflow.com/questions/4380945 | ||
| cmd = f"git diff --exit-code {base_branch}... -- ." | ||
|
|
||
| for path in exclude_path: | ||
| cmd += f" ':^{path}'" | ||
|
|
||
| if debug: | ||
| print(f"cmd: {cmd}") | ||
| try: | ||
| subprocess.check_output(cmd, shell=True) | ||
| return 0 | ||
| except subprocess.CalledProcessError as err: | ||
| if debug: | ||
| print( | ||
| f"Path has been modified with respect to '{base_branch}'\n" | ||
| f"Excluding paths: {exclude_path}" | ||
| ) | ||
| print(f"Return code: {err.returncode}") | ||
| print(f"Output: {err.output}") | ||
| return 1 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser( | ||
| description="Check if a branch has modified" "anything excluding some path/dir" | ||
| ) | ||
| parser.add_argument( | ||
| "-b", "--base-branch", default="main", help="Base branch to compare against" | ||
| ) | ||
| parser.add_argument( | ||
| "-e", | ||
| "--exclude-path", | ||
| default=["doc"], | ||
| nargs="+", | ||
| help="Path to exclude from git diff." | ||
| "Can be used multiple times eg: -e p1 -e p2", | ||
| ) | ||
| parser.add_argument("--debug", action="store_true", help="Print debug info") | ||
|
|
||
| args = parser.parse_args() | ||
| returncode = check_modified(args.base_branch, args.exclude_path, debug=args.debug) | ||
| sys.exit(returncode) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import pytest | ||
| from pkgmt import fail_if_modified | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "base_branch, exclude_path, returncode", | ||
| [ | ||
| [ | ||
| "main", | ||
| ["test_doc1"], | ||
| 1, | ||
| ], | ||
| [ | ||
| "main", | ||
| ["test_doc1", "test_doc2"], | ||
| 0, | ||
| ], | ||
| ], | ||
| ) | ||
| def test_check_modified(tmp_package_modi, base_branch, exclude_path, returncode): | ||
| assert ( | ||
| fail_if_modified.check_modified(base_branch, exclude_path, debug=True) | ||
| == returncode | ||
| ) | ||
|
|
||
|
|
||
| def test_check_modified_2(tmp_package_modi_2): | ||
| assert fail_if_modified.check_modified("main", ["doc"], debug=True) == 0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.