go.yml 4.9 KB

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