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

fix(shell) correct logging output #354

Merged
merged 1 commit into from
Nov 11, 2021
Merged

Conversation

dduportal
Copy link
Contributor

@dduportal dduportal commented Nov 11, 2021

changeGrepVersion
-----------------

**Dry Run enabled**

The shell 🐚 command "./examples/updateCli.generic/shell/target.sh change GNU" ran successfully with the following output:
----
/usr/bin/grep
-rwxr-xr-x  1 root  wheel  173440 Oct 18 05:30 /usr/bin/grep
----
DEBUG: command stderr output was:
----
+ test -n change
+ [[ true == false ]]
+ log 'Variable DRY_RUN is different than false'
+ echo 'Variable DRY_RUN is different than false'
Variable DRY_RUN is different than false
+ [[ change == \c\h\a\n\g\e ]]
+ log 'Change but in dry run'
+ echo 'Change but in dry run'
Change but in dry run
+ command -v grep
++ command -v grep
+ ls -l /usr/bin/grep

----
  • Centralized log method to avoid discrepancy between differents log output for shell

  • Improves log for shell:

    • Stop using the characters βœ”, ⚠ and βœ— for the shell reporting (keeping their usage to the core that reports source/conditions/target)
    • Prints stderr only if the shell command fails (less verbose by default) unless the flag --debug is passed
    • Improved the messages
  • Added a bunch of "generic examples" for shell to allow end to end testing

Click to view the new "normal" output with the generic shell example


+++++++++++
+ PREPARE +
+++++++++++

Repository retrieved: 0


++++++++++++
+ PIPELINE +
++++++++++++



##########################################
# GENERIC EXAMPLE FOR THE SHELL RESOURCE #
##########################################


SOURCES
=======

noDirectoryTiTi
---------------
The shell 🐚 command "ls /titi" exited on error (exit code 1) with the following output:
----
----

command stderr output was:
----
ls: /titi: No such file or directory

----
ERROR: βœ— Shell command exited on error.

default
-------
The shell 🐚 command "./examples/updateCli.generic/shell/source.sh" ran successfully with the following output:
----
GNU
----


CONDITIONS:
===========

withSource
----------
The shell 🐚 command "echo GNU" ran successfully with the following output:
----
GNU
----

noSource
--------
The shell 🐚 command "./examples/updateCli.generic/shell/condition.sh" ran successfully with the following output:
----
/usr/bin/grep
-rwxr-xr-x  1 root  wheel  173440 Oct 18 05:30 /usr/bin/grep
----


TARGETS
========

doesNotChangeAnything
---------------------

**Dry Run enabled**

The shell 🐚 command "./examples/updateCli.generic/shell/target.sh do-not-change GNU" ran successfully with the following output:
----
----
No change detected

changeGrepVersion
-----------------

**Dry Run enabled**

The shell 🐚 command "./examples/updateCli.generic/shell/target.sh change GNU" ran successfully with the following output:
----
/usr/bin/grep
-rwxr-xr-x  1 root  wheel  173440 Oct 18 05:30 /usr/bin/grep
----

=============================

REPORTS:


βœ” SHELL.YAML:
	Sources:
		βœ” [default] (shell)
		βœ— [noDirectoryTiTi] (shell)
	Condition:
		βœ” [noSource] (shell)
		βœ” [withSource] (shell)
	Target:
		⚠ [changeGrepVersion]  (shell)
		βœ” [doesNotChangeAnything]  (shell)



Run Summary
===========
Pipeline(s) run:
  * Changed:	0
  * Failed:	0
  * Skipped:	0
  * Succeeded:	1
  * Total:	1
Click to view the new "debug" output with the generic shell example


+++++++++++
+ PREPARE +
+++++++++++

Repository retrieved: 0


++++++++++++
+ PIPELINE +
++++++++++++



##########################################
# GENERIC EXAMPLE FOR THE SHELL RESOURCE #
##########################################


SOURCES
=======

noDirectoryTiTi
---------------
The shell 🐚 command "ls /titi" exited on error (exit code 1) with the following output:
----
----

command stderr output was:
----
ls: /titi: No such file or directory

----
ERROR: βœ— Shell command exited on error.

default
-------
The shell 🐚 command "./examples/updateCli.generic/shell/source.sh" ran successfully with the following output:
----
GNU
----
DEBUG: command stderr output was:
----
+ grep --version
+ head -n1
+ awk '{print $4}'

----


CONDITIONS:
===========

withSource
----------
The shell 🐚 command "echo GNU" ran successfully with the following output:
----
GNU
----
DEBUG: command stderr output was:
----
----

noSource
--------
The shell 🐚 command "./examples/updateCli.generic/shell/condition.sh" ran successfully with the following output:
----
/usr/bin/grep
-rwxr-xr-x  1 root  wheel  173440 Oct 18 05:30 /usr/bin/grep
----
DEBUG: command stderr output was:
----
+ command -v grep
++ command -v grep
+ ls -l /usr/bin/grep

----


TARGETS
========

doesNotChangeAnything
---------------------

**Dry Run enabled**

The shell 🐚 command "./examples/updateCli.generic/shell/target.sh do-not-change GNU" ran successfully with the following output:
----
----
DEBUG: command stderr output was:
----
+ test -n do-not-change
+ [[ true == false ]]
+ log 'Variable DRY_RUN is different than false'
+ echo 'Variable DRY_RUN is different than false'
Variable DRY_RUN is different than false
+ [[ do-not-change == \c\h\a\n\g\e ]]
+ log 'No changes applied in dry run'
+ echo 'No changes applied in dry run'
No changes applied in dry run
+ exit 0

----
No change detected

changeGrepVersion
-----------------

**Dry Run enabled**

The shell 🐚 command "./examples/updateCli.generic/shell/target.sh change GNU" ran successfully with the following output:
----
/usr/bin/grep
-rwxr-xr-x  1 root  wheel  173440 Oct 18 05:30 /usr/bin/grep
----
DEBUG: command stderr output was:
----
+ test -n change
+ [[ true == false ]]
+ log 'Variable DRY_RUN is different than false'
+ echo 'Variable DRY_RUN is different than false'
Variable DRY_RUN is different than false
+ [[ change == \c\h\a\n\g\e ]]
+ log 'Change but in dry run'
+ echo 'Change but in dry run'
Change but in dry run
+ command -v grep
++ command -v grep
+ ls -l /usr/bin/grep

----

=============================

REPORTS:


βœ” SHELL.YAML:
	Sources:
		βœ” [default] (shell)
		βœ— [noDirectoryTiTi] (shell)
	Condition:
		βœ” [noSource] (shell)
		βœ” [withSource] (shell)
	Target:
		⚠ [changeGrepVersion]  (shell)
		βœ” [doesNotChangeAnything]  (shell)



Run Summary
===========
Pipeline(s) run:
  * Changed:	0
  * Failed:	0
  * Skipped:	0
  * Succeeded:	1
  * Total:	1

Fix #325

Test

To test this pull request, you can run the following commands:

go build -o ./dist/updatecli && ./dist/updatecli --debug diff --config ./examples/updateCli.generic/shell/shell.yaml

@dduportal dduportal added bug Something isn't working condition Modify condition resource resource-shell Resource of kind Shell source target Related to updatecli target labels Nov 11, 2021
@dduportal dduportal marked this pull request as ready for review November 11, 2021 14:15
@dduportal dduportal marked this pull request as draft November 11, 2021 15:25
@dduportal
Copy link
Contributor Author

I'm converting to draft and I'll had another commit: the output for targets is not correct. But the current code is staying

- Fixes updatecli#325 by printing newlines (using better block output with separators)
- Centralized log method to avoid discrepancy between cases
- Only prints error's output as Info when the command fails. Otherwise you need the "debug" flag.

Signed-off-by: Damien Duportal <damien.duportal@gmail.com>
@dduportal
Copy link
Contributor Author

dduportal commented Nov 11, 2021

Ready for review: PR message updated to provide example, how to test and details, rebased and squash from main branch.

Copy link
Member

@olblak olblak left a comment

Choose a reason for hiding this comment

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

It seems good to me

pkg/plugins/shell/errors.go Show resolved Hide resolved
pkg/plugins/shell/main.go Show resolved Hide resolved
@olblak olblak merged commit dc90759 into updatecli:main Nov 11, 2021
@dduportal dduportal deleted the gh-325 branch November 11, 2021 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working condition Modify condition resource resource-shell Resource of kind Shell source target Related to updatecli target
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

New lines not interpreted in shell command output in target when applying
2 participants