go.yml 6.8 KB

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