Skip to content

Commit

Permalink
Reworking Github Actions
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Malusev <dusan@dusanmalusev.dev>
  • Loading branch information
CodeLieutenant committed Apr 15, 2024
1 parent b1db9e5 commit a45e393
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 109 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ on:
- master
- develop
jobs:
golangci-lint:
lint:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-tests-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-tests-${{ hashFiles('**/go.sum') }}
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
golangci_lint_flags: "--tests=false"
golangci_lint_flags: "--config=.golangci.yml"
cache: true
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'Create Release'

on:
push:
tags:
- 'v*'

jobs:
create_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Get Tag
if: startsWith(github.ref, 'refs/tags/v')
uses: olegtarasov/get-tag@v2.1.3
id: version_tag
with:
tagRegex: "v(.*)"
- name: Upload Release Asset
uses: softprops/action-gh-release@v1
id: release
with:
name: "v${{ steps.version_tag.outputs.tag }}"
tag_name: "v${{ steps.version_tag.outputs.tag }}"
generate_release_notes: true
append_body: true
prerelease: false
fail_on_unmatched_files: true
- name: "Generate release changelog"
uses: heinrichreimer/action-github-changelog-generator@v2.3
with:
token: ${{ secrets.GITHUB_TOKEN }}
author: true
releaseUrl: ${{ steps.release.outputs.url }}
issues: false
pullRequests: true
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update CHANGELOG.md"
branch: master
commit_options: '--no-verify --signoff'
file_pattern: CHANGELOG.md
5 changes: 3 additions & 2 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ jobs:
Gosec:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Run Gosec
uses: securego/gosec@master
with:
Expand Down
45 changes: 24 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,38 @@ jobs:
RABBITMQ_DEFAULT_PASS: guest
ports:
- '5672:5672'

strategy:
matrix:
os: [ubuntu-latest]
go: [ '1.21', '1.22' ]
os: ['ubuntu-latest']
go: [ '1.22' ]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-tests-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-tests-${{ hashFiles('**/go.sum') }}
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- uses: actions/cache@v3
- name: Install Task
uses: arduino/setup-task@v1
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Set up gotestfmt
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
- name: Test ${{ matrix.go }}
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run tests
run: |
go test -race -covermode=atomic -coverprofile=coverage.txt -timeout 5m -json -v ./... 2>&1 | gotestfmt
- uses: codecov/codecov-action@v1
go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
task test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt
flags: tests
name: codecov-umbrella
fail_ci_if_error: true
verbose: true
slug: nano-interactive/go-amqp
19 changes: 4 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@ run:
timeout: 5m
issues-exit-code: 1
tests: true

skip-dirs:
- docs/
- nanodocker/
- cli/migrations

skip-files:
- "*_gen\\.go$"

modules-download-mode: mod
allow-parallel-runners: true
go: '1.21'
go: '1.22'
modules-download-mode: mod
allow-parallel-runners: true

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
Expand All @@ -41,7 +31,6 @@ linters:
- gofumpt
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoglobals
- gocognit
- goconst
- gocritic
Expand Down Expand Up @@ -96,4 +85,4 @@ linters:
- whitespace
- zerologlint
- prealloc
# - perfsprint
- perfsprint
37 changes: 32 additions & 5 deletions amqp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ type Message struct {

var cnt atomic.Uint64

func handler(ctx context.Context, msg Message) error {
func handler(_ context.Context, msg Message) error {
defer cnt.Add(1)
fmt.Printf("[INFO] Message received: %d %s\n", cnt.Load(), msg.Name)
//nolint:forbidigo
_, _ = fmt.Printf("[INFO] Message received: %d %s\n", cnt.Load(), msg.Name)
return nil
}

func ExampleConsumer() {
c, err := consumer.NewFunc(handler,
consumer.QueueDeclare{QueueName: "testing_queue"},
consumer.WithOnMessageError[Message](func(ctx context.Context, d *amqp091.Delivery, err error) {
fmt.Fprintf(os.Stderr, "[ERROR] Message error: %s\n", err)
_, _ = fmt.Fprintf(os.Stderr, "[ERROR] Message error: %s\n", err)
}),
consumer.WithConnectionOptions[Message](connection.Config{
Host: "127.0.0.1",
Expand All @@ -46,6 +47,12 @@ func ExampleConsumer() {
panic(err)
}

go func() {
if err := c.Start(context.Background()); err != nil {
panic(err)
}
}()

fmt.Println("[INFO] Consumer started")
time.Sleep(100 * time.Second)

Expand All @@ -58,6 +65,7 @@ type MyHandler struct{}

func (h MyHandler) Handle(ctx context.Context, msg Message) error {
defer cnt.Add(1)
//nolint:forbidigo
fmt.Printf("[INFO] Message received: %d %s\n", cnt.Load(), msg.Name)
return nil
}
Expand All @@ -79,6 +87,12 @@ func ExampleConsumerWithHandler() {
panic(err)
}

go func() {
if err := c.Start(context.Background()); err != nil {
panic(err)
}
}()

fmt.Println("[INFO] Consumer started")
time.Sleep(100 * time.Second)

Expand Down Expand Up @@ -111,10 +125,16 @@ func ExampleConsumerWithSignal() {
panic(err)
}

go func() {
if err := c.Start(ctx); err != nil {
panic(err)
}
}()

fmt.Println("[INFO] Consumer started")
<-sig
cancel()
fmt.Println("[INFO] Signal Recieved")
fmt.Println("[INFO] Signal Received")

if err := c.Close(); err != nil {
panic(err)
Expand All @@ -129,12 +149,13 @@ func (h MyRawHandler) Handle(ctx context.Context, d *amqp091.Delivery) error {

_ = json.Unmarshal(d.Body, &msg)

//nolint:forbidigo
fmt.Printf("[INFO] Message received: %d %s\n", cnt.Load(), msg.Name)

return d.Ack(false)
}

func ExampleConsumerWithRawHandler() {
func Example_ConsumerWithRawHandler() {
c, err := consumer.NewRaw(MyRawHandler{},
consumer.QueueDeclare{QueueName: "testing_queue"},
consumer.WithOnMessageError[Message](func(ctx context.Context, d *amqp091.Delivery, err error) {
Expand All @@ -151,6 +172,12 @@ func ExampleConsumerWithRawHandler() {
panic(err)
}

go func() {
if err := c.Start(context.Background()); err != nil {
panic(err)
}
}()

fmt.Println("[INFO] Consumer started")
time.Sleep(100 * time.Second)

Expand Down
17 changes: 0 additions & 17 deletions consumer/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ type (
}
)

//func newQueue[T any]() (queue, error) {
//
// if err != nil {
// return queue{}, err
// }
//
// return queue{
// connection: conn,
// watcher: watcher,
// workers: int64(cfg.queueConfig.Workers),
// }, nil
//}

func (c *Consumer[T]) Start(base context.Context) error {
_, cancel := context.WithCancel(base)

Expand Down Expand Up @@ -59,7 +46,3 @@ func (c *Consumer[T]) Start(base context.Context) error {

return nil
}

//func (q *queue) Close() error {

//}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ go 1.22
require (
github.com/rabbitmq/amqp091-go v1.9.0
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.7.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
golang.org/x/sync v0.7.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
40 changes: 0 additions & 40 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,20 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rabbitmq/amqp091-go v1.5.0 h1:VouyHPBu1CrKyJVfteGknGOGCzmOz0zcv/tONLkb7rg=
github.com/rabbitmq/amqp091-go v1.5.0/go.mod h1:JsV0ofX5f1nwOGafb8L5rBItt9GyhfQfcJj+oyz0dGg=
github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo=
github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0=
github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
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/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Loading

0 comments on commit a45e393

Please sign in to comment.