tests.yml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. name: Tests
  2. on: [push, pull_request]
  3. jobs:
  4. unit-tests:
  5. runs-on: ubuntu-latest
  6. strategy:
  7. matrix:
  8. go: ['1.19', '1.20']
  9. steps:
  10. - uses: actions/checkout@v3
  11. with:
  12. # clone in the gopath
  13. path: src/github.com/${{ github.repository }}
  14. fetch-depth: 0
  15. - uses: actions/setup-go@v2
  16. with:
  17. stable: false
  18. go-version: ${{ matrix.go }}
  19. - run: |
  20. # `env` doesn't allow for variable expansion, so we use the GITHUB_ENV
  21. # trick.
  22. echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
  23. echo "GO111MODULE=on" >> $GITHUB_ENV
  24. - name: run unit tests
  25. run: |
  26. cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}
  27. go get -v -t ./...
  28. echo "" > "${GITHUB_WORKSPACE}"/coverage.txt
  29. for d in $(go list ./...); do
  30. go test -v -race -coverprofile=profile.out -covermode=atomic "${d}"
  31. if [ -f profile.out ]; then
  32. cat profile.out >> "${GITHUB_WORKSPACE}"/coverage.txt
  33. rm profile.out
  34. fi
  35. done
  36. - name: report coverage to codecov
  37. uses: codecov/codecov-action@v3
  38. with:
  39. files: coverage.txt
  40. flags: unittests
  41. fail_ci_if_error: true
  42. verbose: true
  43. integration-tests:
  44. runs-on: ubuntu-latest
  45. strategy:
  46. matrix:
  47. go: ['1.19', '1.20']
  48. steps:
  49. - uses: actions/checkout@v3
  50. with:
  51. # clone in the gopath
  52. path: src/github.com/${{ github.repository }}
  53. fetch-depth: 0
  54. - uses: actions/setup-go@v2
  55. with:
  56. stable: false
  57. go-version: ${{ matrix.go }}
  58. - run: |
  59. # `env` doesn't allow for variable expansion, so we use the GITHUB_ENV
  60. # trick.
  61. echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
  62. echo "GO111MODULE=on" >> $GITHUB_ENV
  63. - name: setup integ tests
  64. run: |
  65. cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}
  66. ./.ci/setup-integ.sh
  67. - name: run integ tests
  68. run: |
  69. cd $GITHUB_WORKSPACE/src/github.com/${{ github.repository }}/integ
  70. go get -v -t -tags=integration ./...
  71. echo "" > "${GITHUB_WORKSPACE}"/coverage.txt
  72. for d in $(go list -tags=integration ./...); do
  73. go test -c -tags=integration -v -race -coverprofile=profile.out -covermode=atomic "${d}"
  74. testbin="./$(basename $d).test"
  75. # only run it if it was built - i.e. if there are integ tests
  76. test -x "${testbin}" && sudo "./${testbin}"
  77. if [ -f profile.out ]; then
  78. cat profile.out >> "${GITHUB_WORKSPACE}"/coverage.txt
  79. rm profile.out
  80. fi
  81. done
  82. - name: report coverage to codecov
  83. uses: codecov/codecov-action@v3
  84. with:
  85. files: coverage.txt
  86. flags: integtests
  87. fail_ci_if_error: true
  88. verbose: true