Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#

name: CodeQL

on:
pull_request:
# The branches below must be a subset of the branches above
branches: "*"

permissions:
contents: read

jobs:
analyse:
permissions:
actions: read # for github/codeql-action/init to get workflow details
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/autobuild to send a status report
name: Analyse
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# Analysis
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

60 changes: 60 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This is a basic workflow to help you get started with Actions

name: "golang ci lint"

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: "*"

# Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
matrix:
golang:
- 1.20.0

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: "set up go"
uses: actions/setup-go@v3
with:
go-version: 1.20.0

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: "checkout ${{ github.ref }}"
uses: actions/checkout@v3

- name: "golang ci lint"
uses: golangci/golangci-lint-action@v3.1.0
with:
version: v1.51.0
args: --timeout=10m
skip-go-installation: true
92 changes: 92 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

linters-settings:
govet:
shadow: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 10
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
misspell:
locale: US
lll:
line-length: 140
goimports:
local-prefixes: github.com/golangci/golangci-lint
gocritic:
enabled-tags:
- performance
- style
- experimental
disabled-checks:
- wrapperFunc

linters:
disable-all: true
enable:
- govet
- staticcheck
- ineffassign
- misspell
- asciicheck
- bodyclose
- rowserrcheck
- gofmt
- durationcheck
- sqlclosecheck

run:

issues:
exclude-dirs:
- test/testdata_etc
- pkg/golinters/goanalysis/(checker|passes)
exclude-rules:
- text: "weak cryptographic primitive"
linters:
- gosec
- linters:
- staticcheck
text: "SA1019:"
- path: _test\.go
linters:
- errcheck
- gosec
- rowserrcheck
- govet

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.57.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"

2 changes: 1 addition & 1 deletion at/basic/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func insertData(ctx context.Context) error {
}

func sampleInsert(ctx context.Context) {
tm.WithGlobalTx(ctx, &tm.GtxConfig{
_ = tm.WithGlobalTx(ctx, &tm.GtxConfig{
Name: "ATSampleLocalGlobalTx_Insert",
Timeout: time.Second * 30,
}, insertData)
Expand Down
2 changes: 1 addition & 1 deletion at/basic/insert_on_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func insertOnUpdateData(ctx context.Context) error {
}

func sampleInsertOnUpdate(ctx context.Context) {
tm.WithGlobalTx(ctx, &tm.GtxConfig{
_ = tm.WithGlobalTx(ctx, &tm.GtxConfig{
Name: "ATSampleLocalGlobalTx_InsertOnUpdate",
Timeout: time.Second * 30,
}, insertOnUpdateData)
Expand Down
6 changes: 6 additions & 0 deletions at/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func main() {
// sample: select for udpate
sampleSelectForUpdate(ctx)

// updateData
_ = updateData(ctx)

// deleteData
_ = deleteData(ctx)

<-make(chan struct{})
}

Expand Down
2 changes: 1 addition & 1 deletion at/basic/select_for_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func selectForUpdateData(ctx context.Context) error {
}

func sampleSelectForUpdate(ctx context.Context) {
tm.WithGlobalTx(ctx, &tm.GtxConfig{
_ = tm.WithGlobalTx(ctx, &tm.GtxConfig{
Name: "ATSampleLocalGlobalTx_SelectForUpdate",
Timeout: time.Second * 30,
}, selectForUpdateData)
Expand Down
12 changes: 11 additions & 1 deletion at/gorm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,17 @@ type OrderTblModel struct {
func main() {
initConfig()
// insert
tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
_ = tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
Name: "ATSampleLocalGlobalTx",
Timeout: time.Second * 30,
}, insertData)

// update
_ = updateData(context.Background())

// delete
_ = deleteData(context.Background())

<-make(chan struct{})
}

Expand All @@ -66,6 +73,9 @@ func initDB() {
gormDB, err = gorm.Open(mysql.New(mysql.Config{
Conn: sqlDB,
}), &gorm.Config{})
if err != nil {
panic("open DB error")
}
}

// insertData insert one data
Expand Down
6 changes: 4 additions & 2 deletions at/grpc/cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ func main() {
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
defer func() {
_ = conn.Close()
}()
businessClient := __.NewATServiceBusinessClient(conn)

client.InitPath("../../../../conf/seatago.yml")
tm.WithGlobalTx(
_ = tm.WithGlobalTx(
context.Background(),
&tm.GtxConfig{
Name: "XASampleLocalGlobalTx",
Expand Down
8 changes: 4 additions & 4 deletions at/non_transaction/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ func main() {

insertId := insertData()

// insertDuplicateData(insertId)
insertDuplicateData(insertId)

selectData(insertId)

updateData(insertId)
_ = updateData(insertId)

selectData(insertId)

deleteData(insertId)
_ = deleteData(insertId)

selectData(insertId)

userIds := batchInsertData()

batchDeleteData(userIds)
_ = batchDeleteData(userIds)

<-make(chan struct{})
}
Expand Down
2 changes: 1 addition & 1 deletion at/rollback/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ func main() {
sampleUpdate(bgCtx)

// sample insert on update
// sampleInsertOnUpdate(bgCtx)
sampleInsertOnUpdate(bgCtx)
}
11 changes: 10 additions & 1 deletion integrate_test/at/insert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"database/sql"
"fmt"
"log"
"time"

"gorm.io/driver/mysql"
Expand All @@ -43,11 +44,16 @@ func main() {
initConfig()

// test: insert
tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
err := tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
Name: "ATSampleLocalGlobalTx",
Timeout: time.Second * 30,
}, insertData)

if err != nil {
log.Fatalf("failed to init transaction: %v", err)
return
}

ctx := context.Background()

// check
Expand Down Expand Up @@ -78,6 +84,9 @@ func initDB() {
gormDB, err = gorm.Open(mysql.New(mysql.Config{
Conn: sqlDB,
}), &gorm.Config{})
if err != nil {
panic("open DB error")
}
}

func getData() OrderTblModel {
Expand Down
2 changes: 1 addition & 1 deletion tcc/dubbo/client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
}

func run() {
tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
_ = tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
Name: "TccSampleLocalGlobalTx",
}, business)
<-make(chan struct{})
Expand Down
2 changes: 1 addition & 1 deletion tcc/fence/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func main() {
client.InitPath("../../../conf/seatago.yml")
tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
_ = tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
Name: "TccSampleLocalGlobalTx",
}, business)
<-make(chan struct{})
Expand Down
Loading
Loading