def run(self, action_name=None, reuse=False, parallel=False): """Run the pipeline or a specific action""" os.environ['WORKSPACE'] = self.workspace if scm.get_user(): repo_id = '{}/{}'.format(scm.get_user(), scm.get_name()) else: repo_id = 'unknown' self.env = { 'GITHUB_WORKSPACE': self.workspace, 'GITHUB_WORKFLOW': self.wf.name, 'GITHUB_ACTOR': 'popper', 'GITHUB_REPOSITORY': repo_id, 'GITHUB_EVENT_NAME': self.wf.on, 'GITHUB_EVENT_PATH': '/{}/{}'.format(self.workspace, 'workflow/event.json'), 'GITHUB_SHA': scm.get_sha(), 'GITHUB_REF': scm.get_ref() } for e in dict(self.env): self.env.update({e.replace('GITHUB_', 'POPPER_'): self.env[e]}) self.download_actions() self.instantiate_runners() if action_name: self.wf.get_runner(action_name).run(reuse) else: for s in self.wf.get_stages(): self.run_stage(s, reuse, parallel)
def get_workflow_env(wf, workspace): """Updates the Popper environment variable with Github environment variables. Args: wf(popper.parser.Workflow): Instance of the Workflow class. workspace(str): Location of the workspace. Returns: dict: dictionary containing Github variables. """ if scm.get_user(): repo_id = '{}/{}'.format(scm.get_user(), scm.get_name()) else: repo_id = 'unknown' env = { 'HOME': os.environ['HOME'], 'GITHUB_WORKFLOW': wf.name, 'GITHUB_ACTION': '', 'GITHUB_ACTOR': 'popper', 'GITHUB_REPOSITORY': repo_id, 'GITHUB_EVENT_NAME': wf.on, 'GITHUB_EVENT_PATH': '/tmp/github_event.json', 'GITHUB_WORKSPACE': workspace, 'GITHUB_SHA': scm.get_sha(), 'GITHUB_REF': scm.get_ref() } for e in dict(env): env.update({e.replace('GITHUB_', 'POPPER_'): env[e]}) return env
def run(self, action, skip_clone, skip_pull, skip, workspace, reuse, dry_run, parallel, with_dependencies, skip_secrets_prompt=False): """Run the pipeline or a specific action""" os.environ['WORKSPACE'] = workspace if scm.get_user(): repo_id = '{}/{}'.format(scm.get_user(), scm.get_name()) else: repo_id = 'unknown' if with_dependencies and (not action): log.fail('`--with-dependencies` can be used only with ' 'action argument.') if skip and action: log.fail('`--skip` can\'t be used when action argument ' 'is passed.') new_wf = deepcopy(self.wf) if skip: new_wf = self.wf.skip_actions(skip) if action: new_wf = self.wf.filter_action(action, with_dependencies) new_wf.check_for_unreachable_actions(skip) env = { 'GITHUB_WORKSPACE': workspace, 'GITHUB_WORKFLOW': new_wf.name, 'GITHUB_ACTOR': 'popper', 'GITHUB_REPOSITORY': repo_id, 'GITHUB_EVENT_NAME': new_wf.on, 'GITHUB_EVENT_PATH': '/tmp/github_event.json', 'GITHUB_SHA': scm.get_sha(), 'GITHUB_REF': scm.get_ref() } for e in dict(env): env.update({e.replace('GITHUB_', 'POPPER_'): env[e]}) self.check_secrets(new_wf, dry_run, skip_secrets_prompt) self.download_actions(new_wf, dry_run, skip_clone) self.instantiate_runners(new_wf, workspace, env, dry_run, skip_pull) for s in new_wf.get_stages(): self.run_stage(new_wf, s, reuse, parallel)
def __init__(self, wfile, workspace, quiet, debug, dry_run): wfile = pu.find_default_wfile(wfile) with open(wfile, 'r') as fp: self.wf = hcl.load(fp) self.workspace = workspace self.debug = debug if debug: self.quiet = False else: self.quiet = quiet self.dry_run = dry_run self.actions_cache_path = os.path.join('/', 'tmp', 'actions') self.validate_syntax() self.check_secrets() self.normalize() self.complete_graph() self.env = { 'GITHUB_WORKSPACE': self.workspace, 'GITHUB_WORKFLOW': self.wf['name'], 'GITHUB_ACTOR': 'popper', 'GITHUB_REPOSITORY': '{}/{}'.format(scm.get_user(), scm.get_name()), 'GITHUB_EVENT_NAME': self.wf['on'], 'GITHUB_EVENT_PATH': '/{}/{}'.format(self.workspace, 'workflow/event.json'), 'GITHUB_SHA': scm.get_sha(), 'GITHUB_REF': scm.get_ref() } for e in dict(self.env): self.env.update({e.replace('GITHUB_', 'POPPER_'): self.env[e]})
def get_workflow_env(wf, workspace): if scm.get_user(): repo_id = '{}/{}'.format(scm.get_user(), scm.get_name()) else: repo_id = 'unknown' env = { 'HOME': os.environ['HOME'], 'GITHUB_WORKFLOW': wf.name, 'GITHUB_ACTION': '', 'GITHUB_ACTOR': 'popper', 'GITHUB_REPOSITORY': repo_id, 'GITHUB_EVENT_NAME': wf.on, 'GITHUB_EVENT_PATH': '/tmp/github_event.json', 'GITHUB_WORKSPACE': workspace, 'GITHUB_SHA': scm.get_sha(), 'GITHUB_REF': scm.get_ref() } for e in dict(env): env.update({e.replace('GITHUB_', 'POPPER_'): env[e]}) return env
def test_get_user(self): user = scm.get_user() if self.with_git: self.assertEqual(user, 'cplee') else: self.assertEqual(user, '')
def test_get_user(self): user = scm.get_user() if self.with_git: self.assertEqual(user, 'popperized') else: self.assertEqual(user, '')