From a7903233202050c0a76eaf7e7b6c5479154837f9 Mon Sep 17 00:00:00 2001 From: closetool Date: Tue, 16 Mar 2021 17:00:58 +0800 Subject: [PATCH] ci: github action ci and semantic release Signed-off-by: closetool --- .github/workflows/ci.yml | 59 ++++++++++++++++++++++++++++++++++++++++ adapter.go | 2 +- adapter_test.go | 10 +++---- go.mod | 2 +- go.sum | 3 +- 5 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2d918db --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +name: Go + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + + test: + runs-on: ubuntu-latest + + services: + mysql: + image: mysql + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: casbin + ports: + - 3306:3306 + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.14 + + - uses: actions/checkout@v2 + - name: Run Unit tests + run: go test -v -coverprofile=./profile.cov ./... + + #- uses: actions/checkout@v2 + #- uses: shogo82148/actions-goveralls@v1 + # with: + # path-to-profile: ./profile.cov + + semantic-release: + needs: [test] + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v2 + - name: Run semantic-release + uses: go-semantic-release/action@v1 + if: github.repository == 'casbin/gorm-adapter' && github.event_name == 'push' + with: + github-token: ${{ secrets.GH_TOKEN }} \ No newline at end of file diff --git a/adapter.go b/adapter.go index 3c77a2a..22a322e 100755 --- a/adapter.go +++ b/adapter.go @@ -143,7 +143,7 @@ func NewAdapter(driverName string, dataSourceName string, params ...interface{}) } else { return nil, errors.New("wrong format") } - } else { + } else if len(params) != 0{ return nil, errors.New("too many parameters") } diff --git a/adapter_test.go b/adapter_test.go index 9b9d6d2..b440752 100755 --- a/adapter_test.go +++ b/adapter_test.go @@ -248,7 +248,7 @@ func testUpdatePolicy(t *testing.T, a *Adapter) { } func TestAdapterWithCustomTable(t *testing.T) { - db, err := gorm.Open(postgres.Open("user=postgres host=127.0.0.1 port=5432 sslmode=disable"), &gorm.Config{}) + db, err := gorm.Open(postgres.Open("user=postgres password=postgres host=127.0.0.1 port=5432 sslmode=disable"), &gorm.Config{}) if err != nil { panic(err) } @@ -260,7 +260,7 @@ func TestAdapterWithCustomTable(t *testing.T) { } } - db, err = gorm.Open(postgres.Open("user=postgres host=127.0.0.1 port=5432 sslmode=disable dbname=casbin_custom_table"), &gorm.Config{}) + db, err = gorm.Open(postgres.Open("user=postgres password=postgres host=127.0.0.1 port=5432 sslmode=disable dbname=casbin_custom_table"), &gorm.Config{}) if err != nil { panic(err) } @@ -278,7 +278,7 @@ func TestAdapters(t *testing.T) { testAutoSave(t, a) testSaveLoad(t, a) - a = initAdapter(t, "postgres", "user=postgres host=127.0.0.1 port=5432 sslmode=disable") + a = initAdapter(t, "postgres", "user=postgres password=postgres host=127.0.0.1 port=5432 sslmode=disable") testAutoSave(t, a) testSaveLoad(t, a) @@ -297,7 +297,7 @@ func TestAdapters(t *testing.T) { a = initAdapterWithGormInstance(t, db) testFilteredPolicy(t, a) - db, err = gorm.Open(postgres.Open("user=postgres host=127.0.0.1 port=5432 sslmode=disable dbname=casbin"), &gorm.Config{}) + db, err = gorm.Open(postgres.Open("user=postgres password=postgres host=127.0.0.1 port=5432 sslmode=disable dbname=casbin"), &gorm.Config{}) if err != nil { panic(err) } @@ -330,7 +330,7 @@ func TestAdapters(t *testing.T) { a = initAdapterWithGormInstanceByName(t, db, "casbin_rule") testFilteredPolicy(t, a) - db, err = gorm.Open(postgres.Open("user=postgres host=127.0.0.1 port=5432 sslmode=disable dbname=casbin"), &gorm.Config{}) + db, err = gorm.Open(postgres.Open("user=postgres password=postgres host=127.0.0.1 port=5432 sslmode=disable dbname=casbin"), &gorm.Config{}) if err != nil { panic(err) } diff --git a/go.mod b/go.mod index ecd01e0..a76bcd5 100644 --- a/go.mod +++ b/go.mod @@ -12,5 +12,5 @@ require ( gorm.io/driver/postgres v1.0.1 gorm.io/driver/sqlite v1.1.4 gorm.io/driver/sqlserver v1.0.4 - gorm.io/gorm v1.21.4-0.20210314024258-2055e29eb812 + gorm.io/gorm v1.20.7 ) diff --git a/go.sum b/go.sum index 9380494..5d46c81 100644 --- a/go.sum +++ b/go.sum @@ -197,7 +197,6 @@ gorm.io/driver/sqlserver v1.0.4/go.mod h1:ciEo5btfITTBCj9BkoUVDvgQbUdLWQNqdFY5OG gorm.io/gorm v1.9.19/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= gorm.io/gorm v1.20.0/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= gorm.io/gorm v1.20.1/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= +gorm.io/gorm v1.20.7 h1:rMS4CL3pNmYq1V5/X+nHHjh1Dx6dnf27+Cai5zabo+M= gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= -gorm.io/gorm v1.21.4-0.20210314024258-2055e29eb812 h1:fN5b578CC+G7WQWCXJBnaTuT72rZvGAXWd20bMMiFwo= -gorm.io/gorm v1.21.4-0.20210314024258-2055e29eb812/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=