-
Notifications
You must be signed in to change notification settings - Fork 7k
[CI] Add PR/Issue Auto Labeler #13380
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
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d07dafa
update
DN6 0ae2b3b
update
DN6 11a8ade
update
DN6 60326ae
update
DN6 91eeacc
update
DN6 c74cb82
update
DN6 c2d318f
update
DN6 62d73bf
update
DN6 d9d9d6a
Apply suggestion from @sayakpaul
DN6 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
Some comments aren't visible on the classic Files Changed page.
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,97 @@ | ||
| # https://github.com/actions/labeler | ||
| pipelines: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/pipelines/** | ||
|
|
||
| models: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/models/** | ||
|
|
||
| schedulers: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/schedulers/** | ||
|
|
||
| single-file: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/loaders/single_file.py | ||
| - src/diffusers/loaders/single_file_model.py | ||
| - src/diffusers/loaders/single_file_utils.py | ||
|
|
||
| ip-adapter: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/loaders/ip_adapter.py | ||
|
|
||
| lora: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/loaders/lora_base.py | ||
| - src/diffusers/loaders/lora_conversion_utils.py | ||
| - src/diffusers/loaders/lora_pipeline.py | ||
| - src/diffusers/loaders/peft.py | ||
|
|
||
| loaders: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/loaders/textual_inversion.py | ||
| - src/diffusers/loaders/transformer_flux.py | ||
| - src/diffusers/loaders/transformer_sd3.py | ||
| - src/diffusers/loaders/unet.py | ||
| - src/diffusers/loaders/unet_loader_utils.py | ||
| - src/diffusers/loaders/utils.py | ||
| - src/diffusers/loaders/__init__.py | ||
|
|
||
| quantization: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/quantizers/** | ||
|
|
||
| hooks: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/hooks/** | ||
|
|
||
| guiders: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/guiders/** | ||
|
|
||
| modular-pipelines: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/modular_pipelines/** | ||
|
|
||
| experimental: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/experimental/** | ||
|
|
||
| documentation: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - docs/** | ||
|
|
||
| tests: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - tests/** | ||
|
|
||
| examples: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - examples/** | ||
|
|
||
| CI: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - .github/** | ||
|
|
||
| utils: | ||
| - changed-files: | ||
| - any-glob-to-any-file: | ||
| - src/diffusers/utils/** | ||
| - src/diffusers/commands/** |
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,36 @@ | ||
| name: Issue Labeler | ||
|
|
||
| on: | ||
| issues: | ||
| types: [opened] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
| jobs: | ||
| label: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Install dependencies | ||
| run: pip install huggingface_hub | ||
| - name: Get labels from LLM | ||
| id: get-labels | ||
| env: | ||
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
| ISSUE_TITLE: ${{ github.event.issue.title }} | ||
| ISSUE_BODY: ${{ github.event.issue.body }} | ||
| run: | | ||
| LABELS=$(python utils/label_issues.py) | ||
| echo "labels=$LABELS" >> "$GITHUB_OUTPUT" | ||
| - name: Apply labels | ||
| if: steps.get-labels.outputs.labels != '' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| ISSUE_NUMBER: ${{ github.event.issue.number }} | ||
| LABELS: ${{ steps.get-labels.outputs.labels }} | ||
| run: | | ||
| for label in $(echo "$LABELS" | python -c "import json,sys; print('\n'.join(json.load(sys.stdin)))"); do | ||
| gh issue edit "$ISSUE_NUMBER" --add-label "$label" | ||
| done |
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,63 @@ | ||
| name: PR Labeler | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| label: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/labeler@v5 | ||
| with: | ||
| sync-labels: true | ||
|
|
||
| missing-tests: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Check for missing tests | ||
| id: check | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" \ | ||
| | python utils/check_test_missing.py | ||
| - name: Add or remove missing-tests label | ||
| if: always() | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: | | ||
| if [ "${{ steps.check.outcome }}" = "failure" ]; then | ||
| gh pr edit "$PR_NUMBER" --add-label "missing-tests" | ||
| else | ||
| gh pr edit "$PR_NUMBER" --remove-label "missing-tests" 2>/dev/null || true | ||
| fi | ||
|
|
||
| size-label: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Label PR by diff size | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| DIFF_SIZE=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}" --jq '.additions + .deletions') | ||
| for label in size/S size/M size/L; do | ||
| gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$label" 2>/dev/null || true | ||
| done | ||
| if [ "$DIFF_SIZE" -lt 50 ]; then | ||
| gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "size/S" | ||
| elif [ "$DIFF_SIZE" -lt 200 ]; then | ||
| gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "size/M" | ||
| else | ||
| gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "size/L" | ||
| fi | ||
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,86 @@ | ||
| import ast | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like it's only for new pipeline/model/scheduler additions? |
||
| import json | ||
| import sys | ||
|
|
||
|
|
||
| SRC_DIRS = ["src/diffusers/pipelines/", "src/diffusers/models/", "src/diffusers/schedulers/"] | ||
| MIXIN_BASES = {"ModelMixin", "SchedulerMixin", "DiffusionPipeline"} | ||
|
|
||
|
|
||
| def extract_classes_from_file(filepath: str) -> list[str]: | ||
| with open(filepath) as f: | ||
| tree = ast.parse(f.read()) | ||
|
|
||
| classes = [] | ||
| for node in ast.walk(tree): | ||
| if not isinstance(node, ast.ClassDef): | ||
| continue | ||
| base_names = set() | ||
| for base in node.bases: | ||
| if isinstance(base, ast.Name): | ||
| base_names.add(base.id) | ||
| elif isinstance(base, ast.Attribute): | ||
| base_names.add(base.attr) | ||
| if base_names & MIXIN_BASES: | ||
| classes.append(node.name) | ||
|
|
||
| return classes | ||
|
|
||
|
|
||
| def extract_imports_from_file(filepath: str) -> set[str]: | ||
| with open(filepath) as f: | ||
| tree = ast.parse(f.read()) | ||
|
|
||
| names = set() | ||
| for node in ast.walk(tree): | ||
| if isinstance(node, ast.ImportFrom): | ||
| for alias in node.names: | ||
| names.add(alias.name) | ||
| elif isinstance(node, ast.Import): | ||
| for alias in node.names: | ||
| names.add(alias.name.split(".")[-1]) | ||
|
|
||
| return names | ||
|
|
||
|
|
||
| def main(): | ||
| pr_files = json.load(sys.stdin) | ||
|
|
||
| new_classes = [] | ||
| for f in pr_files: | ||
| if f["status"] != "added" or not f["filename"].endswith(".py"): | ||
| continue | ||
| if not any(f["filename"].startswith(d) for d in SRC_DIRS): | ||
| continue | ||
| try: | ||
| new_classes.extend(extract_classes_from_file(f["filename"])) | ||
| except (FileNotFoundError, SyntaxError): | ||
| continue | ||
|
|
||
| if not new_classes: | ||
| sys.exit(0) | ||
|
|
||
| new_test_files = [ | ||
| f["filename"] | ||
| for f in pr_files | ||
| if f["status"] == "added" and f["filename"].startswith("tests/") and f["filename"].endswith(".py") | ||
| ] | ||
|
|
||
| imported_names = set() | ||
| for filepath in new_test_files: | ||
| try: | ||
| imported_names |= extract_imports_from_file(filepath) | ||
| except (FileNotFoundError, SyntaxError): | ||
| continue | ||
|
|
||
| untested = [cls for cls in new_classes if cls not in imported_names] | ||
|
|
||
| if untested: | ||
| print(f"missing-tests: {', '.join(untested)}") | ||
| sys.exit(1) | ||
| else: | ||
| sys.exit(0) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially for a future PR.
We don't run our entire test suite on the PR before merging and issues might surface after merging. So, it could be nice to also output a comment suggesting what SLOW test suites should be run by the maintainers before merging.
WDYT?