go.yml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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: Check Go module tidiness and generated files
  40. shell: bash
  41. run: |
  42. go mod tidy
  43. task generate
  44. STATUS=$(git status --porcelain)
  45. if [ ! -z "$STATUS" ]; then
  46. echo "Unstaged files:"
  47. echo $STATUS
  48. echo "Run 'go mod tidy' or 'task generate' commit them"
  49. exit 1
  50. fi
  51. test:
  52. name: Test
  53. strategy:
  54. matrix:
  55. go-version: [ 1.18.x, 1.19.x ]
  56. platform: [ ubuntu-latest, macos-latest ]
  57. runs-on: ${{ matrix.platform }}
  58. steps:
  59. - name: Install Go
  60. uses: actions/setup-go@v2
  61. with:
  62. go-version: ${{ matrix.go-version }}
  63. - name: Checkout code
  64. uses: actions/checkout@v2
  65. - name: Run tests with coverage
  66. run: go test -v -race -coverprofile=coverage -covermode=atomic ./...
  67. - name: Upload coverage report to Codecov
  68. uses: codecov/[email protected]
  69. with:
  70. file: ./coverage
  71. flags: unittests
  72. - name: Send email on failure
  73. uses: dawidd6/action-send-mail@v3
  74. if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  75. with:
  76. server_address: smtp.mailgun.org
  77. server_port: 465
  78. username: ${{ secrets.SMTP_USERNAME }}
  79. password: ${{ secrets.SMTP_PASSWORD }}
  80. subject: GitHub Actions (${{ github.repository }}) job result
  81. to: [email protected]
  82. from: GitHub Actions (${{ github.repository }})
  83. reply_to: [email protected]
  84. body: |
  85. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  86. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  87. # Running tests with race detection consumes too much memory on Windows,
  88. # see https://github.com/golang/go/issues/46099 for details.
  89. test-windows:
  90. name: Test
  91. strategy:
  92. matrix:
  93. go-version: [ 1.18.x, 1.19.x ]
  94. platform: [ windows-latest ]
  95. runs-on: ${{ matrix.platform }}
  96. steps:
  97. - name: Install Go
  98. uses: actions/setup-go@v2
  99. with:
  100. go-version: ${{ matrix.go-version }}
  101. - name: Checkout code
  102. uses: actions/checkout@v2
  103. - name: Run tests with coverage
  104. run: go test -v -coverprofile=coverage -covermode=atomic ./...
  105. - name: Upload coverage report to Codecov
  106. uses: codecov/[email protected]
  107. with:
  108. file: ./coverage
  109. flags: unittests
  110. - name: Send email on failure
  111. uses: dawidd6/action-send-mail@v3
  112. if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  113. with:
  114. server_address: smtp.mailgun.org
  115. server_port: 465
  116. username: ${{ secrets.SMTP_USERNAME }}
  117. password: ${{ secrets.SMTP_PASSWORD }}
  118. subject: GitHub Actions (${{ github.repository }}) job result
  119. to: [email protected]
  120. from: GitHub Actions (${{ github.repository }})
  121. reply_to: [email protected]
  122. body: |
  123. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  124. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  125. postgres:
  126. name: Postgres
  127. strategy:
  128. matrix:
  129. go-version: [ 1.18.x, 1.19.x ]
  130. platform: [ ubuntu-latest ]
  131. runs-on: ${{ matrix.platform }}
  132. services:
  133. postgres:
  134. image: postgres:9.6
  135. env:
  136. POSTGRES_PASSWORD: postgres
  137. options: >-
  138. --health-cmd pg_isready
  139. --health-interval 10s
  140. --health-timeout 5s
  141. --health-retries 5
  142. ports:
  143. - 5432:5432
  144. steps:
  145. - name: Install Go
  146. uses: actions/setup-go@v2
  147. with:
  148. go-version: ${{ matrix.go-version }}
  149. - name: Checkout code
  150. uses: actions/checkout@v2
  151. - name: Run tests with coverage
  152. run: go test -v -race -coverprofile=coverage -covermode=atomic ./internal/db/...
  153. env:
  154. GOGS_DATABASE_TYPE: postgres
  155. PGPORT: 5432
  156. PGHOST: localhost
  157. PGUSER: postgres
  158. PGPASSWORD: postgres
  159. PGSSLMODE: disable
  160. mysql:
  161. name: MySQL
  162. strategy:
  163. matrix:
  164. go-version: [ 1.18.x, 1.19.x ]
  165. platform: [ ubuntu-18.04 ]
  166. runs-on: ${{ matrix.platform }}
  167. steps:
  168. - name: Start MySQL server
  169. run: sudo systemctl start mysql
  170. - name: Install Go
  171. uses: actions/setup-go@v2
  172. with:
  173. go-version: ${{ matrix.go-version }}
  174. - name: Checkout code
  175. uses: actions/checkout@v2
  176. - name: Run tests with coverage
  177. run: go test -v -race -coverprofile=coverage -covermode=atomic ./internal/db/...
  178. env:
  179. GOGS_DATABASE_TYPE: mysql
  180. MYSQL_USER: root
  181. MYSQL_PASSWORD: root
  182. MYSQL_HOST: localhost
  183. MYSQL_PORT: 3306
  184. sqlite-go:
  185. name: SQLite - Go
  186. strategy:
  187. matrix:
  188. go-version: [ 1.18.x, 1.19.x ]
  189. platform: [ ubuntu-latest ]
  190. runs-on: ${{ matrix.platform }}
  191. steps:
  192. - name: Install Go
  193. uses: actions/setup-go@v2
  194. with:
  195. go-version: ${{ matrix.go-version }}
  196. - name: Checkout code
  197. uses: actions/checkout@v2
  198. - name: Run tests with coverage
  199. run: go test -v -race -parallel=1 -coverprofile=coverage -covermode=atomic ./internal/db/...
  200. env:
  201. GOGS_DATABASE_TYPE: sqlite