go.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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: go test -shuffle=on -v -race -coverprofile=coverage -covermode=atomic ./...
  73. - name: Upload coverage report to Codecov
  74. uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
  75. with:
  76. file: ./coverage
  77. flags: unittests
  78. - name: Send email on failure
  79. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  80. if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  81. with:
  82. smtp_username: ${{ secrets.SMTP_USERNAME }}
  83. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  84. # Running tests with race detection consumes too much memory on Windows,
  85. # see https://github.com/golang/go/issues/46099 for details.
  86. test-windows:
  87. name: Test Windows
  88. strategy:
  89. matrix:
  90. go-version: [ 1.25.x ]
  91. platform: [ windows-latest ]
  92. runs-on: ${{ matrix.platform }}
  93. steps:
  94. - name: Checkout code
  95. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  96. - name: Install Go
  97. uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
  98. with:
  99. go-version: ${{ matrix.go-version }}
  100. - name: Run tests with coverage
  101. run: go test -shuffle=on -v -coverprofile=coverage -covermode=atomic ./...
  102. - name: Upload coverage report to Codecov
  103. uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
  104. with:
  105. file: ./coverage
  106. flags: unittests
  107. - name: Send email on failure
  108. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  109. if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  110. with:
  111. smtp_username: ${{ secrets.SMTP_USERNAME }}
  112. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  113. postgres:
  114. name: Postgres
  115. strategy:
  116. matrix:
  117. go-version: [ 1.25.x ]
  118. platform: [ ubuntu-latest ]
  119. runs-on: ${{ matrix.platform }}
  120. services:
  121. postgres:
  122. image: postgres:9.6
  123. env:
  124. POSTGRES_PASSWORD: postgres
  125. options: >-
  126. --health-cmd pg_isready
  127. --health-interval 10s
  128. --health-timeout 5s
  129. --health-retries 5
  130. ports:
  131. - 5432:5432
  132. steps:
  133. - name: Checkout code
  134. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  135. - name: Install Go
  136. uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
  137. with:
  138. go-version: ${{ matrix.go-version }}
  139. - name: Run tests with coverage
  140. run: go test -shuffle=on -v -race -coverprofile=coverage -covermode=atomic ./internal/database/...
  141. env:
  142. GOGS_DATABASE_TYPE: postgres
  143. PGPORT: 5432
  144. PGHOST: localhost
  145. PGUSER: postgres
  146. PGPASSWORD: postgres
  147. PGSSLMODE: disable
  148. mysql:
  149. name: MySQL
  150. strategy:
  151. matrix:
  152. go-version: [ 1.25.x ]
  153. platform: [ ubuntu-22.04 ] # Use the lowest version possible for backwards compatibility
  154. runs-on: ${{ matrix.platform }}
  155. steps:
  156. - name: Start MySQL server
  157. run: sudo systemctl start mysql
  158. - name: Checkout code
  159. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  160. - name: Install Go
  161. uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
  162. with:
  163. go-version: ${{ matrix.go-version }}
  164. - name: Run tests with coverage
  165. run: go test -shuffle=on -v -race -coverprofile=coverage -covermode=atomic ./internal/database/...
  166. env:
  167. GOGS_DATABASE_TYPE: mysql
  168. MYSQL_USER: root
  169. MYSQL_PASSWORD: root
  170. MYSQL_HOST: localhost
  171. MYSQL_PORT: 3306