diff --git a/.editorconfig b/.editorconfig index e697ad5..4217d90 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,3 +14,7 @@ indent_style = space [*.feature] 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 14f610b..adc1718 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -1,3 +1,4 @@ +--- name: lint on: @@ -6,44 +7,21 @@ on: - master pull_request: -env: - GO_VERSION: 1.19.x - jobs: lint: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-go@v5 - with: - go-version: ${{ env.GO_VERSION }} + - name: Checkout code + uses: nhatthm/gh-actions/checkout@master - - 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 031f541..f97874a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,3 +1,4 @@ +--- name: test on: @@ -8,53 +9,54 @@ 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@v4 + - 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 (unit) 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 }} - name: Upload code coverage (features) if: matrix.go-version == env.GO_LATEST_VERSION - uses: codecov/codecov-action@v3 + uses: nhatthm/gh-actions/codecov@master with: - files: ./features.coverprofile + file: ./features.coverprofile flags: featurestests-${{ runner.os }} diff --git a/.github/workflows/update-registry.yaml b/.github/workflows/update-registry.yaml index 5252604..013492f 100644 --- a/.github/workflows/update-registry.yaml +++ b/.github/workflows/update-registry.yaml @@ -3,31 +3,20 @@ name: 'update-registry' on: push: + branches: + - master tags: - v* workflow_dispatch: -env: - MODULE_NAME: consolesteps - jobs: notify: runs-on: ubuntu-latest - strategy: - matrix: - registry: [ go.nhat.io, go-staging.nhat.io ] steps: - - uses: actions/checkout@v4 - - - id: vars - run: | - make $GITHUB_OUTPUT + - name: Checkout code + uses: nhatthm/gh-actions/checkout@master - - 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 74dfb67..f4a2451 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -20,6 +20,8 @@ linters-settings: linters: enable-all: true disable: + - deadcode + - depguard - exhaustivestruct - exhaustruct - forbidigo @@ -38,12 +40,15 @@ linters: - nolintlint # https://github.com/golangci/golangci-lint/issues/3063 - paralleltest - scopelint + - structcheck - tagliatelle - testpackage + - varcheck - varnamelen - wrapcheck issues: + max-same-issues: 20 exclude-use-default: false exclude-rules: - linters: diff --git a/Makefile b/Makefile index aa50205..dfe6f9d 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ +MODULE_NAME = consolesteps + VENDOR_DIR = vendor GITHUB_OUTPUT ?= /dev/null -GOLANGCI_LINT_VERSION ?= v1.51.1 +GOLANGCI_LINT_VERSION ?= v1.55.2 GO ?= go GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION) diff --git a/assertions_test.go b/assertions_test.go index b0ca5f1..c3f7b7d 100644 --- a/assertions_test.go +++ b/assertions_test.go @@ -3,7 +3,7 @@ package consolesteps import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestTestingT_LastError(t *testing.T) { @@ -12,5 +12,5 @@ func TestTestingT_LastError(t *testing.T) { tee := teeError() tee.Errorf("error: %s", "unknown") - assert.EqualError(t, tee.LastError(), `error: unknown`) + require.EqualError(t, tee.LastError(), `error: unknown`) } diff --git a/features/bootstrap/godog_test.go b/features/bootstrap/godog_test.go index a0f7839..e9fd0d9 100644 --- a/features/bootstrap/godog_test.go +++ b/features/bootstrap/godog_test.go @@ -12,6 +12,7 @@ import ( "github.com/cucumber/godog" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.nhat.io/consolesteps" ) @@ -66,7 +67,7 @@ func RunSuite(t *testing.T, path string, featureContext func(t *testing.T, ctx * var paths []string files, err := os.ReadDir(filepath.Clean(path)) - assert.NoError(t, err) + require.NoError(t, err) paths = make([]string, 0, len(files)) diff --git a/go.mod b/go.mod index c888b34..f19dd7a 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/gofrs/uuid v4.4.0+incompatible // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-memdb v1.3.4 // indirect - github.com/hashicorp/golang-lru v0.5.4 // indirect + github.com/hashicorp/golang-lru v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 8b2c6aa..e493dbe 100644 --- a/go.sum +++ b/go.sum @@ -27,8 +27,9 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE= github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= +github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02 h1:AgcIVYPa6XJnU3phs104wLj8l5GEththEw6+F79YsIY= github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=