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

ci: setup pipeline #8

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/actions/prepare-test-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Prepare test environment"
description: "Prepares test environment"

runs:
using: "composite"
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '${{ env.GO_VERSION }}'

- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '${{ env.PYTHON_VERSION }}'
33 changes: 33 additions & 0 deletions .github/actions/static-code-check/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Run static code check"
description: "Performs static code checks."

runs:
using: "composite"
steps:
- name: Setup virtual environment
run: |
python3 -m venv venv
shell: bash

- name: Install tests requirements
run: |
source ./venv/bin/activate
pip3 install -r test/requirements.txt
psergee marked this conversation as resolved.
Show resolved Hide resolved
shell: bash

- name: Log versions
run: |
go version
shell: bash

- name: Go Linter
uses: golangci/golangci-lint-action@v3
with:
args: --config=golangci-lint.yml --out-${NO_FUTURE}format colored-line-number
skip-cache: true

- name: Python Linter
run: |
source ./venv/bin/activate
python3 -m flake8 test
shell: bash
62 changes: 0 additions & 62 deletions .github/workflows/test.yml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
name: Tests

on: [push, pull_request]

env:
GO_VERSION: 1.14
PYTHON_VERSION: '3.x'

jobs:
tests:
if: |
(github.event_name == 'push') ||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.owner.login != 'tarantool')
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@master

- name: Prepare env
uses: ./.github/actions/prepare-test-env

- name: Static code check
uses: ./.github/actions/static-code-check

- name: Unit tests
run: make test

- name: Integration tests
run: |
source ./venv/bin/activate
make integration

tests-mac-os:
if: |
(github.event_name == 'push') ||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.owner.login != 'tarantool')
runs-on: macos-12
steps:
- uses: actions/checkout@master

- name: Prepare env
uses: ./.github/actions/prepare-test-env

- name: Install additional dependencies
run: brew install tmux

- name: Static code check
uses: ./.github/actions/static-code-check

- name: Unit tests
run: make test

- name: Integration tests
run: |
source ./venv/bin/activate
make integration
20 changes: 13 additions & 7 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (b *Buffer) Text() string {
return b.workingLines[b.workingIndex]
}

// NewLineCount returns the number of `\n` in the buffer text
// NewLineCount returns the number of `\n` in the buffer text.
func (b *Buffer) NewLineCount() int {
return strings.Count(b.Text(), "\n")
}
Expand All @@ -41,7 +41,8 @@ func (b *Buffer) Document() (d *Document) {
}

// DisplayCursorPosition returns the cursor position on rendered text on terminal emulators.
// So if Document is "日本(cursor)語", DisplayedCursorPosition returns 4 because '日' and '本' are double width characters.
// So if Document is "日本(cursor)語", DisplayedCursorPosition returns 4 because '日' and '本' are
// double width characters.
func (b *Buffer) DisplayCursorPosition() int {
return b.Document().DisplayCursorPosition()
}
Expand Down Expand Up @@ -71,7 +72,8 @@ func (b *Buffer) InsertText(v string, overwrite bool, moveCursor bool) {
// (When doing this, make sure that the cursor_position is valid for this text.
// text/cursor_position should be consistent at any time, otherwise set a Document instead.)
func (b *Buffer) setText(v string) {
debug.Assert(b.cursorPosition <= len([]rune(v)), "length of input should be shorter than cursor position")
debug.Assert(b.cursorPosition <= len([]rune(v)),
"length of input should be shorter than cursor position")
// replace CR with LF
v = strings.ReplaceAll(v, "\r", "\n")
b.workingLines[b.workingIndex] = v
Expand All @@ -88,7 +90,8 @@ func (b *Buffer) setCursorPosition(p int) {

func (b *Buffer) setDocument(d *Document) {
b.cacheDocument = d
b.setCursorPosition(d.cursorPosition) // Call before setText because setText check the relation between cursorPosition and line length.
b.setCursorPosition(d.cursorPosition) // Call before setText because setText check the relation
// between cursorPosition and line length.
b.setText(d.Text)
}

Expand Down Expand Up @@ -132,7 +135,8 @@ func (b *Buffer) CursorDown(count int) {
b.preferredColumn = orig
}

// DeleteBeforeCursor delete specified number of characters before cursor and return the deleted text.
// DeleteBeforeCursor deletes specified number of characters before cursor
// and returns the deleted text.
func (b *Buffer) DeleteBeforeCursor(count int) (deleted string) {
debug.Assert(count >= 0, "count should be positive")
r := []rune(b.Text())
Expand Down Expand Up @@ -170,13 +174,15 @@ func (b *Buffer) Delete(count int) (deleted string) {
return
}

// JoinNextLine joins the next line to the current one by deleting the line ending after the current line.
// JoinNextLine joins the next line to the current one by deleting the line ending after the
// current line.
func (b *Buffer) JoinNextLine(separator string) {
if !b.Document().OnLastLine() {
b.cursorPosition += b.Document().GetEndOfLinePosition()
b.Delete(1)
// Remove spaces
b.setText(b.Document().TextBeforeCursor() + separator + strings.TrimLeft(b.Document().TextAfterCursor(), " "))
b.setText(b.Document().TextBeforeCursor() + separator +
strings.TrimLeft(b.Document().TextAfterCursor(), " "))
}
}

Expand Down
3 changes: 2 additions & 1 deletion completer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var (
)

// FilePathCompleter is a completer for your local file system.
// Please caution that you need to set OptionCompletionWordSeparator(completer.FilePathCompletionSeparator)
// Please caution that you need to set
// OptionCompletionWordSeparator(completer.FilePathCompletionSeparator)
// when you use this completer.
type FilePathCompleter struct {
Filter func(fi os.FileInfo) bool
Expand Down
100 changes: 79 additions & 21 deletions completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,38 @@ func TestFormatShortSuggestion(t *testing.T) {
},
{
in: []Suggest{
{Text: "--all-namespaces", Description: "-------------------------------------------------------------------------------------------------------------------------------------------"},
{Text: "--allow-missing-template-keys", Description: "-----------------------------------------------------------------------------------------------------------------------------------------------"},
{Text: "--export", Description: "----------------------------------------------------------------------------------------------------------"},
{Text: "-f", Description: "-----------------------------------------------------------------------------------"},
{Text: "--filename", Description: "-----------------------------------------------------------------------------------"},
{Text: "--include-extended-apis", Description: "------------------------------------------------------------------------------------"},
{
Text: "--all-namespaces",
Description: "---------------------------------------------" +
"-------------------------------" +
"---------------------------------------------------------------",
},
{
Text: "--allow-missing-template-keys",
Description: "---------------------------------------------" +
"-------------------------------" +
"---------------------------------------------------------------",
},
{
Text: "--export",
Description: "---------------------------------------------" +
"-------------------------------------------------------------",
},
{
Text: "-f",
Description: "---------------------------------------------" +
"--------------------------------------",
},
{
Text: "--filename",
Description: "---------------------------------------------" +
"--------------------------------------",
},
{
Text: "--include-extended-apis",
Description: "---------------------------------------------" +
"--------------------------------------",
},
},
expected: []Suggest{
{Text: " --all-namespaces ", Description: " --------------... "},
Expand All @@ -86,23 +112,55 @@ func TestFormatShortSuggestion(t *testing.T) {
},
{
in: []Suggest{
{Text: "--all-namespaces", Description: "If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace."},
{Text: "--allow-missing-template-keys", Description: "If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats."},
{Text: "--export", Description: "If true, use 'export' for the resources. Exported resources are stripped of cluster-specific information."},
{Text: "-f", Description: "Filename, directory, or URL to files identifying the resource to get from a server."},
{Text: "--filename", Description: "Filename, directory, or URL to files identifying the resource to get from a server."},
{Text: "--include-extended-apis", Description: "If true, include definitions of new APIs via calls to the API server. [default true]"},
{Text: "--all-namespaces", Description: "If present, list the requested" +
" object(s) across all namespaces. Namespace in current context" +
" is ignored even if specified with --namespace."},
{Text: "--allow-missing-template-keys", Description: "If true," +
" ignore any errors in templates when a field or map key" +
" is missing in the template. Only applies to golang and jsonpath" +
" output formats."},
{Text: "--export", Description: "If true, use 'export'" +
" for the resources. Exported resources are stripped" +
" of cluster-specific information."},
{Text: "-f", Description: "Filename, directory, or URL to" +
" files identifying the resource to get from a server."},
{Text: "--filename", Description: "Filename, directory, or URL to" +
" files identifying the resource to get from a server."},
{Text: "--include-extended-apis", Description: "If true," +
" include definitions of new APIs via calls to" +
" the API server. [default true]"},
},
expected: []Suggest{
{Text: " --all-namespaces ", Description: " If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace. "},
{Text: " --allow-missing-template-keys ", Description: " If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. "},
{Text: " --export ", Description: " If true, use 'export' for the resources. Exported resources are stripped of cluster-specific information. "},
{Text: " -f ", Description: " Filename, directory, or URL to files identifying the resource to get from a server. "},
{Text: " --filename ", Description: " Filename, directory, or URL to files identifying the resource to get from a server. "},
{Text: " --include-extended-apis ", Description: " If true, include definitions of new APIs via calls to the API server. [default true] "},
},
max: 500,
exWidth: len(" --include-extended-apis " + " If true, include definitions of new APIs via calls to the API server. [default true] "),
{Text: " --all-namespaces ", Description: " If present," +
" list the requested object(s) across all namespaces." +
" Namespace in current context is ignored even if specified" +
" with --namespace. "},
{Text: " --allow-missing-template-keys ", Description: " If true," +
" ignore any errors in templates when a field or map key" +
" is missing in the template. Only applies to golang and" +
" jsonpath output formats. "},
{Text: " --export ", Description: " If true," +
" use 'export' for the resources. Exported resources are" +
" stripped of cluster-specific" +
" information. "},
{Text: " -f ", Description: " Filename," +
" directory, or URL to files identifying the resource to get" +
" from a server. " +
" "},
{Text: " --filename ", Description: " Filename," +
" directory, or URL to files identifying the resource to get" +
" from a server. " +
" "},
{Text: " --include-extended-apis ", Description: " If true," +
" include definitions of new APIs via calls to the API server." +
" [default true]" +
" "},
},
max: 500,
exWidth: len(" --include-extended-apis " +
"If true, include definitions of new APIs via calls to" +
" the API server. [default true] " +
" "),
},
}

Expand Down
Loading