go.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. - name: Check Go module tidiness and generated files
  40. shell: bash
  41. run: |
  42. go mod tidy
  43. task generate
  44. task generate-schemadoc
  45. STATUS=$(git status --porcelain)
  46. if [ ! -z "$STATUS" ]; then
  47. echo "Unstaged files:"
  48. echo $STATUS
  49. echo "Run 'go mod tidy', 'task generate' or 'task generate-schemadoc' and commit them"
  50. exit 1
  51. fi
  52. test:
  53. name: Test
  54. strategy:
  55. matrix:
  56. go-version: [ 1.16.x, 1.17.x, 1.18.x ]
  57. platform: [ ubuntu-latest, macos-latest, windows-latest ]
  58. runs-on: ${{ matrix.platform }}
  59. steps:
  60. - name: Install Go
  61. uses: actions/setup-go@v2
  62. with:
  63. go-version: ${{ matrix.go-version }}
  64. - name: Checkout code
  65. uses: actions/checkout@v2
  66. - name: Run tests with coverage
  67. run: go test -v -race -coverprofile=coverage -covermode=atomic ./...
  68. - name: Upload coverage report to Codecov
  69. uses: codecov/[email protected]
  70. with:
  71. file: ./coverage
  72. flags: unittests
  73. - name: Send email on failure
  74. uses: dawidd6/action-send-mail@v3
  75. if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  76. with:
  77. server_address: smtp.mailgun.org
  78. server_port: 465
  79. username: ${{ secrets.SMTP_USERNAME }}
  80. password: ${{ secrets.SMTP_PASSWORD }}
  81. subject: GitHub Actions (${{ github.repository }}) job result
  82. to: [email protected]
  83. from: GitHub Actions (${{ github.repository }})
  84. reply_to: [email protected]
  85. body: |
  86. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  87. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  88. postgres:
  89. name: Postgres
  90. strategy:
  91. matrix:
  92. go-version: [ 1.16.x, 1.17.x, 1.18.x ]
  93. platform: [ ubuntu-latest ]
  94. runs-on: ${{ matrix.platform }}
  95. services:
  96. postgres:
  97. image: postgres:9.6
  98. env:
  99. POSTGRES_PASSWORD: postgres
  100. options: >-
  101. --health-cmd pg_isready
  102. --health-interval 10s
  103. --health-timeout 5s
  104. --health-retries 5
  105. ports:
  106. - 5432:5432
  107. steps:
  108. - name: Install Go
  109. uses: actions/setup-go@v2
  110. with:
  111. go-version: ${{ matrix.go-version }}
  112. - name: Checkout code
  113. uses: actions/checkout@v2
  114. - name: Run tests with coverage
  115. run: go test -v -race -coverprofile=coverage -covermode=atomic ./internal/db
  116. env:
  117. GOGS_DATABASE_TYPE: postgres
  118. PGPORT: 5432
  119. PGHOST: localhost
  120. PGUSER: postgres
  121. PGPASSWORD: postgres
  122. PGSSLMODE: disable
  123. mysql:
  124. name: MySQL
  125. strategy:
  126. matrix:
  127. go-version: [ 1.16.x, 1.17.x, 1.18.x ]
  128. platform: [ ubuntu-18.04 ]
  129. runs-on: ${{ matrix.platform }}
  130. steps:
  131. - name: Start MySQL server
  132. run: sudo systemctl start mysql
  133. - name: Install Go
  134. uses: actions/setup-go@v2
  135. with:
  136. go-version: ${{ matrix.go-version }}
  137. - name: Checkout code
  138. uses: actions/checkout@v2
  139. - name: Run tests with coverage
  140. run: go test -v -race -coverprofile=coverage -covermode=atomic ./internal/db
  141. env:
  142. GOGS_DATABASE_TYPE: mysql
  143. MYSQL_USER: root
  144. MYSQL_PASSWORD: root
  145. MYSQL_HOST: localhost
  146. MYSQL_PORT: 3306
  147. sqlite-go:
  148. name: SQLite (Go)
  149. strategy:
  150. matrix:
  151. go-version: [ 1.16.x, 1.17.x, 1.18.x ]
  152. platform: [ ubuntu-latest ]
  153. runs-on: ${{ matrix.platform }}
  154. steps:
  155. - name: Install Go
  156. uses: actions/setup-go@v2
  157. with:
  158. go-version: ${{ matrix.go-version }}
  159. - name: Checkout code
  160. uses: actions/checkout@v2
  161. - name: Run tests with coverage
  162. run: go test -v -race -parallel=1 -coverprofile=coverage -covermode=atomic ./internal/db
  163. env:
  164. GOGS_DATABASE_TYPE: sqlite