Repository navigation
Lint - Categories in the properties.json file - #1099
aparna-ravindra wants to merge 7 commits into
Conversation
| @@ -0,0 +1,37 @@ | |||
| require 'json' | |||
There was a problem hiding this comment.
Why not use validate-data script itself?
There was a problem hiding this comment.
The reasons I plan on keeping the script separate
- Modularity : The validate-data script already does multiple checks. We expect to add more checks in the validate-categories script, which will make validate-data bulky if combined.
- Validate-Data is a mandatory check on PR, failing which will block PR merge. We intend Validate-categories to nudge the PR author with information on best practices for the values of the category field. There is no plan on failing the check.
There was a problem hiding this comment.
Ah! I think I get it now. category validation is an optional thing and we only put a PR message. Seems like we discussed it long back.
There was a problem hiding this comment.
@aparna-ravindra actually just re-thinking about it, currently we are only validating the template type category and not tech stack category. And if so, then we should fail the validation just like validate-data. And hence we can make this part of validate-data itself. Thoughts?
| @allowed_categories = settings['allowed_categories'] | ||
|
|
||
| def validateCategories(categories) | ||
| return categories.nil? || (categories.is_a?(Array) && ! categories.select{|l| @allowed_categories.detect{|p| p.casecmp(l) == 0 } }.empty? ) |
There was a problem hiding this comment.
Will array intersection achieve same result as select and detect?
There was a problem hiding this comment.
Need this to be case-insensitive
| @allowed_categories = settings['allowed_categories'] | ||
|
|
||
| def validateCategories(categories) | ||
| return categories.nil? || (categories.is_a?(Array) && ! categories.select{|l| @allowed_categories.detect{|p| p.casecmp(l) == 0 } }.empty? ) |
There was a problem hiding this comment.
If categories is nil, then validate should fail
There was a problem hiding this comment.
categories is an optional field. We do have a blank template today where there are no categories.
There was a problem hiding this comment.
This seems troublesome to me. Blank is a special case we should handle is separately. For any other template, we can disallow missing categories.
|
|
||
| result = [] | ||
| for folder in folders | ||
| files = Dir.entries(folder).select {|entry| File.file?(File.join(folder, entry)) && (File.extname(entry) == ".yaml" || File.extname(entry) == ".yml") } |
There was a problem hiding this comment.
Do we need to co-relate with workflow yml file? Or just simply look through all properties file?
There was a problem hiding this comment.
The co-relation is taken care by the validate-data script.
There was a problem hiding this comment.
No, I meant why do we need to first find the workflow file name and then look for properties.json for that? We can directly iterate through all properties.json and validate category.
| # read-only repo token | ||
| # no access to secrets | ||
| on: | ||
| pull_request: |
There was a problem hiding this comment.
add on push event as well. ghes branch has direct pushes.
There was a problem hiding this comment.
ghes branch is updated only through the sync-ghes workflow, I believe.
Also, we require a PR to comment if needed. Otherwise, the validation script is run, but the result is not shared anywhere.
There was a problem hiding this comment.
Got it. So, essentially master branch is the gatekeeper for ensuring correct categories.
| @@ -0,0 +1,62 @@ | |||
| name: Validate Categories on PR | |||
There was a problem hiding this comment.
Please add a comment on what are the valid categories
| - name: Save Validation Output | ||
| if: ${{steps.comment-format.outputs.content && steps.comment-format.outputs.content != '' }} | ||
| run: | | ||
| mkdir -p ./category_validation |
There was a problem hiding this comment.
This approach for publishing artifact is needed due to the reason that PR workflow won't have permission to write to PR in case of forked repos most probably. Isn't it?
Would it be easier to write a bot or as I mentioned in another comment to make category validation part of validate-data
Context
The categories listed in the .properties.json file of a template determine the section under which the template appears in the actions/new page.
What does this PR contain?
This PR aims at validating the
categoriesfield present in the .properties.json file for each of the templates and identifying that it contains at least one of the supported categories. The aim is to make the reviewer aware of such cases by commenting on the PR. The reviewer can then choose to recommend the right category for the template.The list of recognised categories is maintained in the settings.json file and is shared in the comment with the PR owner.
This PR contains two workflows
The comment on the PR appears like this: https://github.com/aparna-ravindra/starter-workflows/pull/42#issuecomment-920592073
tldr;
Two workflows were needed because the workflows running on the PR branch(from forked repo) do not have permission to comment on the issue. This has been documented here. In gist the doc says
At the same time it mentions:
Therefore the approach described in the doc has been followed.