Skip to content

Conversation

@torresxb1
Copy link
Contributor

Issue #, if available:

Description of changes:
Currently there are a few nested conditions in the workflow. This PR refactors to remove some nesting and try to simplify the logic.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

source_dir, artifacts_dir, scratch_dir, manifest_path, osutils, subprocess_npm
)

def actions_without_bundler(self, source_dir, artifacts_dir, scratch_dir, manifest_path, osutils, subprocess_npm):
Copy link
Contributor Author

@torresxb1 torresxb1 Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was originally meant for when the workflow would have actions_with_bundler (for esbuild) and actions_without_bundler. But the bundler actions were split into a separate workflow (esbuild), so there's not much use for having actions_without_bundler in a separate function. So I just moved the logic into the workflow constructor.

Comment on lines -130 to -133
LOG.info(
"download_dependencies is False and dependencies_dir is None. Copying the source files into the "
"artifacts directory. "
)
Copy link
Contributor Author

@torresxb1 torresxb1 Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this message was a bit weird and not totally accurate, so I removed it. The message could be printed even if dependencies_dir is not None (if combine_dependencies is False) . Let me know if you think I should bring this message back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the conditions that lead to this message being output is not a valid SAM CLI use case anyway (shouldn't be very common):
https://github.com/aws/aws-lambda-builders/pull/272/files#r701280071

return

# if we downloaded dependencies, update dependencies_dir
if self.download_dependencies:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we branching on the same condition twice?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other general comment is we have more than a few branches, we should go down a handler route where we mutate on a a given object all the way through.

eg: self.actions is the one we mutate in this workflow, something like below would be useful to grok through it.

for action_mapper in action_mappers:
    action_mapper.apply(*args, **kwargs)

Copy link
Contributor Author

@torresxb1 torresxb1 Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we branching on the same condition twice?

The first time it doesn't depend on self.dependencies_dir. The second time we can assume we have self.dependencies_dir (since we checked it before).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L77 and L99

the conditions are the same, what am I missing?

Copy link
Contributor Author

@torresxb1 torresxb1 Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part in the middle of those:

if not self.dependencies_dir:
self.actions += artifacts_cleanup_actions
return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first time it doesn't care about, or depend on, self.dependencies_dir. The second time, since we have checked dependencies_dir, we can assume we have it and we don't have to check for it again. Otherwise it would require some conditional nesting or repetitive conditions, which is what I'm trying to refactor out here 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to me this is not intuitive and requires a further refactor.

self.actions += artifacts_cleanup_actions
and
self.actions += artifacts_cleanup_actions
is also repeated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ the above is also due to something similar. One is performed when there's no dependencies dir and one is performed when there is.

To me the refactor is easier to read than before, but let me know if you disagree. Also open to suggestions on how to further refactor.

@sriram-mv
Copy link
Contributor

Note: I still believe this requires an overall refactor, there are repeated statements and branching logic that looks identical even though the state that they operate on could be different.

@sriram-mv sriram-mv self-requested a review February 22, 2023 17:56
@torresxb1
Copy link
Contributor Author

Created an internal ticket to suggest further, bigger, refactoring improvements.
Merging this one.

@torresxb1 torresxb1 merged commit 5fb3368 into aws:develop Feb 22, 2023
@torresxb1 torresxb1 deleted the refactor-node-npm-workflow branch February 22, 2023 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants