-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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/** |
| 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| - 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| name: PR Labeler | ||
|
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. 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? |
||
|
|
||
| on: | ||
| pull_request_target: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| label: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5 | ||
| with: | ||
| sync-labels: true | ||
|
|
||
| missing-tests: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| - 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 | ||
| 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() | ||
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.
Yes good idea to use SHAs.