1
0
Fork 0
mirror of synced 2024-12-04 13:25:34 -05:00

Compare commits

...

5 commits

Author SHA1 Message Date
Clumsy-Coder
c118227942
Merge 974156ccde into 8d94c6ec1a 2024-11-28 23:53:16 +00:00
Anish Athalye
8d94c6ec1a Disable coverage status checks 2024-11-21 17:23:21 +05:30
Anish Athalye
2294ac78f8 Update actions 2024-11-21 17:13:19 +05:30
Clumsy-Coder
974156ccde docs(readme): add docs for using shell conditionally
## what
  - add documentation on using shell command conditionally

  ## how

  ## why

  ## where

  ## usage
2022-08-11 21:12:47 -06:00
Clumsy-Coder
25ef5d5a5f feat(shell): run shell command conditionally
## what
  - add feature to run shell command (optionally)

  ## how
  - the shell directive will check if the 'if' property is available.
    If it is, it will run the command in 'if' property.
    If the command results in a return 0 code or 'true', then the
    'command' property will run.
    If the condition to run the command is a non 0 code or 'false',
      the shell command won't run
  - dotbot config example:
    ```yaml
    - shell:
        - command: echo "this is running on a MacOS"
          if: uname -s | grep -i "Darwin"
    ```
  - dotbot config example: skipping command if false
    ```yaml
    - shell:
        - command: echo "This command should be skipped"
          if: false
    ```

  ## why
  - can run the shell command conditionally
  - can use multiple dotbot configs to run different OS
    - Ex: incorporating it in https://github.com/ecarlson94/dotbot-template

  ## where
  - file changed in `./dotbot/plugins/shell.py`

  ## usage
  Create dotbot config
    ```yaml
    - shell:
        - command: echo "this is running on a MacOS"
          if: uname -s | grep -i "Darwin"
    ```

    ```yaml
    - shell:
        - command: echo "This command should be skipped"
          if: false
    ```
2022-08-11 21:10:50 -06:00
4 changed files with 47 additions and 2 deletions

View file

@ -47,11 +47,14 @@ jobs:
run: | run: |
python -m tox python -m tox
python -m tox -e coverage_report python -m tox -e coverage_report
- uses: codecov/codecov-action@v3 - uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
fmt: fmt:
name: Format name: Format
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: psf/black@stable - uses: psf/black@stable
- uses: isort/isort-action@v1 - uses: isort/isort-action@v1

View file

@ -336,6 +336,7 @@ fine-grained control.
| `stdin` | Allow a command to read from standard input (default: false) | | `stdin` | Allow a command to read from standard input (default: false) |
| `stdout` | Show a command's output from stdout (default: false) | | `stdout` | Show a command's output from stdout (default: false) |
| `stderr` | Show a command's error output from stderr (default: false) | | `stderr` | Show a command's error output from stderr (default: false) |
| `if` | Run command if a condition is true (default: true) (optional) |
Note that `quiet` controls whether the command (a string) is printed in log Note that `quiet` controls whether the command (a string) is printed in log
output, it does not control whether the output from running the command is output, it does not control whether the output from running the command is
@ -360,6 +361,19 @@ printed (that is controlled by `stdout` / `stderr`). When a command's `stdin` /
stderr: true stderr: true
``` ```
##### Running shell command conditionally
```yaml
- shell:
- command: apt update && apt upgrade -y
if: lsb_release -i | grep -io 'debian'
description: Update APT package repository
- command: dnf update -y
if: lsb_release -i | grep -io 'fedora'
description: Update DNF package repository
```
### Clean ### Clean
Clean commands specify directories that should be checked for dead symbolic Clean commands specify directories that should be checked for dead symbolic

4
codecov.yml Normal file
View file

@ -0,0 +1,4 @@
coverage:
status:
project: off
patch: off

View file

@ -34,6 +34,30 @@ class Shell(Plugin):
stdout = item.get("stdout", stdout) stdout = item.get("stdout", stdout)
stderr = item.get("stderr", stderr) stderr = item.get("stderr", stderr)
quiet = item.get("quiet", quiet) quiet = item.get("quiet", quiet)
# run shell command if the 'if' key is present
# Ex:
# - shell:
# - command: echo "This computer is a Mac"
# if: uname -s | grep -i "Darwin"
#
# Ex: skipping shell command
# - shell:
# - command: echo "skip this shell command"
# if: false
if "if" in item:
run_if_result = dotbot.util.shell_command(
str(item["if"]), # this to make sure python doesn't run it. Had a odd behaviour with having the value 'false'. Check Pull Request #321
cwd=self._context.base_directory(),
enable_stdin=False,
enable_stdout=False,
enable_stderr=stderr,
)
# if the condition to run the command is false,
# skip running the command
if run_if_result != 0:
continue
elif isinstance(item, list): elif isinstance(item, list):
cmd = item[0] cmd = item[0]
msg = item[1] if len(item) > 1 else None msg = item[1] if len(item) > 1 else None