go.yml 5.8 KB

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