go.yml 6.6 KB

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