Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce before and after steps for a task. #56

Merged
merged 3 commits into from
Jun 20, 2022

Conversation

jenpet
Copy link
Contributor

@jenpet jenpet commented Jun 9, 2022

Hey guys, I fiddled around with some before and after functionality I could use within robo. Hopefully this finds a way into master. Let me know what you think, will update the docs after we're all happy with it :-)

A task is now able to have several steps which are executed before and after its own execution. The config syntax for this is the same as for the task itself: 'command', 'script' and 'exec' are supported. A task and all of the preceeding steps will still be executed even when the before steps are failing.

Running a task now returns a list of errors which are logged according to their occurrence for easier troubleshooting.

A task is now able to have several steps which are executed before and after its own execution. The config syntax for this is the same as for the task itself: 'command', 'script' and 'exec' are supported. A task and all of the preceeding steps will still be executed even when the before steps are failing.

Running a task now returns a list of errors which are logged according to their occurrence for easier troubleshooting.
@jenpet jenpet force-pushed the feature/before_after_steps branch from 97962fd to d3446af Compare June 9, 2022 21:19
Preceeding to _every_ task, all before steps will be eecuted and accordingly succeeding to all tasks all after steps.
@jenpet
Copy link
Contributor Author

jenpet commented Jun 13, 2022

@yields ping 😊

Copy link
Collaborator

@yields yields left a comment

Choose a reason for hiding this comment

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

LGTM, seems like it just needs some docs to match the rest of the codebase.

interpolation/interpolation.go Show resolved Hide resolved
task/task.go Show resolved Hide resolved
task/task.go Show resolved Hide resolved
task/task.go Show resolved Hide resolved
@jenpet
Copy link
Contributor Author

jenpet commented Jun 14, 2022

No problem, will do so. Just wanted to make sure that you guys are ok with the feature(s).

@jenpet
Copy link
Contributor Author

jenpet commented Jun 19, 2022

@yields updated the code documentation and the readme accordingly. If you are happy with it, I will squash the commits into a single reasonable commit.

@jenpet jenpet requested a review from yields June 20, 2022 07:56
Copy link
Collaborator

@yields yields left a comment

Choose a reason for hiding this comment

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

Awesome! -- thanks for the extra docs :)

@yields yields merged commit a1ab412 into tj:master Jun 20, 2022
@CGamesPlay
Copy link
Contributor

Hi guys, I just submitted #58 and was looking over this code. I just wanted to provide this commentary because the feature isn't technically released yet and there's no better time to fix it than before it's broken!

  1. The example documentation suggests using exec: git pull -r as a before subtask, which would prevent all of the following commands from running, because robo wouldn't be running after that happened. Also, the main task in the example is an exec, which also means that the after subtask couldn't possibly run, either. So, this feature is effectively incompatible with exec tasks.
  2. The ability to define these before and after commands on a single task does not make sense to me, because for both script and command tasks, you could trivially have put that code into the actual task. This means that the only viable use-case for this feature is to define before/after subtasks on the entire robo.yml file.
  3. The only allowed error handling mode is "report but continue". This frankly seems like the least-useful default mode to use, as I can't imagine a use-case where I want to run my main task if my setup code fails. Similarly, running my after task after my main task fails feels like it actually makes troubleshooting more difficult, not less.

Now, what does this feature give users of robo? Remember that per-task before/after functionality is trivial to move into the main task. The global before-after tasks could be moved into an external wrapper script, but then you lose the ability to interpolate variables in them, which was presumably a motivating factor for this feature. Fortunately, it's very simple to accomplish this using robo's pre-existing composition feature. I've included a rewritten version of this below. Note that the UX is different, we have to run robo wrap foo instead of robo foo. However, this could be accomplished using an alias or shell script to even avoid this problem. The advantage of this wrapper is that the user gets to define their own error handling. Adding set -e to any of the commands means that you get "report and fail" error handling semantics. Other combinations are available too, because it's just a shell script (e.g. "report but continue" on before task and "report and fail" on main task).

I don't mean to come in and poo-poo @jenpet's hard work, so I'm sorry that all I have to offer right now is negative feedback. But I think that this feature adds substantial complexity to robo that wasn't fully considered with the feature was added.

foo:
  command: |
    echo "local before {{ .foo }}"
    git status
    echo "local after"

wrap:
  command: |
    echo "global before {{ .foo }}"
    robo "$@"
    /global/after-script.sh

variables:
  foo: bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants