github.com/chyroc/anb@v0.3.0/README.md (about)

     1  # anb
     2  
     3  [![codecov](https://codecov.io/gh/chyroc/anb/branch/master/graph/badge.svg?token=Z73T6YFF80)](https://codecov.io/gh/chyroc/anb)
     4  [![go report card](https://goreportcard.com/badge/github.com/chyroc/anb "go report card")](https://goreportcard.com/report/github.com/chyroc/anb)
     5  [![test status](https://github.com/chyroc/anb/actions/workflows/test.yml/badge.svg)](https://github.com/chyroc/anb/actions)
     6  [![Apache-2.0 license](https://img.shields.io/badge/License-Apache%202.0-brightgreen.svg)](https://opensource.org/licenses/Apache-2.0)
     7  [![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go&logoColor=white)](https://pkg.go.dev/github.com/chyroc/anb)
     8  [![Go project version](https://badge.fury.io/go/github.com%2Fchyroc%2Fanb.svg)](https://badge.fury.io/go/github.com%2Fchyroc%2Fanb)
     9  
    10  ![](./header.png)
    11  
    12  ## Install
    13  
    14  By Brew:
    15  
    16  ```shell
    17  brew install chyroc/tap/anb
    18  ```
    19  
    20  By Go:
    21  
    22  ```shell
    23  go get github.com/chyroc/anb
    24  ```
    25  
    26  ## Usage
    27  
    28  ### Task Command Args
    29  
    30  - `id`: unique id for task, can be used with set-output command
    31  - `if`
    32    - `if` args support `exist` function
    33    - and `!`, `&&`, `||` operator
    34  - `dir`: support cmd and local_cmd task
    35  
    36  #### run task if path not exist
    37  
    38  ```yaml
    39  server:
    40    user: root
    41    host: 1.2.3.4
    42  tasks:
    43    - name: "clone app"
    44      if: |
    45        !exist("/app-path")
    46      local_cmd:
    47        - git clone https://github.com/user/repo app-path
    48  ```
    49  
    50  #### run task if path exist && run command in dir
    51  
    52  ```yaml
    53  server:
    54    user: root
    55    host: 1.2.3.4
    56  tasks:
    57    - name: "pull app"
    58      if: exist("/app-path")
    59      dir: app-path
    60      local_cmd:
    61        - git pull
    62  ```
    63  
    64  ### Support Multi Task
    65  
    66  - cmd
    67  - local_cmd
    68  - upload
    69  - download
    70  
    71  #### exec server command
    72  
    73  ```yaml
    74  server:
    75    user: root
    76    host: 1.2.3.4
    77  tasks:
    78    - cmd: ls
    79    - name: exec commands
    80      cmd:
    81        - ls
    82        - ls -alh
    83  ```
    84  
    85  #### exec local command
    86  
    87  ```yaml
    88  server:
    89    user: root
    90    host: 1.2.3.4
    91  tasks:
    92    - name: exec local command
    93      local_cmd: go build -o /tmp/bin-file main.go
    94    - name: exec server commands
    95      cmd:
    96        - ls
    97  ```
    98  
    99  #### upload files from local to server
   100  
   101  ```yaml
   102  server:
   103    user: root
   104    host: 1.2.3.4
   105  tasks:
   106    - name: "upload file"
   107      upload:
   108        src: README.md
   109        dest: /tmp/README.md
   110    - name: "upload dir"
   111      upload:
   112        src: ./config/
   113        dest: /tmp/config/
   114  ```
   115  
   116  #### download files from server to local
   117  
   118  ```yaml
   119  server:
   120    user: root
   121    host: 1.2.3.4
   122  tasks:
   123    - name: "download file"
   124      upload:
   125        src: /tmp/server-README.md
   126        dest: /tmp/local-README.md
   127    - name: "upload dir"
   128      upload:
   129        src: /tmp/server-config/
   130        dest: /tmp/local-config/
   131  ```