go.yml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 }}