Skip to content

Commit

Permalink
Bump Go version to 1.23 (#107)
Browse files Browse the repository at this point in the history
1. Bump Go version to 1.23
2. Fix skipping code error in test
3. Fix dependency
  • Loading branch information
maranqz authored Sep 4, 2024
1 parent b20076d commit 07a5941
Show file tree
Hide file tree
Showing 36 changed files with 756 additions and 137 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- main
name: Test
env:
GO_TARGET_VERSION: 1.21
OS_TARGET: ubuntu-latest
GOTOOLCHAIN: local
jobs:
tests-units:
needs: [lint]
Expand All @@ -28,19 +28,21 @@ jobs:
- '1.18'
- '1.19'
- '1.20'
- '1.21'
- '1.22'
os:
- ubuntu-latest
# - macos-latest
# - windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
Expand Down Expand Up @@ -82,21 +84,20 @@ jobs:
--health-retries 5
strategy:
matrix:
go-version:
- '1.21' # latest go version
go-version: ['1.23']
os:
- ubuntu-latest
mongodb-version:
- '6.0'
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
Expand Down Expand Up @@ -145,7 +146,7 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_TARGET_VERSION }}
go-version: '1.23'
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
Expand Down
10 changes: 3 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
run:
skip-dirs:
- trm/mock
- trm/manager/mock
- sql/mock

linters:
enable:
- asasalint
Expand All @@ -16,7 +10,6 @@ linters:
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exhaustruct
- exportloopref # https://github.com/kyoh86/exportloopref#whats-this
Expand Down Expand Up @@ -68,6 +61,9 @@ linters-settings:
allow-assign-and-anything: true

issues:
exclude-dirs:
- trm/manager/mock
- sql/mock
exclude-use-default: false
exclude:
- ST1000 # ST1000: at least one file in a package should have a package comment
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.0-rc-9] - 2024-08-03
## [2.0.0] - 2024-09-05

### Fixed

- CI/CD passed always even if some of them failed.

### Changes

- Bumped tests up to go1.23.

## [2.0.0-rc-9] - 2024-08-09

### Fixed

Expand Down
61 changes: 58 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ For example `go get github.com/avito-tech/go-transaction-manager/drivers/sqlx/v2
The library is compatible with the most recent two versions of Go.
Compatibility beyond that is not guaranteed.

The critical bugs are firstly solved for the most recent two Golang versions and then for older ones if it is simple.

#### Disclaimer: Keep your dependencies up to date, even indirect ones.

`go get -u && go mod tidy` helps you.

**Note**: The go-transaction-manager uses some old dependencies to support backwards compatibility for old versions of Go.

## Usage

**To use multiple transactions from different databases**, you need to set CtxKey in [Settings](trm/settings.go)
Expand Down Expand Up @@ -162,8 +170,55 @@ func (r *repo) Save(ctx context.Context, u *user) error {

## Contribution

1. To local development sync dependencies use `make go.work.sync`.
2. After finalizing of changes bump up version in all drivers.
### Requirements

- [golangci-lint](https://golangci-lint.run/welcome/install/)
- [make](https://www.gnu.org/software/make/#download)

### Local Running

* To install all dependencies use `make go.mod.tidy` or `make go.mod.vendor`.
* To run all tests use `make go.test` or `make go.test.with_real_db` for integration tests.
* To run all tests use `make test` or `make test.with_real_db` for integration tests.

To run database by docker, there is [docker-compose.yaml](trm/drivers/test/docker-compose.yaml).
```bash
docker compose -f trm/drivers/test/docker-compose.yaml up
```

For full GitHub Actions run, you can use [act](https://github.com/nektos/act).

#### Running old go versions

To stop Golang upgrading set environment variable `GOTOOLCHAIN=local` .

```sh
go install go1.16 # or older version
go1.16 install
```

Use `-mod=readonly` to prevent `go.mod` modification.

To run tests
```
go1.16 test -race -mod=readonly ./...
```

### How to bump up Golang version in CI/CD

1. Changes in [.github/workflows/main.yaml](.github/workflows/main.yaml).
1. Add all old version of Go in `go-version:` for `tests-units` job.
2. Update `go-version:` on current version of Go for `lint` and `tests-integration` jobs.
2. Update build tags by replacing `build go1.xx` on new version.


### Resolve problems with old version of dependencies

To build `go.mod` compatible for old version use `go mod tidy -compat=1.13` ([docs](https://go.dev/ref/mod#go-mod-tidy)).

However, `--compat` doesn't always work correct and we need to set some library versions manually.

1. `go get go.uber.org/[email protected]` in [trm](trm), [sql](drivers/sql), [sqlx](drivers/sqlx).
2. `go get github.com/mattn/[email protected]` in [trm](trm), [sql](drivers/sql), [sqlx](drivers/sqlx).
3. `go get github.com/stretchr/[email protected]` in [trm](trm), [sql](drivers/sql), [sqlx](drivers/sqlx), [goredis8](drivers/goredis8), [mongo](drivers/mongo).
4. `go get github.com/jackc/[email protected]` in [pgxv4](drivers/pgxv4). Golang version was bumped up from 1.12 to 1.17 in pgconn v1.14.3.
5. `go get golang.org/x/[email protected]` in [pgxv4](drivers/pgxv4).
4 changes: 2 additions & 2 deletions drivers/goredis8/goroutine_leak_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build go1.20
// +build go1.20
//go:build go1.23
// +build go1.23

package goredis8

Expand Down
15 changes: 8 additions & 7 deletions drivers/gorm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/avito-tech/go-transaction-manager/drivers/gorm/v2
go 1.18

require (
github.com/DATA-DOG/go-sqlmock v1.5.1
github.com/avito-tech/go-transaction-manager/trm/v2 v2.0.0-rc10
github.com/mattn/go-sqlite3 v1.14.18
github.com/stretchr/testify v1.8.2
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/avito-tech/go-transaction-manager/trm/v2 v2.0.0-rc9.2
github.com/mattn/go-sqlite3 v1.14.22
github.com/stretchr/testify v1.9.0
go.uber.org/goleak v1.3.0
gorm.io/driver/mysql v1.5.2
gorm.io/driver/sqlite v1.5.4
gorm.io/gorm v1.25.5
gorm.io/driver/mysql v1.5.7
gorm.io/driver/sqlite v1.5.6
gorm.io/gorm v1.25.11
)

require (
Expand All @@ -22,5 +22,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
30 changes: 17 additions & 13 deletions drivers/gorm/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
github.com/DATA-DOG/go-sqlmock v1.5.1 h1:FK6RCIUSfmbnI/imIICmboyQBkOckutaa6R5YYlLZyo=
github.com/DATA-DOG/go-sqlmock v1.5.1/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/avito-tech/go-transaction-manager/trm/v2 v2.0.0-rc10 h1:SqfNHnRw9CeroyLp4aVJVnmNaSemjbGy0nhiSGerGW4=
github.com/avito-tech/go-transaction-manager/trm/v2 v2.0.0-rc10/go.mod h1:qUNVecb/ahohzAvtGvjfWTeCOejgRRiO/2C4cDvtLjI=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/avito-tech/go-transaction-manager/trm/v2 v2.0.0-rc9.2 h1:z7VXuLvOl4TV676XRugs6LUZ64X2QoiKE37/j29VsNA=
github.com/avito-tech/go-transaction-manager/trm/v2 v2.0.0-rc9.2/go.mod h1:qUNVecb/ahohzAvtGvjfWTeCOejgRRiO/2C4cDvtLjI=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -30,8 +31,8 @@ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+5aI=
github.com/mattn/go-sqlite3 v1.14.18/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
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/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
Expand All @@ -44,8 +45,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
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.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
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=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
Expand Down Expand Up @@ -81,6 +83,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX
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.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.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
Expand All @@ -96,10 +100,10 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.5.2 h1:QC2HRskSE75wBuOxe0+iCkyJZ+RqpudsQtqkp+IMuXs=
gorm.io/driver/mysql v1.5.2/go.mod h1:pQLhh1Ut/WUAySdTHwBpBv6+JKcj+ua4ZFx1QQTBzb8=
gorm.io/driver/sqlite v1.5.4 h1:IqXwXi8M/ZlPzH/947tn5uik3aYQslP9BVveoax0nV0=
gorm.io/driver/sqlite v1.5.4/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4=
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE=
gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg=
gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
4 changes: 2 additions & 2 deletions drivers/gorm/goroutine_leak_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build go1.20
// +build go1.20
//go:build go1.23
// +build go1.23

package gorm

Expand Down
49 changes: 49 additions & 0 deletions drivers/mongo/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package mongo

import (
"context"

"go.mongodb.org/mongo-driver/mongo"

"github.com/avito-tech/go-transaction-manager/trm/v2"
trmcontext "github.com/avito-tech/go-transaction-manager/trm/v2/context"
)

// DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey.
var DefaultCtxGetter = NewCtxGetter(trmcontext.DefaultManager)

// CtxGetter gets Tr from trm.СtxManager by casting trm.Transaction to Tr.
type CtxGetter struct {
ctxManager trm.СtxManager
}

// NewCtxGetter returns *CtxGetter to get Tr from context.Context.
func NewCtxGetter(c trm.СtxManager) *CtxGetter {
return &CtxGetter{ctxManager: c}
}

// DefaultTrOrDB returns mongo.Session from context.Context or DB(mongo.Session) otherwise.
func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db mongo.Session) mongo.Session {
if tr := c.ctxManager.Default(ctx); tr != nil {
return c.convert(tr)
}

return db
}

// TrOrDB returns mongo.Session from context.Context by trm.CtxKey or DB(mongo.Session) otherwise.
func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db mongo.Session) mongo.Session {
if tr := c.ctxManager.ByKey(ctx, key); tr != nil {
return c.convert(tr)
}

return db
}

func (c *CtxGetter) convert(tr trm.Transaction) mongo.Session {
if tx, ok := tr.Transaction().(mongo.Session); ok {
return tx
}

return nil
}
Loading

0 comments on commit 07a5941

Please sign in to comment.