name: build
on:
  push:
    branches:
      - main
      - v2
  pull_request:
    branches:
      - main
      - v2

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Shutdown Ubuntu MySQL (SUDO)
        run: sudo service mysql stop # Shutdown the Default MySQL, "sudo" is necessary, please not remove it

      - uses: mirromutth/mysql-action@v1.1
        with:
          # host port: 3800 # Optional, default value is 3306. The port of host
          # container port: 3307 # Optional, default value is 3306. The port of container
          character set server: "utf8mb4" # Optional, default value is 'utf8mb4'. The '--character-set-server' option for mysqld
          collation server: "utf8mb4_unicode_ci" # Optional, default value is 'utf8mb4_general_ci'. The '--collation-server' option for mysqld
          mysql version: "8.0" # Optional, default value is "latest". The version of the MySQL
          mysql database: "sqlike" # Optional, default value is "test". The specified database which will be create
          mysql root password: "abcd1234" # Required if "mysql user" is empty, default is empty. The root superuser password
          # mysql user: "developer" # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Can use secrets, too
          # mysql password: "" # Required if "mysql user" exists. The password for the "mysql user"

      - name: Check out code into the Go module directory
        uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version: "1.20"

      - name: Get dependencies
        run: |
          go version
          go get -v -t -d ./...
          if [ -f Gopkg.toml ]; then
            curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
            dep ensure
          fi

      - name: Test
        run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...

      - name: Codecov
        uses: codecov/codecov-action@v3
        with:
          token: ${{secrets.CODECOV_TOKEN}}

      # - name: Golint
      #   run: |
      #     curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.10.2
      #     go get -u golang.org/x/lint/golint
      #     golangci-lint run
      #     golint -set_exit_status