8000 Enable folding sections when run under Travis by cognifloyd · Pull Request #2851 · ansible/molecule · GitHub
[go: up one dir, main page]

Skip to content

Enable folding sections when run under Travis - #2851

Closed
cognifloyd wants to merge 2 commits into
ansible:masterfrom
cognifloyd:travis-folding
Closed

cognifloyd wants to merge 2 commits into
ansible:masterfrom
cognifloyd:travis-folding

Conversation

@cognifloyd
Copy link
Copy Markdown
Contributor

Add output when molecule is running in travis-ci to make the logs easier to jump through.
Travis log folding is explained here.

PR Type

  • Feature Pull Request

@cognifloyd
Copy link
Copy Markdown
Contributor Author

Test failures are unrelated to this change.

@ssbarnea
ssbarnea self-requested a review September 30, 2020 07:58
@ssbarnea ssbarnea left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice feature, sadly is not yet a generic terminal feature. What worries me is that in case of exceptions, the end section will never be printed, likely causing other issues, especially in cases where multiple commands are executed and some would fail.

Can we maybe catch the exceptions print them and the done bit end and raise them back?

I am also inclined to opt-in for an implementation using a decorator if possible? Using a decorator should make it much easier to wrap the start/end of it, don't you think?

@ssbarnea ssbarnea changed the title Travis folding Enable folding sections when run under Travis Sep 30, 2020
@greg-hellings
Copy link
Copy Markdown
Contributor

This bit concerns me, "While not officially documented, I think you can rely on this behavior in the foreseeable future." But that was written in 2014 and appears to still be valid. So it doesn't concern me that much.

Does it make sense to provide an output mechanism like this specifically just for one CI provider? Do others have similar functionality that we ought to incorporate?

I have no issues with the structure of the code, unless we think we're going to be asked or expected to expand this functionality to support a bunch of other providers.

@cognifloyd
cognifloyd commented Sep 30, 2020 •
Copy link
Copy Markdown
Contributor Author

Can we maybe catch the exceptions print them and the done bit end and raise them back?

I am also inclined to opt-in for an implementation using a decorator if possible? Using a decorator should make it much easier to wrap the start/end of it, don't you think?

I don't like requiring all of the commands to add an extra print function at the end. Doing this in a decorator (edit: a decorator around the Base.execute() function) would increase the complexity of the Base command subclasses even more.

What if I modified execute_scenario instead, wrapping the call to execute_subcommand in a try/finally block to print the end of the fold line. Or it could be a func wrapper around execute_subcommand. I think I'll try a functools wrapper around execute_subcommand.

@cognifloyd
Copy link
Copy Markdown
Contributor Author

@ssbarnea Using a decorator seems to be much simpler. Thanks for the idea. What do you think?

@greg-hellings if we do get requests to add something like this for other CI runners (I haven't seen a feature like this anywhere else), then the new wrapper isolates the CI-specific code more so that it's easy to tell what it is doing.

@cognifloyd
cognifloyd force-pushed the travis-folding branch 2 times, most recently from 86daa5c to 14b16c7 Compare September 30, 2020 22:55
@cognifloyd
Copy link
Copy Markdown
Contributor Author

To test this, I just started upgrading a molecule scenario to use molecule 3.1(ish) - my upgrade is not complete, but it shows how the folding looks:
https://travis-ci.com/github/cognifloyd/community.mongodb/builds/187516426

Sadly, it is not very informative at the folds. I need to play with that to see if there's a way to describe the fold when it is collapsed.

@cognifloyd
cognifloyd commented Oct 1, 2020 •
Copy link
Copy Markdown
Contributor Author

@cognifloyd
cognifloyd force-pushed the travis-folding branch 5 times, most recently from b7da42e to 72b3f14 Compare October 1, 2020 03:41
@cognifloyd
Copy link
Copy Markdown
Contributor Author

OK. So, it's bike-shedding time:

Text

  1. Molecule Scenario: 'default' Action: 'converge'
  2. Molecule - Scenario: 'default' - Action: 'converge'
  3. Molecule | Scenario: 'default' | Action: 'converge'
  4. Molecule --> Scenario: 'default' --> Action: 'converge'
  5. --> Scenario: 'default' --> Action: 'converge'

Color

Yellow bold (33;1m): Current color
Selection_089

Yellow normal (33m):
Selection_088

White bold (37;1m):
Selection_084

White normal (37m):
Selection_085

Cyan bold (36;1m):
Selection_086

Cyan normal (36m): oops. I was hovering when I took this screenshot
Selection_087

@cognifloyd
Copy link
Copy Markdown
Contributor Author

My top 3:

  1. Cyan bold
  2. White normal
  3. Yellow bold

Comment thread molecule/command/base.py Resolved
@ssbarnea
ssbarnea commented Oct 1, 2020
Copy link
Copy Markdown
Member

I would not spend much time investing in colorama as I am already working on a big change that drops it and switching to https://github.com/willmcgugan/rich

@cognifloyd
cognifloyd force-pushed the travis-folding branch 3 times, most recently from 4e18899 to 9e6b52b Compare October 1, 2020 15:55
@cognifloyd
cognifloyd commented Oct 1, 2020 •
Copy link
Copy Markdown
Contributor Author

Yes, the colorama escape sequence works just fine for Travis. Feel free to replace it with rich when you make the switch.

I went with Bold Cyan with the text Molecule --> Scenario: 'default' --> Action: 'converge':
Selection_090

So, unless anyone else wants to join in the bike-shedding, I think this is ready to merge.

@cognifloyd
cognifloyd commented Oct 1, 2020 •
Copy link
Copy Markdown
Contributor Author

I squashed and rebased.

Plus I've also prepared a 2.22 backport. Will there be a 2.23 release at some point?
looks like the 2.22 CI config is out of date and therefore broken

@ssbarnea ssbarnea left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That change is far from ready, being broken and not tested:

$ molecule list                                                                                                                 [18:36:45]
--> Found config file /Users/ssbarnea/.config/molecule/config.yml
travis_fold:start:default.listMolecule --> Scenario: 'default' --> Action: 'list'
travis_fold:end:default.list
Traceback (most recent call last):
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/bin/molecule", line 33, in <module>
    sys.exit(load_entry_point('molecule', 'console_scripts', 'molecule')())
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/ssbarnea/c/a/molecule/molecule/command/list.py", line 111, in list
    statuses.extend(base.execute_subcommand(scenario.config, subcommand))
TypeError: 'NoneType' object is not iterable
$ molecule list                                                                                                                 [18:36:45]
--> Found config file /Users/ssbarnea/.config/molecule/config.yml
travis_fold:start:default.listMolecule --> Scenario: 'default' --> Action: 'list'
travis_fold:end:default.list
Traceback (most recent call last):
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/bin/molecule", line 33, in <module>
    sys.exit(load_entry_point('molecule', 'console_scripts', 'molecule')())
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/ssbarnea/.pyenv/versions/3.8.2/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/ssbarnea/c/a/molecule/molecule/command/list.py", line 111, in list
    statuses.extend(base.execute_subcommand(scenario.config, subcommand))
TypeError: 'NoneType' object is not iterable

Uses a function wrapper around execute_subcommand
Comment thread molecule/command/base.py
)
)
try:
return func(config, subcommand)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I missed this return here. Added. Please try again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For background, I discovered that I missed this in the 2.22 branch, but didn't check to see if it was also required for 3.x. Oops.
See: cognifloyd@6ddc9b2

@cognifloyd
cognifloyd force-pushed the travis-folding branch 4 times, most recently from 041792d to 903762a Compare October 4, 2020 04:22
@cognifloyd
cognifloyd commented Oct 4, 2020 •
Copy link
Copy Markdown
Contributor Author

I parametrized the unit test for execute_subcommand so that it tests as if running on Travis as well.
Do you want any functional or other tests for this? I suppose we could run this and check that the prints happen, but I'm not sure that has much value.
We could also re-run some of the functional or integration tests on Travis if it's worth adding travis to the test infra.

@cognifloyd
cognifloyd requested a review from ssbarnea October 4, 2020 04:39
@ssbarnea
Copy link
Copy Markdown
Member

Please rebase it, I moved molecule/ under lib/molecule. Sorry for the inconvenience.

@ssbarnea
Copy link
Copy Markdown
Member

Closing due to lack of updates. Ping me if you want to reopen it.

@ssbarnea ssbarnea closed this Oct 23, 2020
@cognifloyd
Copy link
Copy Markdown
Contributor Author

revisiting now. Please reopen.

@cognifloyd
Copy link
Copy Markdown
Contributor Author

Here's what it looks like with the latest rich formatted output instead of straight colorama.
image

@cognifloyd
Copy link
Copy Markdown
Contributor Author

Re-submitted PR as #2967

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

0