go.yml 2.8 KB

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