diff --git a/.github/semantic.yml b/.github/semantic.yml new file mode 100644 index 0000000..34b7f4d --- /dev/null +++ b/.github/semantic.yml @@ -0,0 +1,12 @@ +# Always validate the PR title AND all the commits +titleAndCommits: true +# Require at least one commit to be valid +# this is only relevant when using commitsOnly: true or titleAndCommits: true, +# which validate all commits by default +anyCommit: true +# Allow use of Merge commits (eg on github: "Merge branch 'master' into feature/ride-unicorns") +# this is only relevant when using commitsOnly: true (or titleAndCommits: true) +allowMergeCommits: false +# Allow use of Revert commits (eg on github: "Revert "feat: ride unicorns"") +# this is only relevant when using commitsOnly: true (or titleAndCommits: true) +allowRevertCommits: false diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..97ff760 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,164 @@ +name: Build + +on: [push, pull_request] + +jobs: + + go-tests: + name: Running Go tests + runs-on: ubuntu-latest + services: + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: casdoor + MYSQL_ROOT_PASSWORD: 123456 + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: '^1.16.5' + cache-dependency-path: ./go.mod + - name: Tests + run: | + # go test -v $(go list ./...) -tags skipCi + working-directory: ./ + + frontend: + name: Front-end + runs-on: ubuntu-latest + needs: [ go-tests ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'yarn' + cache-dependency-path: ./web/yarn.lock + - run: yarn install && CI=false yarn run build + working-directory: ./web + + backend: + name: Back-end + runs-on: ubuntu-latest + needs: [ go-tests ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: '^1.16.5' + cache-dependency-path: ./go.mod + - run: go version + - name: Build + run: | + go build -race -ldflags "-extldflags '-static'" + working-directory: ./ + + linter: + name: Go-Linter + runs-on: ubuntu-latest + needs: [ go-tests ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: '^1.16.5' + cache: false + + # gen a dummy config file + - run: touch dummy.yml + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: --disable-all -c dummy.yml -E=gofumpt --max-same-issues=0 --timeout 5m --modules-download-mode=mod + + + release-and-push: + name: Release And Push + runs-on: ubuntu-latest + if: github.repository == 'casbin/casibase' && github.event_name == 'push' + needs: [ frontend, backend, linter] + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: -1 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + + - name: Fetch Previous version + id: get-previous-tag + uses: actions-ecosystem/action-get-latest-tag@v1.6.0 + + - name: Release + run: yarn global add semantic-release@17.4.4 && semantic-release + env: + GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }} + + - name: Fetch Current version + id: get-current-tag + uses: actions-ecosystem/action-get-latest-tag@v1.6.0 + + - name: Decide Should_Push Or Not + id: should_push + run: | + old_version=${{steps.get-previous-tag.outputs.tag}} + new_version=${{steps.get-current-tag.outputs.tag }} + + old_array=(${old_version//\./ }) + new_array=(${new_version//\./ }) + + if [ ${old_array[0]} != ${new_array[0]} ] + then + echo ::set-output name=push::'true' + elif [ ${old_array[1]} != ${new_array[1]} ] + then + echo ::set-output name=push::'true' + + else + echo ::set-output name=push::'false' + + fi + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up buildx + id: buildx + uses: docker/setup-buildx-action@v2 + with: + version: latest + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + if: github.repository == 'casbin/casibase' && github.event_name == 'push' && steps.should_push.outputs.push=='true' + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Push to Docker Hub + uses: docker/build-push-action@v3 + if: github.repository == 'casbin/casibase' && github.event_name == 'push' && steps.should_push.outputs.push=='true' + with: + context: . + target: STANDARD + platforms: linux/amd64,linux/arm64 + push: true + tags: casbin/casibase:${{steps.get-current-tag.outputs.tag }},casbin/casibase:latest + + - name: Push All In One Version to Docker Hub + uses: docker/build-push-action@v3 + if: github.repository == 'casbin/casibase' && github.event_name == 'push' && steps.should_push.outputs.push=='true' + with: + context: . + target: ALLINONE + platforms: linux/amd64,linux/arm64 + push: true + tags: casbin/casibase-all-in-one:${{steps.get-current-tag.outputs.tag }},casbin/casibase-all-in-one:latest diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 0000000..06c56b2 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,56 @@ +name: Crowdin Action + +on: + push: + branches: [ master ] + +jobs: + synchronize-with-crowdin: + runs-on: ubuntu-latest + if: github.repository == 'casbin/casibase' && github.event_name == 'push' + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: crowdin action + uses: crowdin/github-action@1.4.8 + with: + upload_translations: true + + download_translations: true + push_translations: true + commit_message: 'refactor: New Crowdin translations by Github Action' + + localization_branch_name: l10n_crowdin_action + create_pull_request: true + pull_request_title: 'refactor: New Crowdin translations' + + crowdin_branch_name: l10n_branch + config: './web/crowdin.yml' + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CROWDIN_PROJECT_ID: '463556' + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} + + - name: crowdin backend action + uses: crowdin/github-action@1.4.8 + with: + upload_translations: true + + download_translations: true + push_translations: true + commit_message: 'refactor: New Crowdin Backend translations by Github Action' + + localization_branch_name: l10n_crowdin_action + create_pull_request: true + pull_request_title: 'refactor: New Crowdin Backend translations' + + crowdin_branch_name: l10n_branch + config: './crowdin.yml' + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CROWDIN_PROJECT_ID: '463556' + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} diff --git a/casdoor/adapter.go b/casdoor/adapter.go index a6f3091..34c9bf1 100644 --- a/casdoor/adapter.go +++ b/casdoor/adapter.go @@ -22,8 +22,10 @@ import ( "xorm.io/xorm" ) -var adapter *Adapter = nil -var CasdoorOrganization string +var ( + adapter *Adapter = nil + CasdoorOrganization string +) type Session struct { SessionKey string `xorm:"char(64) notnull pk"` diff --git a/controllers/file_cache.go b/controllers/file_cache.go index 92ba7d7..3fd3910 100644 --- a/controllers/file_cache.go +++ b/controllers/file_cache.go @@ -22,9 +22,11 @@ import ( "github.com/casbin/casibase/util" ) -var cacheDir string -var appDir string -var cacheMap = map[string]string{} +var ( + cacheDir string + appDir string + cacheMap = map[string]string{} +) func init() { cacheDir = beego.AppConfig.String("cacheDir") diff --git a/main.go b/main.go index 40db5e7..d7c8caf 100644 --- a/main.go +++ b/main.go @@ -35,7 +35,7 @@ func main() { AllowCredentials: true, })) - //beego.DelStaticPath("/static") + // beego.DelStaticPath("/static") beego.SetStaticPath("/static", "web/build/static") // https://studygolang.com/articles/2303 beego.InsertFilter("/", beego.BeforeRouter, routers.TransparentStatic) // must has this for default page diff --git a/object/chat.go b/object/chat.go index d266b65..702cb5f 100644 --- a/object/chat.go +++ b/object/chat.go @@ -27,7 +27,7 @@ type Chat struct { CreatedTime string `xorm:"varchar(100)" json:"createdTime"` UpdatedTime string `xorm:"varchar(100)" json:"updatedTime"` - //Organization string `xorm:"varchar(100)" json:"organization"` + // Organization string `xorm:"varchar(100)" json:"organization"` DisplayName string `xorm:"varchar(100)" json:"displayName"` Category string `xorm:"varchar(100)" json:"category"` Type string `xorm:"varchar(100)" json:"type"` @@ -91,7 +91,7 @@ func UpdateChat(id string, chat *Chat) (bool, error) { return false, err } - //return affected != 0 + // return affected != 0 return true, nil } diff --git a/object/factorset.go b/object/factorset.go index d47210c..215cde8 100644 --- a/object/factorset.go +++ b/object/factorset.go @@ -92,7 +92,7 @@ func UpdateFactorset(id string, factorset *Factorset) (bool, error) { return false, err } - //return affected != 0 + // return affected != 0 return true, nil } diff --git a/object/factorset_tsne_test.go b/object/factorset_tsne_test.go index 6ac968f..74d263c 100644 --- a/object/factorset_tsne_test.go +++ b/object/factorset_tsne_test.go @@ -24,7 +24,7 @@ func TestDoFactorsetTsne(t *testing.T) { dimension := 50 - //factorset := getFactorset("admin", "wikipedia") + // factorset := getFactorset("admin", "wikipedia") factorset, _ := getFactorset("admin", "wordFactor_utf-8") factorset.LoadFactors("../../tmpFiles/") factorset.DoTsne(dimension) diff --git a/object/factorset_upload_test.go b/object/factorset_upload_test.go index aaecb1c..6c76d66 100644 --- a/object/factorset_upload_test.go +++ b/object/factorset_upload_test.go @@ -19,7 +19,7 @@ import "testing" func TestUpdateFactorsetFactors(t *testing.T) { InitConfig() - //factorset := getFactorset("admin", "wikipedia") + // factorset := getFactorset("admin", "wikipedia") factorset, _ := getFactorset("admin", "wordFactor_utf-8") factorset.LoadFactors("../../tmpFiles/") UpdateFactorset(factorset.GetId(), factorset) diff --git a/object/message.go b/object/message.go index 333c05b..12eb682 100644 --- a/object/message.go +++ b/object/message.go @@ -26,7 +26,7 @@ type Message struct { Name string `xorm:"varchar(100) notnull pk" json:"name"` CreatedTime string `xorm:"varchar(100)" json:"createdTime"` - //Organization string `xorm:"varchar(100)" json:"organization"` + // Organization string `xorm:"varchar(100)" json:"organization"` Chat string `xorm:"varchar(100) index" json:"chat"` ReplyTo string `xorm:"varchar(100) index" json:"replyTo"` Author string `xorm:"varchar(100)" json:"author"` diff --git a/object/provider.go b/object/provider.go index 70730cc..49d87d3 100644 --- a/object/provider.go +++ b/object/provider.go @@ -88,7 +88,7 @@ func UpdateProvider(id string, provider *Provider) (bool, error) { return false, err } - //return affected != 0 + // return affected != 0 return true, nil } diff --git a/object/store.go b/object/store.go index 7f896ea..0a52a23 100644 --- a/object/store.go +++ b/object/store.go @@ -118,7 +118,7 @@ func UpdateStore(id string, store *Store) (bool, error) { return false, err } - //return affected != 0 + // return affected != 0 return true, nil } diff --git a/object/store_provider.go b/object/store_provider.go index e13bd43..fbf5173 100644 --- a/object/store_provider.go +++ b/object/store_provider.go @@ -117,7 +117,7 @@ func (store *Store) Populate() error { tokens := strings.Split(strings.Trim(object.Key, "/"), "/") store.createPathIfNotExisted(tokens, size, lastModifiedTime, isLeaf) - //fmt.Printf("%s, %d, %v\n", object.Key, object.Size, object.LastModified) + // fmt.Printf("%s, %d, %v\n", object.Key, object.Size, object.LastModified) } return nil diff --git a/object/vector.go b/object/vector.go index c559d49..417e6d1 100644 --- a/object/vector.go +++ b/object/vector.go @@ -87,7 +87,7 @@ func UpdateVector(id string, vector *Vector) (bool, error) { return false, err } - //return affected != 0 + // return affected != 0 return true, nil } diff --git a/object/video.go b/object/video.go index 4570e81..a89074c 100644 --- a/object/video.go +++ b/object/video.go @@ -102,7 +102,7 @@ func UpdateVideo(id string, video *Video) (bool, error) { return false, err } - //return affected != 0 + // return affected != 0 return true, nil } diff --git a/object/wordset.go b/object/wordset.go index c172ff6..a931db9 100644 --- a/object/wordset.go +++ b/object/wordset.go @@ -87,7 +87,7 @@ func UpdateWordset(id string, wordset *Wordset) (bool, error) { return false, err } - //return affected != 0 + // return affected != 0 return true, nil } diff --git a/object/wordset_graph.go b/object/wordset_graph.go index 0177da5..4fa077f 100644 --- a/object/wordset_graph.go +++ b/object/wordset_graph.go @@ -63,7 +63,7 @@ func GetWordsetGraph(id string, clusterNumber int, distanceLimit int) (*Graph, e runKmeans(wordset.Factors, clusterNumber) g = generateGraph(wordset.Factors, distanceLimit) - //graphCache[cacheId] = g + // graphCache[cacheId] = g return g, nil } @@ -99,7 +99,7 @@ func getNodeColor(weight int) string { func generateGraph(factors []*Factor, distanceLimit int) *Graph { factors = refineFactors(factors) - //factors = factors[:100] + // factors = factors[:100] g := newGraph() g.Nodes = []*Node{} @@ -135,12 +135,12 @@ func generateGraph(factors []*Factor, distanceLimit int) *Graph { } for _, factor := range factors { - //value := 5 + // value := 5 value := int(math.Sqrt(float64(nodeWeightMap[factor.Name]))) + 3 weight := nodeWeightMap[factor.Name] - //nodeColor := "rgb(232,67,62)" - //nodeColor := getNodeColor(value) + // nodeColor := "rgb(232,67,62)" + // nodeColor := getNodeColor(value) nodeColor := factor.Color fmt.Printf("Node [%s]: weight = %d, nodeValue = %d\n", factor.Name, nodeWeightMap[factor.Name], value) diff --git a/routers/router.go b/routers/router.go index 31f6158..51f2b79 100644 --- a/routers/router.go +++ b/routers/router.go @@ -24,12 +24,11 @@ func init() { } func initAPI() { - ns := - beego.NewNamespace("/api", - beego.NSInclude( - &controllers.ApiController{}, - ), - ) + ns := beego.NewNamespace("/api", + beego.NSInclude( + &controllers.ApiController{}, + ), + ) beego.AddNamespace(ns) beego.Router("/api/signin", &controllers.ApiController{}, "POST:Signin") diff --git a/storage/aliyun.go b/storage/aliyun.go index e462a41..d8ec4fd 100644 --- a/storage/aliyun.go +++ b/storage/aliyun.go @@ -58,7 +58,7 @@ func ListObjects(bucketName string, prefix string) ([]oss.ObjectProperties, erro for _, object := range resp.Objects { res = append(res, object) - //fmt.Printf("[%d] %s\n", i, object.Key) + // fmt.Printf("[%d] %s\n", i, object.Key) i += 1 } diff --git a/storage/conf.go b/storage/conf.go index ee7ed69..cd81610 100644 --- a/storage/conf.go +++ b/storage/conf.go @@ -14,6 +14,8 @@ package storage -var endpoint = "" -var clientId = "" -var clientSecret = "" +var ( + endpoint = "" + clientId = "" + clientSecret = "" +) diff --git a/storage/storage_test.go b/storage/storage_test.go index 62c2555..f20bc4f 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !skipCi +// +build !skipCi + package storage import "testing" diff --git a/util/json.go b/util/json.go index abeb0e1..a5e5127 100644 --- a/util/json.go +++ b/util/json.go @@ -18,7 +18,7 @@ import "encoding/json" func StructToJson(v interface{}) string { data, err := json.MarshalIndent(v, "", " ") - //data, err := json.Marshal(v) + // data, err := json.Marshal(v) if err != nil { panic(err) } diff --git a/util/path.go b/util/path.go index 8411caf..9d61cd8 100644 --- a/util/path.go +++ b/util/path.go @@ -98,7 +98,7 @@ func CopyFile(dest string, src string) { panic(err) } - err = os.WriteFile(dest, bs, 0644) + err = os.WriteFile(dest, bs, 0o644) if err != nil { panic(err) } diff --git a/util/string.go b/util/string.go index ed3af38..33fbb6e 100644 --- a/util/string.go +++ b/util/string.go @@ -109,7 +109,7 @@ func ReadStringFromPath(path string) string { } func WriteStringToPath(s string, path string) { - err := ioutil.WriteFile(path, []byte(s), 0644) + err := ioutil.WriteFile(path, []byte(s), 0o644) if err != nil { panic(err) } @@ -125,7 +125,7 @@ func ReadBytesFromPath(path string) []byte { } func WriteBytesToPath(b []byte, path string) { - err := ioutil.WriteFile(path, b, 0644) + err := ioutil.WriteFile(path, b, 0o644) if err != nil { panic(err) } diff --git a/video/conf.go b/video/conf.go index fdf6aba..1f0443f 100644 --- a/video/conf.go +++ b/video/conf.go @@ -14,6 +14,8 @@ package video -var regionId = "" -var accessKeyId = "" -var accessKeySecret = "" +var ( + regionId = "" + accessKeyId = "" + accessKeySecret = "" +)