Skip to content

Commit

Permalink
1. Bump minimal Go version
Browse files Browse the repository at this point in the history
2. Updating dependency versions
3. Expanded documentation
4. Added linters
5. Removed asdf support
  • Loading branch information
BorzdeG committed Aug 14, 2024
1 parent c207222 commit 6c1c171
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 164 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/gosec.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ on:
jobs:
tests:
runs-on: ubuntu-latest
env:
GO111MODULE: on
permissions:
security-events: write
steps:
- name: Checkout Source
uses: actions/checkout@v4

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/test-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Matrix tests

on:
push:
pull_request:

jobs:
test-matrix:
runs-on: ubuntu-latest

strategy:
matrix:
go: ["1.22.x", "stable"]
continueOnError: [false]
# include:
# - go: ">=1.23.0-rc.1"
# continueOnError: true

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
check-latest: true

- run: make go-all-tests

- name: Test Summary
uses: test-summary/action@v2
with:
paths: "junit-report.xml"
if: always()

- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: "junit-report.xml"
verbose: true

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-unit.out
verbose: true
58 changes: 24 additions & 34 deletions .github/workflows/test.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test
name: Tests

on:
push:
Expand All @@ -10,17 +10,25 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- uses: actions/setup-go@v5
with:
go-version: 'stable'
- run: go mod tidy && git diff --exit-code go.mod go.sum

test-asdf:
tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install asdf & tools
uses: asdf-vm/actions/install@v3
- uses: actions/setup-go@v5
with:
go-version: 'stable'
check-latest: true

- run: make go-dependencies

- run: make go-generate && git diff --exit-code

- run: make go-all-tests

Expand All @@ -30,36 +38,18 @@ jobs:
paths: "junit-report.xml"
if: always()

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./.coverage.out

test-matrix:
runs-on: ubuntu-latest

strategy:
matrix:
go: ["1.21.x"]
continueOnError: [false]
include:
- go: ">=1.22.0-rc.1"
continueOnError: true

steps:
- uses: actions/checkout@v4
files: "junit-report.xml"
verbose: true

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
check-latest: true

- run: make go-all-tests

- name: Test Summary
uses: test-summary/action@v2
- name: Upload coverage reports to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v4
with:
paths: "junit-report.xml"
if: always()
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-unit.out
verbose: true
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
tmp.*

# Go
.coverage.out
.coverage-*.out
coverage-*.*
ginkgo-coverage-*.*
junit-report.xml

# IntelliJ IDEs
Expand Down
18 changes: 14 additions & 4 deletions .golangci.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#file: noinspection SpellCheckingInspection
run:
concurrency: 4
modules-download-mode: readonly

# https://golangci-lint.run/usage/configuration/#linters-configuration
linters:
Expand All @@ -12,7 +13,6 @@ linters:
- ineffassign
- staticcheck
- unused
- unused
- asasalint
- bodyclose
- containedctx
Expand All @@ -27,16 +27,19 @@ linters:
- funlen
- gocritic
- gocyclo
- goerr113
- err113
- goimports
- gomnd
- mnd
- gomoddirectives
- gosec
- govet
- grouper
- misspell
- nilerr
- nlreturn
- noctx
- prealloc
- predeclared
- promlinter
- revive
- wastedassign
Expand All @@ -52,11 +55,18 @@ linters:
- wrapcheck
- wsl
- ginkgolinter
# - interfacebloat
- interfacebloat
- sloglint
- nilnil

linters-settings:
varnamelen:
ignore-type-assert-ok: true
ignore-map-index-ok: true
ignore-names:
- l
govet:
enable-all: true
nolintlint:
require-explanation: true
require-specific: true
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

44 changes: 15 additions & 29 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
go-dependencies:
# https://asdf-vm.com/
asdf install golang || :
go-all: go-update go-generate go-all-tests
go-all-tests: go-lint go-unit-tests

# https://github.com/securego/gosec
go install github.com/securego/gosec/v2/cmd/gosec@latest
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
#
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/nunnatsa/ginkgolinter/cmd/ginkgolinter@latest
go-dependencies:
$(eval GOBIN=$(shell go env GOPATH 2>/dev/null)/bin)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) latest
#
go install github.com/onsi/ginkgo/v2/ginkgo@latest
#
go install github.com/vektra/mockery/v2@latest
#
asdf reshim golang || :
#
go get -u -t -v ./... || :

go-generate: go-dependencies
#mockery
go-update: go-dependencies
go mod tidy && go get -t -v -u ./...

go-generate:
go generate ./...

go-lint: go-dependencies
go-lint:
golangci-lint run
ginkgolinter ./...
go vet -vettool=$$(go env GOPATH)/bin/shadow ./...

go-test: go-lint
gosec ./...
ginkgo -r -race --cover --coverprofile=.coverage-ginkgo.out --junit-report=junit-report.xml ./...
go tool cover -func=.coverage-ginkgo.out -o=.coverage.out
cat .coverage.out

go-all-tests: go-dependencies go-generate go-lint go-test
go-unit-tests:
ginkgo -race --cover --coverprofile="ginkgo-coverage-unit.out" --junit-report="junit-report.xml" ./...
go tool cover -func "ginkgo-coverage-unit.out" -o "coverage-unit.out"
go tool cover -html "ginkgo-coverage-unit.out" -o "coverage-unit.html"

go-all: go-all-tests
go mod tidy || :
cat coverage-unit.out
42 changes: 35 additions & 7 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,44 @@ https://goreportcard.com/report/github.com/itbasis/go-hashtag[image:https://gore
go get -u github.com/itbasis/go-hashtag@latest
```

== Example
== Examples

Case-insensitive:
[source,go]
```
----
package main
import "github.com/itbasis/go-hashtag"
import (
"fmt"
"github.com/itbasis/go-hashtag"
)
func main() {
text := "An example of a text with a #hashtag #another #Another"
hashTags := hashtag.NewParser(false).Parse(text)
fmt.Println(hashTags)
func func main() {
text := "An example of a text with a #hashtag"
hashTags := NewParser(false).Parse(text)
// Output: ["hashtag": 1, "another": 2]
}
```
----

Case-sensitive:
[source,go]
----
package main
import (
"fmt"
"github.com/itbasis/go-hashtag"
)
func main() {
text := "An example of a text with a #hashtag #another #Another"
hashTags := hashtag.NewParser(true).Parse(text)
fmt.Println(hashTags)
// Output: ["hashtag": 1, "another": 1, "Another": 1]
}
----
27 changes: 14 additions & 13 deletions go.mod
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
module github.com/itbasis/go-hashtag

go 1.21
go 1.22

require (
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.31.1
github.com/itbasis/go-test-utils/v4 v4.0.0
github.com/onsi/ginkgo/v2 v2.20.0
github.com/onsi/gomega v1.34.1
)

require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/dusted-go/logging v1.3.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240125082051-42cd04596328 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 6c1c171

Please sign in to comment.