diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..910c13e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +insert_final_newline = true +max_line_length = 160 +tab_width = 4 +trim_trailing_whitespace = true + +[Makefile] +indent_style = space + +[.github/workflows/*.{yml,yaml}] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index c919d6c..adc1718 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -1,3 +1,4 @@ +--- name: lint on: @@ -11,37 +12,16 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: nhatthm/gh-actions/checkout@master - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} - - - id: vars - run: | - make $GITHUB_OUTPUT + - name: Setup + uses: nhatthm/gh-actions/find-go-version@master - - name: lint - uses: golangci/golangci-lint-action@v3 + - name: Install Go + uses: nhatthm/gh-actions/setup-go@master with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: ${{ steps.vars.outputs.GOLANGCI_LINT_VERSION }} - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - # Optional: if set to true then the action will use pre-installed Go. - # skip-go-installation: true - - # Optional: if set to true then the action don't cache or restore ~/go/pkg. - # skip-pkg-cache: true + go-version: ${{ env.GO_LATEST_VERSION }} - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true + - name: Lint + uses: nhatthm/gh-actions/golangci-lint@master diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 878ae23..15246ba 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,3 +1,4 @@ +--- name: test on: @@ -8,46 +9,47 @@ on: env: GO111MODULE: "on" - GO_LATEST_VERSION: "1.19.x" jobs: + setup: + runs-on: ubuntu-latest + outputs: + go-latest-version: ${{ steps.find-go-version.outputs.go-latest-version }} + go-supported-versions: ${{ steps.find-go-version.outputs.go-supported-versions }} + steps: + - name: Checkout code + uses: nhatthm/gh-actions/checkout@master + + - id: find-go-version + name: Find Go version + uses: nhatthm/gh-actions/find-go-version@master + test: strategy: fail-fast: false matrix: os: [ ubuntu-latest, macos-latest ] - go-version: [ 1.17.x, 1.18.x, 1.19.x, 1.20.x ] + go-version: ${{ fromJson(needs.setup.outputs.go-supported-versions) }} runs-on: ${{ matrix.os }} + needs: [setup] + env: + GO_LATEST_VERSION: ${{ needs.setup.outputs.go-latest-version }} steps: - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v4 + uses: nhatthm/gh-actions/checkout@master - - name: Go cache - uses: actions/cache@v3 + - name: Install Go + uses: nhatthm/gh-actions/setup-go@master with: - # In order: - # * Module download cache - # * Build cache (Linux) - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-go-${{ matrix.go-version }}-cache-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go-${{ matrix.go-version }}-cache + go-version: ${{ matrix.go-version }} - name: Test - id: test run: | make test - name: Upload code coverage if: matrix.go-version == env.GO_LATEST_VERSION - uses: codecov/codecov-action@v3 + uses: nhatthm/gh-actions/codecov@master with: files: ./unit.coverprofile flags: unittests-${{ runner.os }} diff --git a/.github/workflows/update-registry.yaml b/.github/workflows/update-registry.yaml index d3cc60a..013492f 100644 --- a/.github/workflows/update-registry.yaml +++ b/.github/workflows/update-registry.yaml @@ -12,21 +12,11 @@ on: jobs: notify: runs-on: ubuntu-latest - strategy: - matrix: - registry: [ go.nhat.io, go-staging.nhat.io ] steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: nhatthm/gh-actions/checkout@master - - id: vars - run: | - make $GITHUB_OUTPUT - - - name: notify ${{ matrix.registry }} - uses: benc-uk/workflow-dispatch@v121 + - name: Notify registries + uses: nhatthm/gh-actions/notify-go-registries@master with: - workflow: build - repo: nhatthm/${{ matrix.registry }} token: ${{ secrets.REGISTRY_TOKEN }} - inputs: '{"modules": "${{ steps.vars.outputs.MODULE_NAME }}"}' - ref: 'master' diff --git a/.golangci.yaml b/.golangci.yaml index 5c45adc..2a53ef0 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -21,6 +21,7 @@ linters: enable-all: true disable: - deadcode + - depguard - exhaustivestruct - exhaustruct - forbidigo @@ -34,17 +35,21 @@ linters: - ireturn - lll - maligned + - nonamedreturns - nosnakecase + - nolintlint # https://github.com/golangci/golangci-lint/issues/3063 - paralleltest - scopelint - structcheck - tagliatelle - testpackage + - testifylint - varcheck - varnamelen - wrapcheck issues: + max-same-issues: 20 exclude-use-default: false exclude-rules: - linters: diff --git a/Makefile b/Makefile index 507987c..faf2133 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ MODULE_NAME=surveyexpect VENDOR_DIR = vendor -GOLANGCI_LINT_VERSION ?= v1.52.2 +GOLANGCI_LINT_VERSION ?= v1.55.2 GO ?= go GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION) diff --git a/expect.go b/expect.go index 506f91c..8a7d10e 100644 --- a/expect.go +++ b/expect.go @@ -11,7 +11,7 @@ import ( type TestingT interface { Errorf(format string, args ...interface{}) FailNow() - Cleanup(func()) + Cleanup(f func()) Log(args ...interface{}) Logf(format string, args ...interface{}) } diff --git a/go.mod b/go.mod index 97291db..6d52f5a 100644 --- a/go.mod +++ b/go.mod @@ -14,11 +14,11 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/term v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/sys v0.16.0 // indirect + golang.org/x/term v0.16.0 // indirect + golang.org/x/text v0.14.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index e98c353..61637b9 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxec github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= @@ -54,20 +54,20 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= +golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=