kiegroup / github-action-build-chain

86 stars 24 forks source link

implement `resume` subcommand #451

Closed shubhbapna closed 1 year ago

shubhbapna commented 1 year ago

fixes #450

Overview

This PR implements a basic resume command. Whenever build-chain runs in CLI mode it will store all its state in a json file. This file is later on picked up by the resume command which continues the build after reconstructing the build-chain's previous state. For example if I run:

build-chain build cross_pr -f definition_file -u url

and the command fails to build the 3rd project then when I run build-chain resume in the same workspace like this:

build-chain build resume

build-chain will continue its execution from the 3rd project

I can also specify the workspace by passing the -w, --workspace option

build-chain build resume -w bc

Implementation details

After analyzing all the services, the only ones needed for reconstruction of a state are: configuration service, flow service and checkout service

These services implement a Serializable interface which makes it super simple to serialize them to JSON using the toJSON method and deserialize the JSON back into the object using the fromJSON static method. Furthermore checkout and flow service maintain a saved state as well as current state variable to keep track of the new state they are producing as well as the previous one they got back from the state file. The new state is used to update the state file again.

I chose not to serialize GitTokenService since storing tokens in plain text is not a good idea. Because of this, when running the resume command the user has to pass the tokens again or make sure they are available as env variables.

shubhbapna commented 1 year ago

I would suggest to use build resume instead of tool it looks like more intuitive to me thinking wdyt guys?

@Ginxo Adding resume as a build command might be tough to integrate since build commands need to have a certain flow. Although I could do something which is bit hacky:

  1. externally the user will run build-chain build resume
  2. internally when parsing the arguments, if the arg parser sees that it is a resume command it will switch to "tool" mode

wdyt?