22
33Docs: https://ghapi.fast.ai/actions.html.md"""
44
5- # AUTOGENERATED! DO NOT EDIT! File to edit: ../01_actions.ipynb.
5+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/ 01_actions.ipynb.
66
77# %% auto #0
88__all__ = ['contexts' , 'env_github' , 'Event' , 'def_pipinst' , 'user_repo' , 'create_workflow_files' , 'fill_workflow_templates' ,
1111 'context_github' , 'context_env' , 'context_job' , 'context_steps' , 'context_runner' , 'context_secrets' ,
1212 'context_strategy' , 'context_matrix' , 'context_needs' ]
1313
14- # %% ../01_actions.ipynb #e4187aeb
14+ # %% ../nbs/ 01_actions.ipynb #e4187aeb
1515from fastcore .all import *
1616from .core import *
1717from .templates import *
2020from contextlib import contextmanager
2121from enum import Enum
2222
23- # %% ../01_actions.ipynb #fb69ba90
23+ # %% ../nbs/ 01_actions.ipynb #fb69ba90
2424# So we can run this outside of GitHub actions too, read from file if needed
2525for a ,b in (('CONTEXT_GITHUB' ,context_example ), ('CONTEXT_NEEDS' ,needs_example ), ('GITHUB_REPOSITORY' ,'octocat/Hello-World' )):
2626 if a not in os .environ : os .environ [a ] = b
2929for context in contexts :
3030 globals ()[f'context_{ context } ' ] = dict2obj (loads (os .getenv (f"CONTEXT_{ context .upper ()} " , "{}" )))
3131
32- # %% ../01_actions.ipynb #393990e1
32+ # %% ../nbs/ 01_actions.ipynb #393990e1
3333_all_ = ['context_github' , 'context_env' , 'context_job' , 'context_steps' , 'context_runner' , 'context_secrets' , 'context_strategy' , 'context_matrix' , 'context_needs' ]
3434
35- # %% ../01_actions.ipynb #02ca0806
35+ # %% ../nbs/ 01_actions.ipynb #02ca0806
3636env_github = dict2obj ({k [7 :].lower ():v for k ,v in os .environ .items () if k .startswith ('GITHUB_' )})
3737
38- # %% ../01_actions.ipynb #3170b688
38+ # %% ../nbs/ 01_actions.ipynb #3170b688
3939def user_repo ():
4040 "List of `user,repo` from `env_github.repository"
4141 return env_github .repository .split ('/' )
4242
43- # %% ../01_actions.ipynb #deb389d7
43+ # %% ../nbs/ 01_actions.ipynb #deb389d7
4444Event = str_enum ('Event' ,
4545 'page_build' ,'content_reference' ,'repository_import' ,'create' ,'workflow_run' ,'delete' ,'organization' ,'sponsorship' ,
4646 'project_column' ,'push' ,'context' ,'milestone' ,'project_card' ,'project' ,'package' ,'pull_request' ,'repository_dispatch' ,
@@ -50,14 +50,14 @@ def user_repo():
5050 'installation' ,'release' ,'issues' ,'repository' ,'gollum' ,'membership' ,'deployment' ,'deploy_key' ,'issue_comment' ,'ping' ,
5151 'deployment_status' ,'fork' ,'schedule' )
5252
53- # %% ../01_actions.ipynb #bf0b5888
53+ # %% ../nbs/ 01_actions.ipynb #bf0b5888
5454def _create_file (path :Path , fname :str , contents ):
5555 if contents and not (path / fname ).exists (): (path / fname ).write_text (contents )
5656
5757def _replace (s :str , find , repl , i :int = 0 , suf :str = '' ):
5858 return s .replace (find , textwrap .indent (repl , ' ' * i )+ suf )
5959
60- # %% ../01_actions.ipynb #26eb64e5
60+ # %% ../nbs/ 01_actions.ipynb #26eb64e5
6161def create_workflow_files (fname :str , workflow :str , build_script :str , prebuild :bool = False ):
6262 "Create workflow and script files in suitable places in `github` folder"
6363 if not os .path .exists ('.git' ): return print ('This does not appear to be the root of a git repo' )
@@ -69,7 +69,7 @@ def create_workflow_files(fname:str, workflow:str, build_script:str, prebuild:bo
6969 _create_file (scr_path , f'build-{ fname } .py' , build_script )
7070 if prebuild : _create_file (scr_path , f'prebuild-{ fname } .py' , build_script )
7171
72- # %% ../01_actions.ipynb #3cf450a0
72+ # %% ../nbs/ 01_actions.ipynb #3cf450a0
7373def fill_workflow_templates (name :str , event , run , context , script , opersys = 'ubuntu' , prebuild = False ):
7474 "Function to create a simple Ubuntu workflow that calls a Python `ghapi` script"
7575 c = wf_tmpl
@@ -80,23 +80,23 @@ def fill_workflow_templates(name:str, event, run, context, script, opersys='ubun
8080 c = _replace (c , f'${ find } ' , str (repl ), i )
8181 create_workflow_files (name , c , script , prebuild = prebuild )
8282
83- # %% ../01_actions.ipynb #bc2f80a5
83+ # %% ../nbs/ 01_actions.ipynb #bc2f80a5
8484def env_contexts (contexts ):
8585 "Create a suitable `env:` line for a workflow to make a context available in the environment"
8686 contexts = uniqueify (['github' ] + listify (contexts ))
8787 return "\n " .join ("CONTEXT_" + o .upper () + ": ${{ toJson(" + o .lower () + ") }}" for o in contexts )
8888
89- # %% ../01_actions.ipynb #561125fa
89+ # %% ../nbs/ 01_actions.ipynb #561125fa
9090def_pipinst = 'pip install -Uq ghapi'
9191
92- # %% ../01_actions.ipynb #39c5d429
92+ # %% ../nbs/ 01_actions.ipynb #39c5d429
9393def create_workflow (name :str , event :Event , contexts :list = None , opersys = 'ubuntu' , prebuild = False ):
9494 "Function to create a simple Ubuntu workflow that calls a Python `ghapi` script"
9595 script = "from fastcore.all import *\n from ghapi import *"
9696 fill_workflow_templates (name , f'{ event } :' , def_pipinst , env_contexts (contexts ),
9797 script = script , opersys = opersys , prebuild = prebuild )
9898
99- # %% ../01_actions.ipynb #e8482286
99+ # %% ../nbs/ 01_actions.ipynb #e8482286
100100@call_parse
101101def gh_create_workflow (
102102 name :str , # Name of the workflow file
@@ -106,53 +106,53 @@ def gh_create_workflow(
106106 "Supports `gh-create-workflow`, a CLI wrapper for `create_workflow`."
107107 create_workflow (name , Event [event ], contexts .split ())
108108
109- # %% ../01_actions.ipynb #a85ea1f8
109+ # %% ../nbs/ 01_actions.ipynb #a85ea1f8
110110_example_url = 'https://raw.githubusercontent.com/fastai/ghapi/master/examples/{}.json'
111111
112- # %% ../01_actions.ipynb #47cfc8b9
112+ # %% ../nbs/ 01_actions.ipynb #47cfc8b9
113113def example_payload (event ):
114114 "Get an example of a JSON payload for `event`"
115115 return dict2obj (urljson (_example_url .format (event )))
116116
117- # %% ../01_actions.ipynb #778d7cc7
117+ # %% ../nbs/ 01_actions.ipynb #778d7cc7
118118def github_token ():
119119 "Get GitHub token from `GITHUB_TOKEN` env var if available, or from `github` context"
120120 return os .getenv ('GITHUB_TOKEN' , context_github .get ('token' , None ))
121121
122- # %% ../01_actions.ipynb #88716812
122+ # %% ../nbs/ 01_actions.ipynb #88716812
123123def actions_output (name , value ):
124124 "Print the special GitHub Actions `::set-output` line for `name::value`"
125125 print (f"::set-output name={ name } ::{ value } " )
126126
127- # %% ../01_actions.ipynb #50cad4c2
127+ # %% ../nbs/ 01_actions.ipynb #50cad4c2
128128def actions_debug (message ):
129129 "Print the special `::debug` line for `message`"
130130 print (f"::debug::{ message } " )
131131
132- # %% ../01_actions.ipynb #5b6d15ab
132+ # %% ../nbs/ 01_actions.ipynb #5b6d15ab
133133def actions_warn (message , details = '' ):
134134 "Print the special `::warning` line for `message`"
135135 print (f"::warning { details } ::{ message } " )
136136
137- # %% ../01_actions.ipynb #e97ba982
137+ # %% ../nbs/ 01_actions.ipynb #e97ba982
138138def actions_error (message , details = '' ):
139139 "Print the special `::error` line for `message`"
140140 print (f"::error { details } ::{ message } " )
141141
142- # %% ../01_actions.ipynb #a7ff989d
142+ # %% ../nbs/ 01_actions.ipynb #a7ff989d
143143@contextmanager
144144def actions_group (title ):
145145 "Context manager to print the special `::group`/`::endgroup` lines for `title`"
146146 print (f"::group::{ title } " )
147147 yield
148148 print (f"::endgroup::" )
149149
150- # %% ../01_actions.ipynb #3405cb7f
150+ # %% ../nbs/ 01_actions.ipynb #3405cb7f
151151def actions_mask (value ):
152152 "Print the special `::add-mask` line for `value`"
153153 print (f"::add-mask::{ value } " )
154154
155- # %% ../01_actions.ipynb #8682ff46
155+ # %% ../nbs/ 01_actions.ipynb #8682ff46
156156def set_git_user (api = None ):
157157 "Set git user name/email to authenticated user (if `api`) or GitHub Actions bot (otherwise)"
158158 if api :
0 commit comments