go.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. name: Go
  2. on:
  3. push:
  4. branches:
  5. - main
  6. - 'release/**'
  7. paths:
  8. - '**.go'
  9. - 'go.mod'
  10. - '.golangci.yml'
  11. - '.github/workflows/go.yml'
  12. pull_request:
  13. paths:
  14. - '**.go'
  15. - 'go.mod'
  16. - '.golangci.yml'
  17. - '.github/workflows/go.yml'
  18. env:
  19. GOPROXY: "https://proxy.golang.org"
  20. permissions:
  21. contents: read
  22. jobs:
  23. lint:
  24. permissions:
  25. contents: read # for actions/checkout to fetch code
  26. pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
  27. name: Lint
  28. runs-on: ubuntu-latest
  29. steps:
  30. - name: Checkout code
  31. uses: actions/checkout@v2
  32. - name: Run golangci-lint
  33. uses: golangci/golangci-lint-action@v2
  34. with:
  35. version: latest
  36. args: --timeout=30m
  37. - name: Install Task
  38. uses: arduino/setup-task@v1
  39. - name: Install goimports and go-mockgen
  40. run: |
  41. go install github.com/derision-test/go-mockgen/cmd/[email protected]
  42. go install golang.org/x/tools/cmd/goimports@latest
  43. - name: Check Go module tidiness and generated files
  44. shell: bash
  45. run: |
  46. go mod tidy
  47. task generate
  48. STATUS=$(git status --porcelain)
  49. if [ ! -z "$STATUS" ]; then
  50. echo "Unstaged files:"
  51. echo $STATUS
  52. echo "Run 'go mod tidy' or 'task generate' commit them"
  53. exit 1
  54. fi
  55. test:
  56. name: Test
  57. strategy:
  58. matrix:
  59. go-version: [ 1.16.x, 1.17.x, 1.18.x ]
  60. platform: [ ubuntu-latest, macos-latest, windows-latest ]
  61. runs-on: ${{ matrix.platform }}
  62. steps:
  63. - name: Install Go
  64. uses: actions/setup-go@v2
  65. with:
  66. go-version: ${{ matrix.go-version }}
  67. - name: Checkout code
  68. uses: actions/checkout@v2
  69. - name: Run tests with coverage
  70. run: go test -v -race -coverprofile=coverage -covermode=atomic ./...
  71. - name: Upload coverage report to Codecov
  72. uses: codecov/[email protected]
  73. with:
  74. file: ./coverage
  75. flags: unittests
  76. - name: Send email on failure
  77. uses: dawidd6/action-send-mail@v3
  78. if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  79. with:
  80. server_address: smtp.mailgun.org
  81. server_port: 465
  82. username: ${{ secrets.SMTP_USERNAME }}
  83. password: ${{ secrets.SMTP_PASSWORD }}
  84. subject: GitHub Actions (${{ github.repository }}) job result
  85. to: [email protected]
  86. from: GitHub Actions (${{ github.repository }})
  87. reply_to: [email protected]
  88. body: |
  89. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  90. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  91. postgres:
  92. name: Postgres
  93. strategy:
  94. matrix:
  95. go-version: [ 1.16.x, 1.17.x, 1.18.x ]
  96. platform: [ ubuntu-latest ]
  97. runs-on: ${{ matrix.platform }}
  98. services:
  99. postgres:
  100. image: postgres:9.6
  101. env:
  102. POSTGRES_PASSWORD: postgres
  103. options: >-
  104. --health-cmd pg_isready
  105. --health-interval 10s
  106. --health-timeout 5s
  107. --health-retries 5
  108. ports:
  109. - 5432:5432
  110. steps:
  111. - name: Install Go
  112. uses: actions/setup-go@v2
  113. with:
  114. go-version: ${{ matrix.go-version }}
  115. - name: Checkout code
  116. uses: actions/checkout@v2
  117. - name: Run tests with coverage
  118. run: go test -v -race -coverprofile=coverage -covermode=atomic ./internal/db
  119. env:
  120. GOGS_DATABASE_TYPE: postgres
  121. PGPORT: 5432
  122. PGHOST: localhost
  123. PGUSER: postgres
  124. PGPASSWORD: postgres
  125. PGSSLMODE: disable
  126. mysql:
  127. name: MySQL
  128. strategy:
  129. matrix:
  130. go-version: [ 1.16.x, 1.17.x, 1.18.x ]
  131. platform: [ ubuntu-18.04 ]
  132. runs-on: ${{ matrix.platform }}
  133. steps:
  134. - name: Start MySQL server
  135. run: sudo systemctl start mysql
  136. - name: Install Go
  137. uses: actions/setup-go@v2
  138. with:
  139. go-version: ${{ matrix.go-version }}
  140. - name: Checkout code
  141. uses: actions/checkout@v2
  142. - name: Run tests with coverage
  143. run: go test -v -race -coverprofile=coverage -covermode=atomic ./internal/db
  144. env:
  145. GOGS_DATABASE_TYPE: mysql
  146. MYSQL_USER: root
  147. MYSQL_PASSWORD: root
  148. MYSQL_HOST: localhost
  149. MYSQL_PORT: 3306
  150. sqlite-go:
  151. name: SQLite (Go)
  152. strategy:
  153. matrix:
  154. go-version: [ 1.16.x, 1.17.x, 1.18.x ]
  155. platform: [ ubuntu-latest ]
  156. runs-on: ${{ matrix.platform }}
  157. steps:
  158. - name: Install Go
  159. uses: actions/setup-go@v2
  160. with:
  161. go-version: ${{ matrix.go-version }}
  162. - name: Checkout code
  163. uses: actions/checkout@v2
  164. - name: Run tests with coverage
  165. run: go test -v -race -parallel=1 -coverprofile=coverage -covermode=atomic ./internal/db
  166. env:
  167. GOGS_DATABASE_TYPE: sqlite