go.yml 2.5 KB

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