1313# limitations under the License.
1414import json
1515import os
16- import re
1716import subprocess
1817from typing import List
1918
2019
2120def print_debug (msg : str ):
21+ """Print a message that is only visible when the GHA debug flag is set."""
2222 print (f"::debug::{ msg } " )
2323
2424
2525def set_output (name : str , value : str ):
26+ """Set a GHA output variable."""
2627 with open (ensure_env_var ("GITHUB_OUTPUT" ), "a" ) as f :
2728 f .write (f"{ name } ={ value } \n " )
2829
2930
3031def ensure_env_var (var : str ) -> str :
32+ """Return value of envvar `var`, throw if it's not set."""
3133 value = os .environ .get (var )
3234 if value is None or len (value ) == 0 :
3335 raise ValueError (f"Environment variable { var } is not set" )
3436 return value
3537
3638
3739def run_checked (args , ** kwargs ):
40+ """Run command and caputre it's output and check that it exists succesfully."""
3841 result = subprocess .run (args , ** kwargs , capture_output = True , check = True , text = True )
3942 return result
4043
4144
4245def jq (file : str , query : str , args : List [str ] = []):
46+ """Wrapper to run `jq` query on a file on disk or on a JSON string."""
4347 if os .path .isfile (file ):
4448 result = run_checked (["jq" , * args , query , file ])
4549 elif file .startswith ("{" ):
@@ -51,6 +55,7 @@ def jq(file: str, query: str, args: List[str] = []):
5155
5256
5357def gh_api (endpoint : str , method : str = "get" , options : List [str ] = []):
58+ """Wrapper to run `gh` REST API calls."""
5459 args = [
5560 "gh" ,
5661 "api" ,
@@ -67,6 +72,7 @@ def gh_api(endpoint: str, method: str = "get", options: List[str] = []):
6772
6873
6974def ensure_json (output : str ):
75+ """Always return valid JSON."""
7076 if output .isspace ():
7177 return json .loads ("{}" )
7278 else :
0 commit comments