go.yml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. jobs:
  21. lint:
  22. name: Lint
  23. runs-on: ubuntu-latest
  24. steps:
  25. - name: Checkout code
  26. uses: actions/checkout@v2
  27. - name: Run golangci-lint
  28. uses: golangci/golangci-lint-action@v2
  29. with:
  30. version: latest
  31. args: --timeout=30m
  32. - name: Check Go module tidiness
  33. shell: bash
  34. run: |
  35. go mod tidy
  36. STATUS=$(git status --porcelain go.mod go.sum)
  37. if [ ! -z "$STATUS" ]; then
  38. echo "Running go mod tidy modified go.mod and/or go.sum"
  39. exit 1
  40. fi
  41. test:
  42. name: Test
  43. strategy:
  44. matrix:
  45. go-version: [ 1.15.x, 1.16.x, 1.17.x ]
  46. platform: [ ubuntu-latest, macos-latest, windows-latest ]
  47. runs-on: ${{ matrix.platform }}
  48. steps:
  49. - name: Install Go
  50. uses: actions/setup-go@v2
  51. with:
  52. go-version: ${{ matrix.go-version }}
  53. - name: Checkout code
  54. uses: actions/checkout@v2
  55. - name: Run tests with coverage
  56. run: go test -v -race -coverprofile=coverage -covermode=atomic ./...
  57. - name: Upload coverage report to Codecov
  58. uses: codecov/[email protected]
  59. with:
  60. file: ./coverage
  61. flags: unittests
  62. - name: Send email on failure
  63. uses: dawidd6/action-send-mail@v3
  64. if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  65. with:
  66. server_address: smtp.mailgun.org
  67. server_port: 465
  68. username: ${{ secrets.SMTP_USERNAME }}
  69. password: ${{ secrets.SMTP_PASSWORD }}
  70. subject: GitHub Actions (${{ github.repository }}) job result
  71. to: [email protected]
  72. from: GitHub Actions (${{ github.repository }})
  73. reply_to: [email protected]
  74. body: |
  75. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  76. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}