feat(action): added validation for searchLine field in actions#7994
Open
cx-ricardo-jesus wants to merge 31 commits intomasterfrom
Open
feat(action): added validation for searchLine field in actions#7994cx-ricardo-jesus wants to merge 31 commits intomasterfrom
cx-ricardo-jesus wants to merge 31 commits intomasterfrom
Conversation
Contributor
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.








Reason for Proposed Changes
Proposed Changes
validate-search-lineto thego-ciworkflow, along with its supporting Python script, to automatically validate the correctness of the searchLine field in the modified KICS queries.dorny/paths-filteraction , to get the modified files in each PR/push to a branch, because the purpose of this actions is to validate the searchLine value for the queries changed on the relative push. This action produces the outputqueriesthat is a boolean that indicates whether any matching files with the path 'assets/queries/**/query.rego' (KICS query path) and the outputqueries_filesthat contains a JSON array with the exact paths of the changed files.Set up Python,Set up GoandValidate searchLineonly run ifsteps.filter.outputs.queries == true, meaning they are entirely skipped if no query file was modified.validate-search-line.pythat was made in Python because almost all the other scripts are also written in Python.get_changed_queries()helper function. This function reads theCHANGED_QUERIESenvironment variable, which is the JSON array produced bydorny/paths-filter. It parses the array and, for each entry ending in/query.rego, extracts the parent directory (the query folder) and returns of Path objects pointing to those directories.validate_querywill be used, which aims to validate a single directory. This helper function first of all, uses another helper function calledhas_search_line_defined, which only checks if the query contains the searchLine defined. If the query that was modified in the PR has this field defined, it starts a KICS scan command using the helper functionrun_kics_scanthat only runs that command and returns True if the scan ran with no problems. After that, it uses the helper function called validate_scan_results, which reads the results from the scan that ran previously, and checks if the line is defined to"-1"or if thesearchLinevalue is not equal to the value in thelinefield. If any of these scenarios happen, it returns False.::error::Some searchLine validations failed. See errors above..I submit this contribution under the Apache-2.0 license.