Skip to content

Commit

Permalink
update run pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbo committed May 1, 2024
1 parent 5ae3e9e commit 51b1cb2
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 252 deletions.
64 changes: 33 additions & 31 deletions src/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ def build(

logger = get_logger('main')

def run_step(returncode, msg):
if returncode != 0:
def run_step(step, msg, *args, **kwargs):
try:
step(*args, **kwargs)
except Exception:
raise StepException(msg)

logger.info(f'Running build for {owner}/{repository}/{branch}')
Expand Down Expand Up @@ -124,8 +126,9 @@ def run_step(returncode, msg):
# FETCH
#
run_step(
fetch_repo(owner, repository, branch, github_token),
'There was a problem fetching the repository, see the above logs for details.'
fetch_repo,
'There was a problem fetching the repository, see the above logs for details.',
owner, repository, branch, github_token,
)

commit_sha = fetch_commit_sha(CLONE_DIR_PATH)
Expand All @@ -146,63 +149,62 @@ def run_step(returncode, msg):

if federalist_config.full_clone():
run_step(
update_repo(CLONE_DIR_PATH),
'There was a problem updating the repository, see the above logs for details.'
update_repo,
'There was a problem updating the repository, see the above logs for details.',
CLONE_DIR_PATH,
)

##
# BUILD
#
run_step(
setup_node(
federalist_config.should_cache(),
bucket,
s3_client,
post_metrics,
status_callback,
),
'There was a problem setting up Node, see the above logs for details.'
setup_node,
'There was a problem setting up Node, see the above logs for details.',
federalist_config.should_cache(),
bucket,
s3_client,
post_metrics,
status_callback,
)

# Run the npm `federalist` task (if it is defined)
run_step(
run_build_script(
branch, owner, repository, site_prefix, baseurl, decrypted_uevs
),
'There was a problem running the federalist script, see the above logs for details.'
run_build_script,
'There was a problem running the federalist script, see the above logs for details.',
branch, owner, repository, site_prefix, baseurl, decrypted_uevs,
)

# Run the appropriate build engine based on generator
if generator == 'jekyll':
run_step(
setup_ruby(federalist_config.should_cache(), post_metrics, status_callback),
'There was a problem setting up Ruby, see the above logs for details.'
setup_ruby,
'There was a problem setting up Ruby, see the above logs for details.',
federalist_config.should_cache(), post_metrics, status_callback,
)

run_step(
setup_bundler(federalist_config.should_cache(), bucket, s3_client),
'There was a problem setting up Bundler, see the above logs for details.'
setup_bundler,
'There was a problem setting up Bundler, see the above logs for details.',
federalist_config.should_cache(), bucket, s3_client,
)

run_step(
build_jekyll(
branch, owner, repository, site_prefix, baseurl, config, decrypted_uevs
),
'There was a problem running Jekyll, see the above logs for details.'
build_jekyll,
'There was a problem running Jekyll, see the above logs for details.',
branch, owner, repository, site_prefix, baseurl, config, decrypted_uevs,
)

elif generator == 'hugo':
# extra: --hugo-version (not yet used)
run_step(
download_hugo(),
download_hugo,
'There was a problem downloading Hugo, see the above logs for details.'
)

run_step(
build_hugo(
branch, owner, repository, site_prefix, baseurl, decrypted_uevs
),
'There was a problem running Hugo, see the above logs for details.'
build_hugo,
'There was a problem running Hugo, see the above logs for details.',
branch, owner, repository, site_prefix, baseurl, decrypted_uevs,
)

elif generator == 'static':
Expand Down
9 changes: 4 additions & 5 deletions src/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setuser():
os.setuid(pwd.getpwnam('customer').pw_uid)


def run(logger, command, cwd=None, env=None, shell=False, check=False, node=False, ruby=False, return_output=False): # noqa: E501
def run(logger, command, cwd=None, env=None, shell=False, check=False, node=False, ruby=False):
'''
Run an OS command with provided cwd or env, stream logs to logger, and return the exit code.
Expand Down Expand Up @@ -68,10 +68,9 @@ def run(logger, command, cwd=None, env=None, shell=False, check=False, node=Fals
logger.info(line)
output.write(line)

if check and p.returncode:
raise subprocess.CalledProcessError(p.returncode, command)

if return_output:
if check:
if p.returncode:
raise subprocess.CalledProcessError(p.returncode, command)
return output

return p.returncode
Expand Down
Loading

0 comments on commit 51b1cb2

Please sign in to comment.