From d893e307e8ab09d979103c6ab20863ab46977bff Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 25 Sep 2021 00:40:07 +0300 Subject: [PATCH 1/5] BIP-5 Print actual recipe executing time in terminal renderer --- .github/workflows/ci.yml | 2 +- cli/cli.go | 2 +- render/renderer_terminal.go | 59 +++++++++++++++++++++++++++++++++---- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83bb651c..7f340b8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: '10.x' + node-version: '14.x' - name: Install codeclimate-test-reporter run: npm install -g codeclimate-test-reporter diff --git a/cli/cli.go b/cli/cli.go index 4b1e5f1a..9a0205a8 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -37,7 +37,7 @@ import ( // Application info const ( APP = "bibop" - VER = "4.7.0" + VER = "4.8.0" DESC = "Utility for testing command-line tools" ) diff --git a/render/renderer_terminal.go b/render/renderer_terminal.go index bdfb266b..6d389c96 100644 --- a/render/renderer_terminal.go +++ b/render/renderer_terminal.go @@ -24,11 +24,21 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // +const ( + _ANIMATION_STARTED uint8 = 1 + _ANIMATION_STOP uint8 = 2 +) + +// ////////////////////////////////////////////////////////////////////////////////// // + // TerminalRenderer renders info to terminal type TerminalRenderer struct { isStarted bool isFinished bool start time.Time + + curAction *recipe.Action + syncChan chan uint8 } // ////////////////////////////////////////////////////////////////////////////////// // @@ -101,15 +111,19 @@ func (rr *TerminalRenderer) ActionStarted(a *recipe.Action) { return } - rr.renderTmpMessage( - " {s-}└─{!} {s~-}● {!}"+rr.formatActionName(a)+" {s}%s{!} {s-}[%s]{!}", - rr.formatActionArgs(a), - rr.formatDuration(time.Since(rr.start), false), - ) + rr.curAction = a + rr.syncChan = make(chan uint8) + + go rr.renderCurrentActionProgress() + + // Wait until animation started + <-rr.syncChan } // ActionFailed prints info about failed action func (rr *TerminalRenderer) ActionFailed(a *recipe.Action, err error) { + rr.syncChan <- _ANIMATION_STOP + rr.renderTmpMessage( " {s-}└─{!} {r}✖ {!}"+rr.formatActionName(a)+" {s}%s{!}", rr.formatActionArgs(a), @@ -124,6 +138,8 @@ func (rr *TerminalRenderer) ActionFailed(a *recipe.Action, err error) { // ActionDone prints info about successfully finished action func (rr *TerminalRenderer) ActionDone(a *recipe.Action, isLast bool) { + rr.syncChan <- _ANIMATION_STOP + if isLast { rr.renderTmpMessage( " {s-}└─{!} {g}✔ {!}"+rr.formatActionName(a)+" {s}%s{!}", @@ -252,6 +268,39 @@ func (rr *TerminalRenderer) renderTmpMessage(f string, a ...interface{}) { fmtc.Printf("{s}…{!}") } +// renderCurrentActionProgress renders info about current action +func (rr *TerminalRenderer) renderCurrentActionProgress() { + frame := 0 + + ticker := time.NewTicker(time.Second / 4) + defer ticker.Stop() + + rr.syncChan <- _ANIMATION_STARTED + + for { + select { + case <-rr.syncChan: + return + case <-ticker.C: + dot := " " + frame++ + + switch frame { + case 2: + dot = "{s-}●{!}" + case 3: + dot, frame = "{s}●{!}", 0 + } + + rr.renderTmpMessage( + " {s-}└─{!} "+dot+" {!}"+rr.formatActionName(rr.curAction)+" {s}%s{!} {s-}[%s]{!}", + rr.formatActionArgs(rr.curAction), + rr.formatDuration(time.Since(rr.start), false), + ) + } + } +} + // renderMessage prints message limited by window size func (rr *TerminalRenderer) renderMessage(f string, a ...interface{}) { ww := window.GetWidth() From 32007edad8ef405c07181da77830ea8bf691609c Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 25 Sep 2021 00:47:32 +0300 Subject: [PATCH 2/5] Align all strcuts with Aligo --- cli/executor/executor.go | 2 +- recipe/recipe.go | 19 ++++++++++--------- render/renderer_json.go | 8 ++++---- render/renderer_terminal.go | 7 +++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cli/executor/executor.go b/cli/executor/executor.go index 6cebefa9..a62343f2 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -55,9 +55,9 @@ type Executor struct { // ExecutorConfig contains executor configuration type Config struct { + ErrsDir string Quiet bool DisableCleanup bool - ErrsDir string } // ValidationConfig is config for validation diff --git a/recipe/recipe.go b/recipe/recipe.go index a6e0c428..221b84ff 100644 --- a/recipe/recipe.go +++ b/recipe/recipe.go @@ -27,44 +27,45 @@ const TEARDOWN_TAG = "teardown" // ////////////////////////////////////////////////////////////////////////////////// // // Recipe contains recipe data +// aligo:ignore type Recipe struct { + Packages []string // Package list + Commands []*Command // Commands File string // Path to recipe Dir string // Working dir + Delay float64 // Delay between commands UnsafeActions bool // Allow unsafe actions RequireRoot bool // Require root privileges FastFinish bool // Fast finish flag LockWorkdir bool // Locking workdir flag Unbuffer bool // Disabled IO buffering HTTPSSkipVerify bool // Disable certificate verification - Delay float64 // Delay between commands - Packages []string // Package list - Commands []*Command // Commands variables map[string]*Variable // Variables } // Command contains command with all actions +// aligo:ignore type Command struct { + Actions []*Action // Slice with actions User string // User name Tag string // Tag Cmdline string // Command line Description string // Description - Actions []*Action // Slice with actions + Recipe *Recipe // Link to recipe Line uint16 // Line in recipe props map[string]interface{} // Properties - - Recipe *Recipe // Link to recipe } // Action contains action name and slice with arguments type Action struct { - Name string // Name Arguments []string // Arguments - Negative bool // Is negative + Name string // Name + Command *Command // Link to command Line uint16 // Line in recipe + Negative bool // Negative check flag - Command *Command // Link to command } type Variable struct { diff --git a/render/renderer_json.go b/render/renderer_json.go index 70d9d68b..762ff60d 100644 --- a/render/renderer_json.go +++ b/render/renderer_json.go @@ -41,20 +41,20 @@ type recipeInfo struct { } type command struct { + Actions []*action `json:"actions"` User string `json:"user,omitempty"` Tag string `json:"tag,omitempty"` Cmdline string `json:"cmdline"` Description string `json:"description"` - IsFailed bool `json:"is_failed"` ErrorMessage string `json:"error_message,omitempty"` - Actions []*action `json:"actions"` + IsFailed bool `json:"is_failed"` } type action struct { - Name string `json:"name"` Arguments []string `json:"arguments"` - IsFailed bool `json:"is_failed"` + Name string `json:"name"` ErrorMessage string `json:"error_message,omitempty"` + IsFailed bool `json:"is_failed"` } // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/render/renderer_terminal.go b/render/renderer_terminal.go index 6d389c96..3f671ff7 100644 --- a/render/renderer_terminal.go +++ b/render/renderer_terminal.go @@ -33,12 +33,11 @@ const ( // TerminalRenderer renders info to terminal type TerminalRenderer struct { + start time.Time + curAction *recipe.Action + syncChan chan uint8 isStarted bool isFinished bool - start time.Time - - curAction *recipe.Action - syncChan chan uint8 } // ////////////////////////////////////////////////////////////////////////////////// // From b92feaa6caa157aa74bee24819e757e7c9acf5f1 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 25 Sep 2021 00:49:55 +0300 Subject: [PATCH 3/5] Add Aligo check to CI workflow --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f340b8c..afc70417 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,44 @@ jobs: CODECLIMATE_REPO_TOKEN: ${{ secrets.CODECLIMATE_TOKEN }} run: codeclimate-test-reporter < cover.out + Aligo: + name: Aligo + runs-on: ubuntu-latest + + needs: Go + + env: + SRC_DIR: src/github.com/${{ github.repository }} + GO111MODULE: auto + + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.16.x' + id: go + + - name: Setup PATH + run: | + echo "GOPATH=${{ github.workspace }}" >> "$GITHUB_ENV" + echo "GOBIN=${{ github.workspace }}/bin" >> "$GITHUB_ENV" + echo "${{ github.workspace }}/bin" >> "$GITHUB_PATH" + + - name: Checkout + uses: actions/checkout@v2 + with: + path: ${{env.SRC_DIR}} + + - name: Download dependencies + working-directory: ${{env.SRC_DIR}} + run: make deps + + - name: Check Golang sources with Aligo + uses: essentialkaos/aligo-action@v1 + with: + path: ${{env.SRC_DIR}} + files: ./... + Shellcheck: name: Shellcheck runs-on: ubuntu-latest From 750c5fc5ebbd81c8f5eb8fe3d737e3013132035b Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 25 Sep 2021 00:55:59 +0300 Subject: [PATCH 4/5] Fix tests --- recipe/recipe_test.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/recipe/recipe_test.go b/recipe/recipe_test.go index abe9ed45..a653a11d 100644 --- a/recipe/recipe_test.go +++ b/recipe/recipe_test.go @@ -75,9 +75,22 @@ func (s *RecipeSuite) TestBasicRecipe(c *C) { c.Assert(c2.Tag, Equals, "special") c.Assert(c2.Description, Equals, "Echo command for service nginx") - a1 := &Action{"copy", []string{"file1", "file2"}, true, 0, nil} - a2 := &Action{"touch", []string{"{service}"}, false, 0, nil} - a3 := &Action{"print", []string{"1.53", "4000", "ABCD"}, false, 0, nil} + a1 := &Action{Name: "copy", + Arguments: []string{"file1", "file2"}, + Negative: true, Line: 0, Command: nil, + } + + a2 := &Action{ + Name: "touch", + Arguments: []string{"{service}"}, + Negative: false, Line: 0, Command: nil, + } + + a3 := &Action{ + Name: "print", + Arguments: []string{"1.53", "4000", "ABCD"}, + Negative: false, Line: 0, Command: nil, + } c1.AddAction(a1) c2.AddAction(a2) @@ -207,7 +220,10 @@ func (s *RecipeSuite) TestIndex(c *C) { c.Assert(c1.Index(), Equals, 0) - a1 := &Action{"abcd", []string{}, true, 0, nil} + a1 := &Action{ + Name: "abcd", Arguments: []string{}, + Negative: true, Line: 0, Command: nil, + } c.Assert(a1.Index(), Equals, -1) From 5e17bb90b6363d24efb4bcd710e6e36213042756 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sun, 26 Sep 2021 15:19:58 +0300 Subject: [PATCH 5/5] Improve README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ef1dcf8..b81a008e 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Official Docker images with bibop: ### Recipe syntax highlighting -* [Sublime Text 3](https://kaos.sh/blackhole-theme-sublime/bibop-recipe.sublime-syntax) +* [Sublime Text 3/4](https://kaos.sh/blackhole-theme-sublime/bibop-recipe.sublime-syntax) * [nano](https://kaos.sh/blackhole-theme-nano/bibop.nanorc) ### Command-line completion