-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from traPtitech/items
/items 実装
- Loading branch information
Showing
35 changed files
with
1,309 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
) | ||
|
||
func main() { | ||
conn, err := sql.Open("mysql", fmt.Sprintf( | ||
"%s:%s@tcp(%s:%s)/?charset=utf8mb4&parseTime=true", | ||
getEnvOrDefault("MYSQL_USERNAME", "root"), | ||
getEnvOrDefault("MYSQL_PASSWORD", "password"), | ||
getEnvOrDefault("MYSQL_HOST", "127.0.0.1"), | ||
getEnvOrDefault("MYSQL_PORT", "3306"), | ||
)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer conn.Close() | ||
|
||
dbs := []string{ | ||
"booq_test", | ||
} | ||
|
||
for _, name := range dbs { | ||
if _, err = conn.Exec("DROP DATABASE IF EXISTS " + name); err != nil { | ||
panic(err) | ||
} | ||
if _, err = conn.Exec("CREATE DATABASE `" + name + "` CHARACTER SET = utf8mb4"); err != nil { | ||
panic(err) | ||
} | ||
log.Println("Database `" + name + "` was created") | ||
} | ||
} | ||
|
||
func getEnvOrDefault(env string, def string) string { | ||
s := os.Getenv(env) | ||
if len(s) == 0 { | ||
return def | ||
} | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
name: Server build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: ./go.mod | ||
- name: mod | ||
run: go mod download | ||
- name: build | ||
run: go build | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: booQ | ||
path: booQ | ||
lint: | ||
name: Server lint | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: ./go.mod | ||
- name: Install reviewdog | ||
run: curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b $(go env GOPATH)/bin | ||
- name: Install golangci-lint | ||
run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin | ||
- name: golangci-lint | ||
run: golangci-lint run --out-format=line-number | reviewdog -f=golangci-lint -name=golangci-lint -reporter=github-check | ||
env: | ||
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
test: | ||
name: Server test | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
env: | ||
MYSQL_USER: root | ||
MYSQL_PASSWORD: password | ||
MYSQL_DATABASE: booq_test | ||
services: | ||
mysql: | ||
image: mariadb:10.11.7 | ||
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 | ||
env: | ||
MYSQL_ROOT_PASSWORD: password | ||
MYSQL_DATABASE: booq_test | ||
ports: | ||
- 3306:3306 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: ./go.mod | ||
- name: Setup DB | ||
run: go run .github/workflows/init.go | ||
- name: Run model tests | ||
run: go test . ./model -v -covermode=atomic -vet=off | ||
- name: Run router tests | ||
run: go test . ./router -v -covermode=atomic -vet=off | ||
spectral: | ||
name: OpenApi Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Spectral checks | ||
uses: stoplightio/[email protected] | ||
with: | ||
file_glob: docs/swagger.yml | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.