From 0200bea480c8842196ea0edf8609cf9d24f9fbc9 Mon Sep 17 00:00:00 2001 From: Miguel Cabrerizo Date: Fri, 2 Sep 2022 15:52:02 +0200 Subject: [PATCH] feat: Closes #36 add workflow for building and testing --- .github/workflows/build_test.yml | 23 ++++++++++++++++++++ server/db/initialize.go | 37 +++++++++++++++++++------------- 2 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/build_test.yml diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml new file mode 100644 index 0000000..196a714 --- /dev/null +++ b/.github/workflows/build_test.yml @@ -0,0 +1,23 @@ +name: Test and Build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + env: + ENV: test + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.18 + check-latest: true + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... \ No newline at end of file diff --git a/server/db/initialize.go b/server/db/initialize.go index dd37945..f40fe68 100644 --- a/server/db/initialize.go +++ b/server/db/initialize.go @@ -19,6 +19,7 @@ package db import ( "errors" "fmt" + "os" "strings" "github.com/doncicuto/glim/models" @@ -102,14 +103,17 @@ func createManager(db *gorm.DB, initialPassword string) error { }).Error; err != nil { return err } - fmt.Println("") - fmt.Println("------------------------------------- WARNING -------------------------------------") - fmt.Println("A new user with manager permissions has been created:") - fmt.Println("- Username: admin") // TODO - Allow username with env - fmt.Printf("- Password %s\n", chosenPassword) - fmt.Println("Please store or write down this password to manage Glim.") - fmt.Println("You can delete this user once you assign manager permissions to another user") - fmt.Println("-----------------------------------------------------------------------------------") + + if os.Getenv("ENV") != "test" { + fmt.Println("") + fmt.Println("------------------------------------- WARNING -------------------------------------") + fmt.Println("A new user with manager permissions has been created:") + fmt.Println("- Username: admin") // TODO - Allow username with env + fmt.Printf("- Password %s\n", chosenPassword) + fmt.Println("Please store or write down this password to manage Glim.") + fmt.Println("You can delete this user once you assign manager permissions to another user") + fmt.Println("-----------------------------------------------------------------------------------") + } return nil } @@ -150,13 +154,16 @@ func createReadonly(db *gorm.DB, initialPassword string) error { }).Error; err != nil { return err } - fmt.Println("") - fmt.Println("------------------------------------- WARNING -------------------------------------") - fmt.Println("A new user with read-only permissions has been created:") - fmt.Println("- Username: search") // TODO - Allow username with env - fmt.Printf("- Password %s\n", chosenPassword) - fmt.Println("Please store or write down this password to perform search queries in Glim.") - fmt.Println("-----------------------------------------------------------------------------------") + + if os.Getenv("ENV") != "test" { + fmt.Println("") + fmt.Println("------------------------------------- WARNING -------------------------------------") + fmt.Println("A new user with read-only permissions has been created:") + fmt.Println("- Username: search") // TODO - Allow username with env + fmt.Printf("- Password %s\n", chosenPassword) + fmt.Println("Please store or write down this password to perform search queries in Glim.") + fmt.Println("-----------------------------------------------------------------------------------") + } return nil }