go.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  32. - name: Install Go
  33. uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
  34. with:
  35. go-version: 1.25.x
  36. - name: Install Task
  37. uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
  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@9fae48acfc02a90574d7c304a1758ef9895495fa # v7.0.1
  54. with:
  55. version: latest
  56. args: --timeout=30m
  57. test:
  58. name: Test
  59. strategy:
  60. matrix:
  61. go-version: [ 1.25.x ]
  62. platform: [ ubuntu-latest, macos-latest ]
  63. runs-on: ${{ matrix.platform }}
  64. steps:
  65. - name: Checkout code
  66. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  67. - name: Install Go
  68. uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
  69. with:
  70. go-version: ${{ matrix.go-version }}
  71. - name: Run tests with coverage
  72. run: |
  73. go test -shuffle=on -v -race -coverprofile=coverage -covermode=atomic -json ./... > test-report.json
  74. go install github.com/mfridman/tparse@latest
  75. tparse -all -file=test-report.json
  76. - name: Upload coverage report to Codecov
  77. uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
  78. with:
  79. file: ./coverage
  80. flags: unittests
  81. - name: Send email on failure
  82. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  83. if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  84. with:
  85. smtp_username: ${{ secrets.SMTP_USERNAME }}
  86. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  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 Windows
  91. strategy:
  92. matrix:
  93. go-version: [ 1.25.x ]
  94. platform: [ windows-latest ]
  95. runs-on: ${{ matrix.platform }}
  96. steps:
  97. - name: Checkout code
  98. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  99. - name: Install Go
  100. uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
  101. with:
  102. go-version: ${{ matrix.go-version }}
  103. - name: Run tests with coverage
  104. run: go test -shuffle=on -v -coverprofile=coverage -covermode=atomic ./...
  105. - name: Upload coverage report to Codecov
  106. uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
  107. with:
  108. file: ./coverage
  109. flags: unittests
  110. - name: Send email on failure
  111. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  112. if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  113. with:
  114. smtp_username: ${{ secrets.SMTP_USERNAME }}
  115. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  116. postgres:
  117. name: Postgres
  118. strategy:
  119. matrix:
  120. go-version: [ 1.25.x ]
  121. platform: [ ubuntu-latest ]
  122. runs-on: ${{ matrix.platform }}
  123. services:
  124. postgres:
  125. image: postgres:9.6
  126. env:
  127. POSTGRES_PASSWORD: postgres
  128. options: >-
  129. --health-cmd pg_isready
  130. --health-interval 10s
  131. --health-timeout 5s
  132. --health-retries 5
  133. ports:
  134. - 5432:5432
  135. steps:
  136. - name: Checkout code
  137. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  138. - name: Install Go
  139. uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
  140. with:
  141. go-version: ${{ matrix.go-version }}
  142. - name: Run tests with coverage
  143. run: |
  144. go test -shuffle=on -v -race -coverprofile=coverage -covermode=atomic -json ./internal/database/... > test-report.json
  145. go install github.com/mfridman/tparse@latest
  146. tparse -all -file=test-report.json
  147. env:
  148. GOGS_DATABASE_TYPE: postgres
  149. PGPORT: 5432
  150. PGHOST: localhost
  151. PGUSER: postgres
  152. PGPASSWORD: postgres
  153. PGSSLMODE: disable
  154. mysql:
  155. name: MySQL
  156. strategy:
  157. matrix:
  158. go-version: [ 1.25.x ]
  159. platform: [ ubuntu-22.04 ] # Use the lowest version possible for backwards compatibility
  160. runs-on: ${{ matrix.platform }}
  161. steps:
  162. - name: Start MySQL server
  163. run: sudo systemctl start mysql
  164. - name: Checkout code
  165. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  166. - name: Install Go
  167. uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
  168. with:
  169. go-version: ${{ matrix.go-version }}
  170. - name: Run tests with coverage
  171. run: |
  172. go test -shuffle=on -v -race -coverprofile=coverage -covermode=atomic -json ./internal/database/... > test-report.json
  173. go install github.com/mfridman/tparse@latest
  174. tparse -all -file=test-report.json
  175. env:
  176. GOGS_DATABASE_TYPE: mysql
  177. MYSQL_USER: root
  178. MYSQL_PASSWORD: root
  179. MYSQL_HOST: localhost
  180. MYSQL_PORT: 3306