-
Notifications
You must be signed in to change notification settings - Fork 554
GHA: Check for category existence on the main component #3136
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
2 commits
Select commit
Hold shift + click to select a range
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
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,82 @@ | ||
| import os | ||
| import sys | ||
| import yaml | ||
| from pathlib import Path | ||
|
|
||
| cwd = os.getcwd() | ||
| missing_category_profiles = [] | ||
| deleted_profiles = [] | ||
|
|
||
| changed_files = os.environ.get('ALL_CHANGED_FILES', '').split() | ||
|
|
||
| for file in changed_files: | ||
| file_basename = os.path.basename(file) | ||
| file_directory = os.path.dirname(file) | ||
|
|
||
| if '/profiles/' in file and file.endswith('.yml'): | ||
| print('\nCHECKING PROFILE:\n%s' % file) | ||
|
|
||
| os.chdir(file_directory) | ||
|
|
||
| if not os.path.exists(file_basename): | ||
| print("Skipping %s - file was deleted" % file_basename) | ||
| deleted_profiles.append(file) | ||
| os.chdir(cwd) | ||
| continue | ||
|
|
||
| with open(file_basename) as fp: | ||
| try: | ||
| profile = yaml.safe_load(fp) | ||
| except yaml.YAMLError as e: | ||
| print("Error parsing %s: %s" % (file_basename, e)) | ||
| os.chdir(cwd) | ||
| continue | ||
|
|
||
| if not profile or 'components' not in profile: | ||
| print("Skipping %s - no components found" % file_basename) | ||
| os.chdir(cwd) | ||
| continue | ||
|
|
||
| # Find the main component and verify it has a categories field | ||
| main_component = next( | ||
| (c for c in profile['components'] if c.get('id') == 'main'), | ||
| None | ||
| ) | ||
|
|
||
| if main_component is None: | ||
| print("Warning: %s has no 'main' component" % file_basename) | ||
| os.chdir(cwd) | ||
| continue | ||
|
|
||
| if not main_component.get('categories'): | ||
| print("MISSING CATEGORY: %s" % file) | ||
| missing_category_profiles.append(file) | ||
| else: | ||
| print("OK: %s has categories: %s" % ( | ||
| file_basename, | ||
| [c['name'] for c in main_component['categories']] | ||
| )) | ||
|
|
||
| os.chdir(cwd) | ||
|
|
||
| with open("profile-categories-comment-body.md", "w") as f: | ||
| if missing_category_profiles: | ||
| f.write("Profile category check: :x: **Missing categories detected.**\n\n") | ||
| f.write("The following profiles are missing a `categories` field on the `main` component:\n\n") | ||
| for profile in missing_category_profiles: | ||
| f.write("- `%s`\n" % profile) | ||
| f.write("\nPlease add a `categories` entry to the `main` component. Example:\n") | ||
| f.write("```yaml\ncomponents:\n - id: main\n categories:\n - name: Switch\n capabilities:\n ...\n```\n") | ||
| else: | ||
| f.write("Profile category check: :white_check_mark: Passed - all profiles have a category defined.\n") | ||
|
|
||
| if deleted_profiles: | ||
| f.write("\n:warning: **Deleted profile files detected:**\n") | ||
| for deleted in deleted_profiles: | ||
| f.write("- `%s`\n" % deleted) | ||
|
|
||
| with open("profile-categories-comment-body.md", "r") as f: | ||
| print("\n" + f.read()) | ||
|
|
||
| if missing_category_profiles: | ||
| sys.exit(1) |
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,34 @@ | ||
| name: Post profile categories comment | ||
| on: | ||
| workflow_run: | ||
| workflows: [Check profile categories] | ||
| types: | ||
| - completed | ||
|
|
||
| jobs: | ||
| comment-on-pr: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Download comment artifact | ||
| uses: dawidd6/action-download-artifact@v6 | ||
| with: | ||
| workflow: check-profile-categories.yml | ||
| run_id: ${{ github.event.workflow_run.id }} | ||
|
|
||
| - run: echo "pr_number=$(cat pr_number/pr_number.txt)" >> $GITHUB_ENV | ||
|
|
||
| - name: Find comment | ||
| uses: peter-evans/find-comment@v2 | ||
| id: fc | ||
| with: | ||
| body-includes: Profile category check | ||
| comment-author: 'github-actions[bot]' | ||
| issue-number: ${{ env.pr_number }} | ||
|
|
||
| - name: Post comment | ||
| uses: peter-evans/create-or-update-comment@v2 | ||
| with: | ||
| comment-id: ${{ steps.fc.outputs.comment-id }} | ||
| body-file: 'profile_categories_comment/profile-categories-comment-body.md' | ||
| edit-mode: replace | ||
| issue-number: ${{ env.pr_number }} |
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,41 @@ | ||
| name: Check profile categories | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize] | ||
| paths: | ||
| - 'drivers/**/profiles/*.yml' | ||
|
|
||
| jobs: | ||
| check-profile-categories: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Gather file changes | ||
| id: changed-files | ||
| uses: tj-actions/changed-files@v47 | ||
|
|
||
| - name: Run python script | ||
| env: | ||
| ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | ||
| run: | | ||
| python ./.github/scripts/check_profile_categories.py | ||
|
|
||
| - name: Upload profile categories comment artifact | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: profile_categories_comment | ||
| path: | | ||
| profile-categories-comment-body.md | ||
|
|
||
| - run: echo ${{ github.event.number }} > pr_number.txt | ||
|
|
||
| - name: Upload PR info | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: pr_number | ||
| path: | | ||
| pr_number.txt |
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
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.
Probably worth a check that this still detects duplicate profiles
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.
Looks like it is still working as it did before: