4
4
import re
5
5
import sys
6
6
from dataclasses import dataclass , field
7
- from typing import IO , Dict , Hashable , List , Mapping
7
+ from typing import IO
8
+ from collections .abc import Hashable , Mapping
8
9
9
10
import yaml
10
11
from jsonpath_ng import parse
15
16
class SafeLineLoader (SafeLoader ):
16
17
def construct_mapping (
17
18
self , node : MappingNode , deep : bool = False
18
- ) -> Dict [Hashable , None ]:
19
+ ) -> dict [Hashable , None ]:
19
20
mapping = super ().construct_mapping (node , deep = deep )
20
21
# Add 1 so line numbering starts at 1
21
22
mapping ["line" ] = node .start_mark .line + 1
@@ -42,7 +43,7 @@ def __post_init__(self) -> None:
42
43
self .name = f"{ self .owner } /{ self .repository } "
43
44
44
45
45
- def find_gitub_actions_in_workflow (file : IO ) -> List [GithubActions ]:
46
+ def find_gitub_actions_in_workflow (file : IO ) -> list [GithubActions ]:
46
47
github_actions = []
47
48
jsonpath_expr = parse ("jobs.*.steps[*].uses" )
48
49
file = yaml .load (file , Loader = SafeLineLoader ) # nosec
@@ -96,7 +97,6 @@ def is_github_workflow_valid(file: IO, allowed_actions: Mapping[str, str]) -> bo
96
97
def load_allowed_actions () -> Mapping [str , str ]:
97
98
with open (
98
99
f"{ os .environ ['GITHUB_ACTION_PATH' ]} /ALLOWED_ACTIONS.yaml" ,
99
- mode = "r" ,
100
100
encoding = "utf-8" ,
101
101
) as file :
102
102
return yaml .safe_load (file )
@@ -107,7 +107,7 @@ def main() -> None:
107
107
allowed_actions = load_allowed_actions ()
108
108
for extension in ("yaml" , "yml" ):
109
109
for entry in glob .glob (f".github/workflows/**/*.{ extension } " , recursive = True ):
110
- with open (entry , mode = "r" , encoding = "utf-8" ) as file :
110
+ with open (entry , encoding = "utf-8" ) as file :
111
111
executions .append (is_github_workflow_valid (file , allowed_actions ))
112
112
113
113
sys .exit (not all (executions ))
0 commit comments