go.yml 6.7 KB

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