* feat: add CI * feat: add CI and run gofumpt * Update conf.go * Delete migrate.yml * Update sync.yml * Update conf.go * Update file_cache.go * Update adapter.go * Update semantic.yml * Update storage_test.go * Update file_cache.go * Update conf.go * Update adapter.go * Update conf.go --------- Co-authored-by: hsluoyz <hsluoyz@qq.com>HEAD
| @@ -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 | |||||
| @@ -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 | |||||
| @@ -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 }} | |||||
| @@ -22,8 +22,10 @@ import ( | |||||
| "xorm.io/xorm" | "xorm.io/xorm" | ||||
| ) | ) | ||||
| var adapter *Adapter = nil | |||||
| var CasdoorOrganization string | |||||
| var ( | |||||
| adapter *Adapter = nil | |||||
| CasdoorOrganization string | |||||
| ) | |||||
| type Session struct { | type Session struct { | ||||
| SessionKey string `xorm:"char(64) notnull pk"` | SessionKey string `xorm:"char(64) notnull pk"` | ||||
| @@ -22,9 +22,11 @@ import ( | |||||
| "github.com/casbin/casibase/util" | "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() { | func init() { | ||||
| cacheDir = beego.AppConfig.String("cacheDir") | cacheDir = beego.AppConfig.String("cacheDir") | ||||
| @@ -35,7 +35,7 @@ func main() { | |||||
| AllowCredentials: true, | AllowCredentials: true, | ||||
| })) | })) | ||||
| //beego.DelStaticPath("/static") | |||||
| // beego.DelStaticPath("/static") | |||||
| beego.SetStaticPath("/static", "web/build/static") | beego.SetStaticPath("/static", "web/build/static") | ||||
| // https://studygolang.com/articles/2303 | // https://studygolang.com/articles/2303 | ||||
| beego.InsertFilter("/", beego.BeforeRouter, routers.TransparentStatic) // must has this for default page | beego.InsertFilter("/", beego.BeforeRouter, routers.TransparentStatic) // must has this for default page | ||||
| @@ -27,7 +27,7 @@ type Chat struct { | |||||
| CreatedTime string `xorm:"varchar(100)" json:"createdTime"` | CreatedTime string `xorm:"varchar(100)" json:"createdTime"` | ||||
| UpdatedTime string `xorm:"varchar(100)" json:"updatedTime"` | 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"` | DisplayName string `xorm:"varchar(100)" json:"displayName"` | ||||
| Category string `xorm:"varchar(100)" json:"category"` | Category string `xorm:"varchar(100)" json:"category"` | ||||
| Type string `xorm:"varchar(100)" json:"type"` | Type string `xorm:"varchar(100)" json:"type"` | ||||
| @@ -91,7 +91,7 @@ func UpdateChat(id string, chat *Chat) (bool, error) { | |||||
| return false, err | return false, err | ||||
| } | } | ||||
| //return affected != 0 | |||||
| // return affected != 0 | |||||
| return true, nil | return true, nil | ||||
| } | } | ||||
| @@ -92,7 +92,7 @@ func UpdateFactorset(id string, factorset *Factorset) (bool, error) { | |||||
| return false, err | return false, err | ||||
| } | } | ||||
| //return affected != 0 | |||||
| // return affected != 0 | |||||
| return true, nil | return true, nil | ||||
| } | } | ||||
| @@ -24,7 +24,7 @@ func TestDoFactorsetTsne(t *testing.T) { | |||||
| dimension := 50 | dimension := 50 | ||||
| //factorset := getFactorset("admin", "wikipedia") | |||||
| // factorset := getFactorset("admin", "wikipedia") | |||||
| factorset, _ := getFactorset("admin", "wordFactor_utf-8") | factorset, _ := getFactorset("admin", "wordFactor_utf-8") | ||||
| factorset.LoadFactors("../../tmpFiles/") | factorset.LoadFactors("../../tmpFiles/") | ||||
| factorset.DoTsne(dimension) | factorset.DoTsne(dimension) | ||||
| @@ -19,7 +19,7 @@ import "testing" | |||||
| func TestUpdateFactorsetFactors(t *testing.T) { | func TestUpdateFactorsetFactors(t *testing.T) { | ||||
| InitConfig() | InitConfig() | ||||
| //factorset := getFactorset("admin", "wikipedia") | |||||
| // factorset := getFactorset("admin", "wikipedia") | |||||
| factorset, _ := getFactorset("admin", "wordFactor_utf-8") | factorset, _ := getFactorset("admin", "wordFactor_utf-8") | ||||
| factorset.LoadFactors("../../tmpFiles/") | factorset.LoadFactors("../../tmpFiles/") | ||||
| UpdateFactorset(factorset.GetId(), factorset) | UpdateFactorset(factorset.GetId(), factorset) | ||||
| @@ -26,7 +26,7 @@ type Message struct { | |||||
| Name string `xorm:"varchar(100) notnull pk" json:"name"` | Name string `xorm:"varchar(100) notnull pk" json:"name"` | ||||
| CreatedTime string `xorm:"varchar(100)" json:"createdTime"` | 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"` | Chat string `xorm:"varchar(100) index" json:"chat"` | ||||
| ReplyTo string `xorm:"varchar(100) index" json:"replyTo"` | ReplyTo string `xorm:"varchar(100) index" json:"replyTo"` | ||||
| Author string `xorm:"varchar(100)" json:"author"` | Author string `xorm:"varchar(100)" json:"author"` | ||||
| @@ -88,7 +88,7 @@ func UpdateProvider(id string, provider *Provider) (bool, error) { | |||||
| return false, err | return false, err | ||||
| } | } | ||||
| //return affected != 0 | |||||
| // return affected != 0 | |||||
| return true, nil | return true, nil | ||||
| } | } | ||||
| @@ -118,7 +118,7 @@ func UpdateStore(id string, store *Store) (bool, error) { | |||||
| return false, err | return false, err | ||||
| } | } | ||||
| //return affected != 0 | |||||
| // return affected != 0 | |||||
| return true, nil | return true, nil | ||||
| } | } | ||||
| @@ -117,7 +117,7 @@ func (store *Store) Populate() error { | |||||
| tokens := strings.Split(strings.Trim(object.Key, "/"), "/") | tokens := strings.Split(strings.Trim(object.Key, "/"), "/") | ||||
| store.createPathIfNotExisted(tokens, size, lastModifiedTime, isLeaf) | 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 | return nil | ||||
| @@ -87,7 +87,7 @@ func UpdateVector(id string, vector *Vector) (bool, error) { | |||||
| return false, err | return false, err | ||||
| } | } | ||||
| //return affected != 0 | |||||
| // return affected != 0 | |||||
| return true, nil | return true, nil | ||||
| } | } | ||||
| @@ -102,7 +102,7 @@ func UpdateVideo(id string, video *Video) (bool, error) { | |||||
| return false, err | return false, err | ||||
| } | } | ||||
| //return affected != 0 | |||||
| // return affected != 0 | |||||
| return true, nil | return true, nil | ||||
| } | } | ||||
| @@ -87,7 +87,7 @@ func UpdateWordset(id string, wordset *Wordset) (bool, error) { | |||||
| return false, err | return false, err | ||||
| } | } | ||||
| //return affected != 0 | |||||
| // return affected != 0 | |||||
| return true, nil | return true, nil | ||||
| } | } | ||||
| @@ -63,7 +63,7 @@ func GetWordsetGraph(id string, clusterNumber int, distanceLimit int) (*Graph, e | |||||
| runKmeans(wordset.Factors, clusterNumber) | runKmeans(wordset.Factors, clusterNumber) | ||||
| g = generateGraph(wordset.Factors, distanceLimit) | g = generateGraph(wordset.Factors, distanceLimit) | ||||
| //graphCache[cacheId] = g | |||||
| // graphCache[cacheId] = g | |||||
| return g, nil | return g, nil | ||||
| } | } | ||||
| @@ -99,7 +99,7 @@ func getNodeColor(weight int) string { | |||||
| func generateGraph(factors []*Factor, distanceLimit int) *Graph { | func generateGraph(factors []*Factor, distanceLimit int) *Graph { | ||||
| factors = refineFactors(factors) | factors = refineFactors(factors) | ||||
| //factors = factors[:100] | |||||
| // factors = factors[:100] | |||||
| g := newGraph() | g := newGraph() | ||||
| g.Nodes = []*Node{} | g.Nodes = []*Node{} | ||||
| @@ -135,12 +135,12 @@ func generateGraph(factors []*Factor, distanceLimit int) *Graph { | |||||
| } | } | ||||
| for _, factor := range factors { | for _, factor := range factors { | ||||
| //value := 5 | |||||
| // value := 5 | |||||
| value := int(math.Sqrt(float64(nodeWeightMap[factor.Name]))) + 3 | value := int(math.Sqrt(float64(nodeWeightMap[factor.Name]))) + 3 | ||||
| weight := nodeWeightMap[factor.Name] | weight := nodeWeightMap[factor.Name] | ||||
| //nodeColor := "rgb(232,67,62)" | |||||
| //nodeColor := getNodeColor(value) | |||||
| // nodeColor := "rgb(232,67,62)" | |||||
| // nodeColor := getNodeColor(value) | |||||
| nodeColor := factor.Color | nodeColor := factor.Color | ||||
| fmt.Printf("Node [%s]: weight = %d, nodeValue = %d\n", factor.Name, nodeWeightMap[factor.Name], value) | fmt.Printf("Node [%s]: weight = %d, nodeValue = %d\n", factor.Name, nodeWeightMap[factor.Name], value) | ||||
| @@ -24,12 +24,11 @@ func init() { | |||||
| } | } | ||||
| func initAPI() { | func initAPI() { | ||||
| ns := | |||||
| beego.NewNamespace("/api", | |||||
| beego.NSInclude( | |||||
| &controllers.ApiController{}, | |||||
| ), | |||||
| ) | |||||
| ns := beego.NewNamespace("/api", | |||||
| beego.NSInclude( | |||||
| &controllers.ApiController{}, | |||||
| ), | |||||
| ) | |||||
| beego.AddNamespace(ns) | beego.AddNamespace(ns) | ||||
| beego.Router("/api/signin", &controllers.ApiController{}, "POST:Signin") | beego.Router("/api/signin", &controllers.ApiController{}, "POST:Signin") | ||||
| @@ -58,7 +58,7 @@ func ListObjects(bucketName string, prefix string) ([]oss.ObjectProperties, erro | |||||
| for _, object := range resp.Objects { | for _, object := range resp.Objects { | ||||
| res = append(res, object) | res = append(res, object) | ||||
| //fmt.Printf("[%d] %s\n", i, object.Key) | |||||
| // fmt.Printf("[%d] %s\n", i, object.Key) | |||||
| i += 1 | i += 1 | ||||
| } | } | ||||
| @@ -14,6 +14,8 @@ | |||||
| package storage | package storage | ||||
| var endpoint = "" | |||||
| var clientId = "" | |||||
| var clientSecret = "" | |||||
| var ( | |||||
| endpoint = "" | |||||
| clientId = "" | |||||
| clientSecret = "" | |||||
| ) | |||||
| @@ -12,6 +12,9 @@ | |||||
| // See the License for the specific language governing permissions and | // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | // limitations under the License. | ||||
| //go:build !skipCi | |||||
| // +build !skipCi | |||||
| package storage | package storage | ||||
| import "testing" | import "testing" | ||||
| @@ -18,7 +18,7 @@ import "encoding/json" | |||||
| func StructToJson(v interface{}) string { | func StructToJson(v interface{}) string { | ||||
| data, err := json.MarshalIndent(v, "", " ") | data, err := json.MarshalIndent(v, "", " ") | ||||
| //data, err := json.Marshal(v) | |||||
| // data, err := json.Marshal(v) | |||||
| if err != nil { | if err != nil { | ||||
| panic(err) | panic(err) | ||||
| } | } | ||||
| @@ -98,7 +98,7 @@ func CopyFile(dest string, src string) { | |||||
| panic(err) | panic(err) | ||||
| } | } | ||||
| err = os.WriteFile(dest, bs, 0644) | |||||
| err = os.WriteFile(dest, bs, 0o644) | |||||
| if err != nil { | if err != nil { | ||||
| panic(err) | panic(err) | ||||
| } | } | ||||
| @@ -109,7 +109,7 @@ func ReadStringFromPath(path string) string { | |||||
| } | } | ||||
| func WriteStringToPath(s string, path string) { | func WriteStringToPath(s string, path string) { | ||||
| err := ioutil.WriteFile(path, []byte(s), 0644) | |||||
| err := ioutil.WriteFile(path, []byte(s), 0o644) | |||||
| if err != nil { | if err != nil { | ||||
| panic(err) | panic(err) | ||||
| } | } | ||||
| @@ -125,7 +125,7 @@ func ReadBytesFromPath(path string) []byte { | |||||
| } | } | ||||
| func WriteBytesToPath(b []byte, path string) { | func WriteBytesToPath(b []byte, path string) { | ||||
| err := ioutil.WriteFile(path, b, 0644) | |||||
| err := ioutil.WriteFile(path, b, 0o644) | |||||
| if err != nil { | if err != nil { | ||||
| panic(err) | panic(err) | ||||
| } | } | ||||
| @@ -14,6 +14,8 @@ | |||||
| package video | package video | ||||
| var regionId = "" | |||||
| var accessKeyId = "" | |||||
| var accessKeySecret = "" | |||||
| var ( | |||||
| regionId = "" | |||||
| accessKeyId = "" | |||||
| accessKeySecret = "" | |||||
| ) | |||||