aweris / gale

GitHub Action Local Executor
Apache License 2.0
142 stars 4 forks source link

Refactor `Step` Interface to Modularize Pre and Post Execution Hooks #99

Closed aweris closed 10 months ago

aweris commented 10 months ago

Description

The current step interface in gale encompasses setup, pre, main and post execution methods and their conditional checks. Not all types of steps within the application make use of the pre and post-execution methods, leading to unnecessary boilerplate code and potential confusion.

A modular approach, potentially using hooks or functional interfaces, may help streamline the implementation, making it more intuitive and reducing redundancies.

Current Behavior:

Desired Behavior:

High-Level Suggestions:

  1. Functional Interface Decomposition: Break down the Step interface into smaller functional interfaces, such as PreExecutable, PostExecutable, etc. This allows steps to implement only the interfaces that are relevant to their operation.

  2. Hook-based System: Instead of having separate methods in the interface, consider having a central execution method that uses hooks or listeners. These hooks can be registered dynamically based on the type of step. For instance, if a step has pre-execution logic, it can register a pre-execution hook.

  3. Base and Extended Step Classes: Another object-oriented approach could involve having a base Step class with the most common methods and then extended classes or interfaces that add pre and post-execution capabilities. Steps can then extend or implement as needed.

  4. Decorator Pattern: Use the decorator pattern to add pre and post-execution capabilities around a core step. This allows for flexible composition and avoids altering existing code.

Tasks:

  1. Review the current usage and necessity of the Step interface's methods across different step types
  2. Decide on the most suitable approach (from the suggestions or another identified method)
  3. Implement the chosen approach and refactor existing steps to align with the new structure.
  4. Ensure comprehensive tests to validate that the steps function correctly post-refactoring.