-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4aa6711
commit 7421fb2
Showing
15 changed files
with
655 additions
and
430 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,50 @@ | ||
import yaml | ||
from yaml import CSafeLoader | ||
|
||
|
||
class Composite: | ||
""" | ||
A class to parse GitHub Action ymls. | ||
""" | ||
|
||
def __init__(self, action_yml: str): | ||
""" | ||
Initializes the CompositeParser instance by loading and parsing the provided YAML file. | ||
Args: | ||
action_yml (str): The YAML file to parse. | ||
""" | ||
self.composite = False | ||
self.parsed_yml = None | ||
try: | ||
self.parsed_yml = yaml.load(action_yml.replace("\t", " "), Loader=CSafeLoader) | ||
except ( | ||
yaml.parser.ParserError, | ||
yaml.scanner.ScannerError, | ||
yaml.constructor.ConstructorError, | ||
) as parse_error: | ||
self.invalid = True | ||
except ValueError as parse_error: | ||
self.invalid = True | ||
except Exception as parse_error: | ||
print( | ||
"Received an exception while parsing action contents: " | ||
+ str(parse_error) | ||
) | ||
self.invalid = True | ||
|
||
if not self.parsed_yml or type(self.parsed_yml) != dict: | ||
self.invalid = True | ||
else: | ||
self.composite = self._check_composite() | ||
|
||
def _check_composite(self): | ||
""" | ||
Checks if the parsed YAML file represents a composite GitHub Actions workflow. | ||
Returns: | ||
bool: True if the parsed YAML file represents a composite GitHub | ||
Actions workflow, False otherwise. | ||
""" | ||
if "runs" in self.parsed_yml and "using" in self.parsed_yml["runs"]: | ||
return self.parsed_yml["runs"]["using"] == "composite" |
This file contains 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 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 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 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 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 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
Oops, something went wrong.